1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
10 #include "editxlinkdialog.h"
12 #include "exportxhtmldialog.h"
14 #include "geometry.h" // for addBBox
15 #include "mainwindow.h"
20 #include "warningdialog.h"
21 #include "xlinkitem.h"
22 #include "xml-freemind.h"
28 extern Main *mainWindow;
29 extern QDBusConnection dbusConnection;
31 extern Settings settings;
32 extern QString tmpVymDir;
34 extern TextEditor *textEditor;
35 extern FlagRow *standardFlagsMaster;
37 extern QString clipboardDir;
38 extern QString clipboardFile;
39 extern bool clipboardEmpty;
41 extern ImageIO imageIO;
43 extern QString vymName;
44 extern QString vymVersion;
45 extern QDir vymBaseDir;
47 extern QDir lastImageDir;
48 extern QDir lastFileDir;
50 extern Settings settings;
52 uint VymModel::idLast=0; // make instance
56 //cout << "Const VymModel\n";
58 rootItem->setModel (this);
64 //cout << "Destr VymModel\n";
65 autosaveTimer->stop();
66 fileChangedTimer->stop();
70 void VymModel::clear()
72 while (rootItem->childCount() >0)
73 deleteItem (rootItem->getChildNum(0) );
76 void VymModel::init ()
81 // Also no scene yet (should not be needed anyway) FIXME-3 VM
95 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
96 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
97 mainWindow->updateHistory (undoSet);
100 makeTmpDirectories();
105 fileName=tr("unnamed");
107 blockReposition=false;
108 blockSaveState=false;
110 autosaveTimer=new QTimer (this);
111 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
113 fileChangedTimer=new QTimer (this);
114 fileChangedTimer->start(3000);
115 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
120 selectionBlocked=false;
125 // animations // FIXME-3 switch to new animation system
126 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
127 animationTicks=settings.readNumEntry("/animation/ticks",10);
128 animationInterval=settings.readNumEntry("/animation/interval",50);
130 animationTimer=new QTimer (this);
131 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
134 defLinkColor=QColor (0,0,255);
135 defXLinkColor=QColor (180,180,180);
136 linkcolorhint=LinkableMapObj::DefaultColor;
137 linkstyle=LinkableMapObj::PolyParabel;
139 defXLinkColor=QColor (230,230,230);
141 hidemode=TreeItem::HideNone;
146 //Initialize DBUS object
147 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
148 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapID),this))
149 qWarning ("VymModel: Couldn't register DBUS object!");
152 void VymModel::makeTmpDirectories()
154 // Create unique temporary directories
155 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapID);
156 histPath = tmpMapDir+"/history";
162 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
167 bool VymModel::isRepositionBlocked()
169 return blockReposition;
172 void VymModel::updateActions() // FIXME-4 maybe don't update if blockReposition is set
174 //cout << "VM::updateActions \n";
175 // Tell mainwindow to update states of actions
176 mainWindow->updateActions();
181 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
183 // tmpdir temporary directory to which data will be written
184 // prefix mapname, which will be appended to images etc.
185 // writeflags Only write flags for "real" save of map, not undo
186 // offset offset of bbox of whole map in scene.
187 // Needed for XML export
196 case LinkableMapObj::Line:
199 case LinkableMapObj::Parabel:
202 case LinkableMapObj::PolyLine:
206 ls="StylePolyParabel";
210 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
212 if (linkcolorhint==LinkableMapObj::HeadingColor)
213 colhint=xml.attribut("linkColorHint","HeadingColor");
215 QString mapAttr=xml.attribut("version",vymVersion);
217 mapAttr+= xml.attribut("author",author) +
218 xml.attribut("comment",comment) +
219 xml.attribut("date",getDate()) +
220 xml.attribut("branchCount", QString().number(branchCount())) +
221 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
222 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
223 xml.attribut("linkStyle", ls ) +
224 xml.attribut("linkColor", defLinkColor.name() ) +
225 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
226 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
228 s+=xml.beginElement("vymmap",mapAttr);
231 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
232 standardFlagsMaster->resetUsedCounter();
234 // Build xml recursivly
236 // Save all mapcenters as complete map, if saveSel not set
237 s+=saveTreeToDir(tmpdir,prefix,offset);
240 switch (saveSel->getType())
242 case TreeItem::Branch:
244 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
246 case TreeItem::MapCenter:
248 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
250 case TreeItem::Image:
252 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
255 // other types shouldn't be safed directly...
260 // Save local settings
261 s+=settings.getDataXML (destPath);
264 if (getSelectedItem() && !saveSel )
265 s+=xml.valueElement("select",getSelectString());
268 s+=xml.endElement("vymmap");
270 //cout << s.toStdString() << endl;
272 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
276 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset)
280 for (int i=0; i<rootItem->branchCount(); i++)
281 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
285 void VymModel::setFilePath(QString fpath, QString destname)
287 if (fpath.isEmpty() || fpath=="")
294 filePath=fpath; // becomes absolute path
295 fileName=fpath; // gets stripped of path
296 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
298 // If fpath is not an absolute path, complete it
299 filePath=QDir(fpath).absPath();
300 fileDir=filePath.left (1+filePath.findRev ("/"));
302 // Set short name, too. Search from behind:
303 int i=fileName.findRev("/");
304 if (i>=0) fileName=fileName.remove (0,i+1);
306 // Forget the .vym (or .xml) for name of map
307 mapName=fileName.left(fileName.findRev(".",-1,true) );
311 void VymModel::setFilePath(QString fpath)
313 setFilePath (fpath,fpath);
316 QString VymModel::getFilePath()
321 QString VymModel::getFileName()
326 QString VymModel::getMapName()
331 QString VymModel::getDestPath()
336 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
338 ErrorCode err=success;
340 parseBaseHandler *handler;
344 case VymMap: handler=new parseVYMHandler; break;
345 case FreemindMap : handler=new parseFreemindHandler; break;
347 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
348 "Unknown FileType in VymModel::load()");
352 bool zipped_org=zipped;
356 selModel->clearSelection();
359 BranchItem *bi=getSelectedBranch();
360 if (!bi) return aborted;
361 if (lmode==ImportAdd)
362 saveStateChangingPart(
365 QString("addMapInsert (%1)").arg(fname),
366 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
368 saveStateChangingPart(
371 QString("addMapReplace(%1)").arg(fname),
372 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
376 // Create temporary directory for packing
378 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
381 QMessageBox::critical( 0, tr( "Critical Load Error" ),
382 tr("Couldn't create temporary directory before load\n"));
387 err=unzipDir (tmpZipDir,fname);
397 // Look for mapname.xml
398 xmlfile= fname.left(fname.findRev(".",-1,true));
399 xmlfile=xmlfile.section( '/', -1 );
400 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
401 if (!mfile.exists() )
403 // mapname.xml does not exist, well,
404 // maybe someone renamed the mapname.vym file...
405 // Try to find any .xml in the toplevel
406 // directory of the .vym file
407 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
408 if (flist.count()==1)
410 // Only one entry, take this one
411 xmlfile=tmpZipDir + "/"+flist.first();
414 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
415 *it=tmpZipDir + "/" + *it;
416 // TODO Multiple entries, load all (but only the first one into this ME)
417 //mainWindow->fileLoadFromTmp (flist);
418 //returnCode=1; // Silently forget this attempt to load
419 qWarning ("MainWindow::load (fn) multimap found...");
422 if (flist.isEmpty() )
424 QMessageBox::critical( 0, tr( "Critical Load Error" ),
425 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
428 } //file doesn't exist
430 xmlfile=mfile.name();
433 QFile file( xmlfile);
435 // I am paranoid: file should exist anyway
436 // according to check in mainwindow.
439 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
440 tr(QString("Couldn't open map %1").arg(file.name())));
444 bool blockSaveStateOrg=blockSaveState;
445 blockReposition=true;
447 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
448 QXmlInputSource source( file);
449 QXmlSimpleReader reader;
450 reader.setContentHandler( handler );
451 reader.setErrorHandler( handler );
452 handler->setModel ( this);
455 // We need to set the tmpDir in order to load files with rel. path
460 tmpdir=fname.left(fname.findRev("/",-1));
461 handler->setTmpDir (tmpdir);
462 handler->setInputFile (file.name());
463 handler->setLoadMode (lmode);
464 bool ok = reader.parse( source );
465 blockReposition=false;
466 blockSaveState=blockSaveStateOrg;
467 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
472 emitSelectionChanged();
478 autosaveTimer->stop();
481 // Reset timestamp to check for later updates of file
482 fileChangedTime=QFileInfo (destPath).lastModified();
485 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
486 tr( handler->errorProtocol() ) );
488 // Still return "success": the map maybe at least
489 // partially read by the parser
494 removeDir (QDir(tmpZipDir));
496 // Restore original zip state
503 ErrorCode VymModel::save (const SaveMode &savemode)
507 QString safeFilePath;
509 ErrorCode err=success;
513 mapFileName=mapName+".xml";
515 // use name given by user, even if he chooses .doc
516 mapFileName=fileName;
518 // Look, if we should zip the data:
521 QMessageBox mb( vymName,
522 tr("The map %1\ndid not use the compressed "
523 "vym file format.\nWriting it uncompressed will also write images \n"
524 "and flags and thus may overwrite files in the "
525 "given directory\n\nDo you want to write the map").arg(filePath),
526 QMessageBox::Warning,
527 QMessageBox::Yes | QMessageBox::Default,
529 QMessageBox::Cancel | QMessageBox::Escape);
530 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
531 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
532 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
535 case QMessageBox::Yes:
536 // save compressed (default file format)
539 case QMessageBox::No:
543 case QMessageBox::Cancel:
550 // First backup existing file, we
551 // don't want to add to old zip archives
555 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
557 QString backupFileName(destPath + "~");
558 QFile backupFile(backupFileName);
559 if (backupFile.exists() && !backupFile.remove())
561 QMessageBox::warning(0, tr("Save Error"),
562 tr("%1\ncould not be removed before saving").arg(backupFileName));
564 else if (!f.rename(backupFileName))
566 QMessageBox::warning(0, tr("Save Error"),
567 tr("%1\ncould not be renamed before saving").arg(destPath));
574 // Create temporary directory for packing
576 tmpZipDir=makeTmpDir (ok,"vym-zip");
579 QMessageBox::critical( 0, tr( "Critical Load Error" ),
580 tr("Couldn't create temporary directory before save\n"));
584 safeFilePath=filePath;
585 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
588 // Create mapName and fileDir
589 makeSubDirs (fileDir);
592 if (savemode==CompleteMap || selModel->selection().isEmpty())
595 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
598 autosaveTimer->stop();
603 if (selectionType()==TreeItem::Image)
606 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
607 // TODO take care of multiselections
610 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
613 qWarning ("ME::saveStringToDisk failed!");
619 if (err==success) err=zipDir (tmpZipDir,destPath);
622 removeDir (QDir(tmpZipDir));
624 // Restore original filepath outside of tmp zip dir
625 setFilePath (safeFilePath);
629 fileChangedTime=QFileInfo (destPath).lastModified();
633 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
635 QString pathDir=path.left(path.findRev("/"));
641 // We need to parse saved XML data
642 parseVYMHandler handler;
643 QXmlInputSource source( file);
644 QXmlSimpleReader reader;
645 reader.setContentHandler( &handler );
646 reader.setErrorHandler( &handler );
647 handler.setModel ( this);
648 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
649 if (undoSel.isEmpty())
653 handler.setLoadMode (NewMap);
657 handler.setLoadMode (ImportReplace);
659 blockReposition=true;
660 bool ok = reader.parse( source );
661 blockReposition=false;
664 // This should never ever happen
665 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
666 handler.errorProtocol());
669 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
672 bool VymModel::addMapInsertInt (const QString &path)
674 QString pathDir=path.left(path.findRev("/"));
680 // We need to parse saved XML data
681 parseVYMHandler handler;
682 QXmlInputSource source( file);
683 QXmlSimpleReader reader;
684 reader.setContentHandler( &handler );
685 reader.setErrorHandler( &handler );
686 handler.setModel (this);
687 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
688 handler.setLoadMode (ImportAdd);
689 blockReposition=true;
690 bool ok = reader.parse( source );
691 blockReposition=false;
692 if ( ok ) return true;
694 // This should never ever happen
695 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
696 handler.errorProtocol());
699 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
703 bool VymModel::addMapInsertInt (const QString &path, int pos)
705 BranchItem *selbi=getSelectedBranch();
708 if (addMapInsertInt (path))
710 if (selbi->depth()>0)
711 relinkBranch (selbi->getLastBranch(), selbi,pos);
715 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
719 qWarning ("ME::addMapInsertInt nothing selected");
723 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
725 ImageItem *ii=createImage(dst);
735 void VymModel::loadFloatImage ()
737 BranchItem *selbi=getSelectedBranch();
741 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
742 fd->setMode (Q3FileDialog::ExistingFiles);
743 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
744 ImagePreview *p =new ImagePreview (fd);
745 fd->setContentsPreviewEnabled( TRUE );
746 fd->setContentsPreview( p, p );
747 fd->setPreviewMode( Q3FileDialog::Contents );
748 fd->setCaption(vymName+" - " +tr("Load image"));
749 fd->setDir (lastImageDir);
752 if ( fd->exec() == QDialog::Accepted )
754 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
755 lastImageDir=QDir (fd->dirPath());
758 for (int j=0; j<fd->selectedFiles().count(); j++)
760 s=fd->selectedFiles().at(j);
761 ii=loadFloatImageInt (selbi,s);
762 //FIXME-3 check savestate for loadImage
768 QString ("loadImage (%1)").arg(s ),
769 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
772 // TODO loadFIO error handling
773 qWarning ("Failed to load "+s);
781 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
786 void VymModel::saveFloatImage ()
788 ImageItem *ii=getSelectedImage();
791 QFileDialog *fd=new QFileDialog( NULL);
792 fd->setFilters (imageIO.getFilters());
793 fd->setCaption(vymName+" - " +tr("Save image"));
794 fd->setFileMode( QFileDialog::AnyFile );
795 fd->setDirectory (lastImageDir);
796 // fd->setSelection (fio->getOriginalFilename());
800 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
802 fn=fd->selectedFiles().at(0);
803 if (QFile (fn).exists() )
805 QMessageBox mb( vymName,
806 tr("The file %1 exists already.\n"
807 "Do you want to overwrite it?").arg(fn),
808 QMessageBox::Warning,
809 QMessageBox::Yes | QMessageBox::Default,
810 QMessageBox::Cancel | QMessageBox::Escape,
811 QMessageBox::NoButton );
813 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
814 mb.setButtonText( QMessageBox::No, tr("Cancel"));
817 case QMessageBox::Yes:
820 case QMessageBox::Cancel:
827 saveFloatImageInt (ii,fd->selectedFilter(),fn );
834 void VymModel::importDirInt(BranchItem *dst, QDir d)
836 BranchItem *selbi=getSelectedBranch();
840 // Traverse directories
841 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
842 QFileInfoList list = d.entryInfoList();
845 for (int i = 0; i < list.size(); ++i)
848 if (fi.fileName() != "." && fi.fileName() != ".." )
850 bi=addNewBranchInt(dst,-2);
851 bi->setHeading (fi.fileName() ); // FIXME-3 check this
852 bi->setHeadingColor (QColor("blue"));
854 if ( !d.cd(fi.fileName()) )
855 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
858 // Recursively add subdirs
865 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
866 list = d.entryInfoList();
868 for (int i = 0; i < list.size(); ++i)
871 bi=addNewBranchInt (dst,-2);
872 bi->setHeading (fi.fileName() );
873 bi->setHeadingColor (QColor("black"));
874 if (fi.fileName().right(4) == ".vym" )
875 bi->setVymLink (fi.filePath());
880 void VymModel::importDirInt (const QString &s)
882 BranchItem *selbi=getSelectedBranch();
885 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
888 importDirInt (selbi,d);
892 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
894 BranchItem *selbi=getSelectedBranch();
898 filters <<"VYM map (*.vym)";
899 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
900 fd->setMode (QFileDialog::DirectoryOnly);
901 fd->setFilters (filters);
902 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
906 if ( fd->exec() == QDialog::Accepted )
908 importDirInt (fd->selectedFile() );
910 //FIXME-3 VM needed? scene()->update();
916 void VymModel::autosave()
921 cout << "VymModel::autosave rejected due to missing filePath\n";
924 QDateTime now=QDateTime().currentDateTime();
926 // Disable autosave, while we have gone back in history
927 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
928 if (redosAvail>0) return;
930 // Also disable autosave for new map without filename
931 if (filePath.isEmpty()) return;
934 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
936 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
937 mainWindow->fileSave (this);
940 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
945 void VymModel::fileChanged()
947 // Check if file on disk has changed meanwhile
948 if (!filePath.isEmpty())
950 QDateTime tmod=QFileInfo (filePath).lastModified();
951 if (tmod>fileChangedTime)
953 // FIXME-3 VM switch to current mapeditor and finish lineedits...
954 QMessageBox mb( vymName,
955 tr("The file of the map on disk has changed:\n\n"
956 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
957 QMessageBox::Question,
959 QMessageBox::Cancel | QMessageBox::Default,
960 QMessageBox::NoButton );
962 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
963 mb.setButtonText( QMessageBox::No, tr("Ignore"));
966 case QMessageBox::Yes:
968 load (filePath,NewMap,fileType);
969 case QMessageBox::Cancel:
970 fileChangedTime=tmod; // allow autosave to overwrite newer file!
976 bool VymModel::isDefault()
981 void VymModel::makeDefault()
987 bool VymModel::hasChanged()
992 void VymModel::setChanged()
995 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
999 latestAddedItem=NULL;
1003 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1005 if (!lmo || !lmo->getTreeItem() ) return QString();
1006 return getObjectName (lmo->getTreeItem() );
1010 QString VymModel::getObjectName (TreeItem *ti)
1013 if (!ti) return QString("Error: NULL has no name!");
1015 if (s=="") s="unnamed";
1017 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1020 void VymModel::redo()
1022 // Can we undo at all?
1023 if (redosAvail<1) return;
1025 bool blockSaveStateOrg=blockSaveState;
1026 blockSaveState=true;
1030 if (undosAvail<stepsTotal) undosAvail++;
1032 if (curStep>stepsTotal) curStep=1;
1033 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1034 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1035 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1036 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1037 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1038 QString version=undoSet.readEntry ("/history/version");
1040 /* TODO Maybe check for version, if we save the history
1041 if (!checkVersion(version))
1042 QMessageBox::warning(0,tr("Warning"),
1043 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1046 // Find out current undo directory
1047 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1051 cout << "VymModel::redo() begin\n";
1052 cout << " undosAvail="<<undosAvail<<endl;
1053 cout << " redosAvail="<<redosAvail<<endl;
1054 cout << " curStep="<<curStep<<endl;
1055 cout << " ---------------------------"<<endl;
1056 cout << " comment="<<comment.toStdString()<<endl;
1057 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1058 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1059 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1060 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1061 cout << " ---------------------------"<<endl<<endl;
1064 // select object before redo
1065 if (!redoSelection.isEmpty())
1066 select (redoSelection);
1071 parseAtom (redoCommand,noErr,errMsg);
1073 blockSaveState=blockSaveStateOrg;
1075 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1076 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1077 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1078 undoSet.writeSettings(histPath);
1080 mainWindow->updateHistory (undoSet);
1083 /* TODO remove testing
1084 cout << "ME::redo() end\n";
1085 cout << " undosAvail="<<undosAvail<<endl;
1086 cout << " redosAvail="<<redosAvail<<endl;
1087 cout << " curStep="<<curStep<<endl;
1088 cout << " ---------------------------"<<endl<<endl;
1094 bool VymModel::isRedoAvailable()
1096 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1102 void VymModel::undo()
1104 // Can we undo at all?
1105 if (undosAvail<1) return;
1107 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1109 bool blockSaveStateOrg=blockSaveState;
1110 blockSaveState=true;
1112 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1113 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1114 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1115 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1116 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1117 QString version=undoSet.readEntry ("/history/version");
1119 /* TODO Maybe check for version, if we save the history
1120 if (!checkVersion(version))
1121 QMessageBox::warning(0,tr("Warning"),
1122 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1125 // Find out current undo directory
1126 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1128 // select object before undo
1129 if (!select (undoSelection))
1131 qWarning ("VymModel::undo() Could not select object for undo");
1138 cout << "VymModel::undo() begin\n";
1139 cout << " undosAvail="<<undosAvail<<endl;
1140 cout << " redosAvail="<<redosAvail<<endl;
1141 cout << " curStep="<<curStep<<endl;
1142 cout << " ---------------------------"<<endl;
1143 cout << " comment="<<comment.toStdString()<<endl;
1144 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1145 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1146 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1147 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1148 cout << " ---------------------------"<<endl<<endl;
1153 parseAtom (undoCommand,noErr,errMsg);
1157 if (curStep<1) curStep=stepsTotal;
1161 blockSaveState=blockSaveStateOrg;
1163 cout << "VymModel::undo() end\n";
1164 cout << " undosAvail="<<undosAvail<<endl;
1165 cout << " redosAvail="<<redosAvail<<endl;
1166 cout << " curStep="<<curStep<<endl;
1167 cout << " ---------------------------"<<endl<<endl;
1170 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1171 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1172 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1173 undoSet.writeSettings(histPath);
1175 mainWindow->updateHistory (undoSet);
1177 //emitSelectionChanged();
1180 bool VymModel::isUndoAvailable()
1182 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1188 void VymModel::gotoHistoryStep (int i)
1190 // Restore variables
1191 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1192 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1194 if (i<0) i=undosAvail+redosAvail;
1196 // Clicking above current step makes us undo things
1199 for (int j=0; j<undosAvail-i; j++) undo();
1202 // Clicking below current step makes us redo things
1204 for (int j=undosAvail; j<i; j++)
1206 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1210 // And ignore clicking the current row ;-)
1214 QString VymModel::getHistoryPath()
1216 QString histName(QString("history-%1").arg(curStep));
1217 return (tmpMapDir+"/"+histName);
1220 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1222 sendData(redoCom); //FIXME-3 testing
1227 if (blockSaveState) return;
1229 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1231 // Find out current undo directory
1232 if (undosAvail<stepsTotal) undosAvail++;
1234 if (curStep>stepsTotal) curStep=1;
1236 QString backupXML="";
1237 QString histDir=getHistoryPath();
1238 QString bakMapPath=histDir+"/map.xml";
1240 // Create histDir if not available
1243 makeSubDirs (histDir);
1245 // Save depending on how much needs to be saved
1247 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1249 QString undoCommand="";
1250 if (savemode==UndoCommand)
1252 undoCommand=undoCom;
1254 else if (savemode==PartOfMap )
1256 undoCommand=undoCom;
1257 undoCommand.replace ("PATH",bakMapPath);
1261 if (!backupXML.isEmpty())
1262 // Write XML Data to disk
1263 saveStringToDisk (bakMapPath,backupXML);
1265 // We would have to save all actions in a tree, to keep track of
1266 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1269 // Write the current state to disk
1270 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1271 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1272 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1273 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1274 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1275 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1276 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1277 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1278 undoSet.setEntry (QString("/history/version"),vymVersion);
1279 undoSet.writeSettings(histPath);
1283 // TODO remove after testing
1284 //cout << " into="<< histPath.toStdString()<<endl;
1285 cout << " stepsTotal="<<stepsTotal<<
1286 ", undosAvail="<<undosAvail<<
1287 ", redosAvail="<<redosAvail<<
1288 ", curStep="<<curStep<<endl;
1289 cout << " ---------------------------"<<endl;
1290 cout << " comment="<<comment.toStdString()<<endl;
1291 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1292 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1293 cout << " redoCom="<<redoCom.toStdString()<<endl;
1294 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1295 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1296 cout << " ---------------------------"<<endl;
1299 mainWindow->updateHistory (undoSet);
1305 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1307 // save the selected part of the map, Undo will replace part of map
1308 QString undoSelection="";
1310 undoSelection=getSelectString(undoSel);
1312 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1313 QString redoSelection="";
1315 redoSelection=getSelectString(undoSel);
1317 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1320 saveState (PartOfMap,
1321 undoSelection, "addMapReplace (\"PATH\")",
1327 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1331 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1334 QString undoSelection;
1335 QString redoSelection=getSelectString(redoSel);
1336 if (redoSel->getType()==TreeItem::Branch)
1338 undoSelection=getSelectString (redoSel->parent());
1339 // save the selected branch of the map, Undo will insert part of map
1340 saveState (PartOfMap,
1341 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1342 redoSelection, "delete ()",
1346 if (redoSel->getType()==TreeItem::MapCenter)
1348 // save the selected branch of the map, Undo will insert part of map
1349 saveState (PartOfMap,
1350 undoSelection, QString("addMapInsert (\"PATH\")"),
1351 redoSelection, "delete ()",
1358 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1360 // "Normal" savestate: save commands, selections and comment
1361 // so just save commands for undo and redo
1362 // and use current selection
1364 QString redoSelection="";
1365 if (redoSel) redoSelection=getSelectString(redoSel);
1366 QString undoSelection="";
1367 if (undoSel) undoSelection=getSelectString(undoSel);
1369 saveState (UndoCommand,
1376 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1378 // "Normal" savestate: save commands, selections and comment
1379 // so just save commands for undo and redo
1380 // and use current selection
1381 saveState (UndoCommand,
1388 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1390 // "Normal" savestate applied to model (no selection needed):
1391 // save commands and comment
1392 saveState (UndoCommand,
1400 QGraphicsScene* VymModel::getScene ()
1405 TreeItem* VymModel::findBySelectString(QString s)
1407 if (s.isEmpty() ) return NULL;
1409 // Old maps don't have multiple mapcenters and don't save full path
1410 if (s.left(2) !="mc")
1413 QStringList parts=s.split (",");
1416 TreeItem *ti=rootItem;
1418 while (!parts.isEmpty() )
1420 typ=parts.first().left(2);
1421 n=parts.first().right(parts.first().length() - 3).toInt();
1422 parts.removeFirst();
1423 if (typ=="mc" || typ=="bo")
1424 ti=ti->getBranchNum (n);
1426 ti=ti->getImageNum (n);
1428 ti=ti->getAttributeNum (n);
1430 ti=ti->getXLinkNum (n);
1431 if(!ti) return NULL;
1436 TreeItem* VymModel::findID (const uint &i) //FIXME-3 Search also other types...
1438 BranchItem *cur=NULL;
1439 BranchItem *prev=NULL;
1440 nextBranch(cur,prev);
1443 if (i==cur->getID() ) return cur;
1444 nextBranch(cur,prev);
1449 //////////////////////////////////////////////
1451 //////////////////////////////////////////////
1452 void VymModel::setVersion (const QString &s)
1457 QString VymModel::getVersion()
1462 void VymModel::setAuthor (const QString &s)
1465 QString ("setMapAuthor (\"%1\")").arg(author),
1466 QString ("setMapAuthor (\"%1\")").arg(s),
1467 QString ("Set author of map to \"%1\"").arg(s)
1472 QString VymModel::getAuthor()
1477 void VymModel::setComment (const QString &s)
1480 QString ("setMapComment (\"%1\")").arg(comment),
1481 QString ("setMapComment (\"%1\")").arg(s),
1482 QString ("Set comment of map")
1487 QString VymModel::getComment ()
1492 QString VymModel::getDate ()
1494 return QDate::currentDate().toString ("yyyy-MM-dd");
1497 int VymModel::branchCount()
1500 BranchItem *cur=NULL;
1501 BranchItem *prev=NULL;
1502 nextBranch(cur,prev);
1506 nextBranch(cur,prev);
1511 void VymModel::setSortFilter (const QString &s)
1514 emit (sortFilterChanged (sortFilter));
1517 QString VymModel::getSortFilter ()
1522 void VymModel::setHeading(const QString &s)
1524 BranchItem *selbi=getSelectedBranch();
1529 "setHeading (\""+selbi->getHeading()+"\")",
1531 "setHeading (\""+s+"\")",
1532 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1533 selbi->setHeading(s );
1534 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1536 emitSelectionChanged();
1540 QString VymModel::getHeading()
1542 TreeItem *selti=getSelectedItem();
1544 return selti->getHeading();
1549 void VymModel::setNote(const QString &s)
1551 TreeItem *selti=getSelectedItem();
1554 emitNoteHasChanged(selti);
1557 "setNote (\""+selti->getNote()+"\")",
1559 "setNote (\""+s+"\")",
1560 QString("Set note of %1 ").arg(getObjectName(selti)) );
1565 QString VymModel::getNote()
1567 TreeItem *selti=getSelectedItem();
1569 return selti->getNote();
1574 void VymModel::findDuplicateURLs() // FIXME-3 needs GUI
1576 // Generate map containing _all_ URLs and branches
1578 QMap <QString,BranchItem*> map;
1579 BranchItem *cur=NULL;
1580 BranchItem *prev=NULL;
1581 nextBranch(cur,prev);
1586 map.insertMulti (u,cur);
1587 nextBranch(cur,prev);
1590 // Extract duplicate URLs
1591 QMap <QString, BranchItem*>::const_iterator i=map.constBegin();
1592 QMap <QString, BranchItem*>::const_iterator firstdup=map.constEnd(); //invalid
1593 while (i != map.constEnd())
1595 if (i!=map.constBegin() && i.key()==firstdup.key())
1597 if ( i-1==firstdup )
1599 cout << firstdup.key().toStdString() << endl;
1600 cout << " - "<< firstdup.value() <<" - "<<firstdup.value()->getHeadingStd()<<endl;
1602 cout << " - "<< i.value() <<" - "<<i.value()->getHeadingStd()<<endl;
1610 BranchItem* VymModel::findText (QString s, bool cs)
1612 if (!s.isEmpty() && s!=findString)
1618 QTextDocument::FindFlags flags=0;
1619 if (cs) flags=QTextDocument::FindCaseSensitively;
1622 { // Nothing found or new find process
1624 // nothing found, start again
1628 nextBranch (findCurrent,findPrevious);
1630 bool searching=true;
1631 bool foundNote=false;
1632 while (searching && !EOFind)
1636 // Searching in Note
1637 if (findCurrent->getNote().contains(findString,cs))
1639 select (findCurrent);
1641 if (getSelectedBranch()!=itFind)
1644 emitShowSelection();
1647 if (textEditor->findText(findString,flags))
1653 // Searching in Heading
1654 if (searching && findCurrent->getHeading().contains (findString,cs) )
1656 select(findCurrent);
1662 if (!nextBranch(findCurrent,findPrevious) )
1665 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1668 return getSelectedBranch();
1673 void VymModel::findReset()
1674 { // Necessary if text to find changes during a find process
1681 void VymModel::emitShowFindWidget()
1683 emit (showFindWidget());
1686 void VymModel::setScene (QGraphicsScene *s)
1691 void VymModel::setURL(const QString &url)
1693 TreeItem *selti=getSelectedItem();
1696 QString oldurl=selti->getURL();
1697 selti->setURL (url);
1700 QString ("setURL (\"%1\")").arg(oldurl),
1702 QString ("setURL (\"%1\")").arg(url),
1703 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1706 emitDataHasChanged (selti);
1707 emitShowSelection();
1711 QString VymModel::getURL()
1713 TreeItem *selti=getSelectedItem();
1715 return selti->getURL();
1720 QStringList VymModel::getURLs(bool ignoreScrolled)
1723 BranchItem *selbi=getSelectedBranch();
1724 BranchItem *cur=selbi;
1725 BranchItem *prev=NULL;
1728 if (!cur->getURL().isEmpty() && !(ignoreScrolled && cur->hasScrolledParent(cur) ))
1729 urls.append( cur->getURL());
1730 cur=nextBranch (cur,prev,true,selbi);
1736 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1738 BranchItem *bi=getSelectedBranch();
1741 BranchObj *bo=(BranchObj*)(bi->getLMO());
1744 QString s=bo->getFrameTypeName();
1745 bo->setFrameType (t);
1746 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1747 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1749 bo->updateLinkGeometry();
1754 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1756 BranchItem *bi=getSelectedBranch();
1759 BranchObj *bo=(BranchObj*)(bi->getLMO());
1762 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1763 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1764 bo->setFrameType (s);
1766 bo->updateLinkGeometry();
1771 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1774 BranchItem *bi=getSelectedBranch();
1777 BranchObj *bo=(BranchObj*)(bi->getLMO());
1780 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1781 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1782 bo->setFramePenColor (c);
1787 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1789 BranchItem *bi=getSelectedBranch();
1792 BranchObj *bo=(BranchObj*)(bi->getLMO());
1795 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1796 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1797 bo->setFrameBrushColor (c);
1802 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1804 BranchItem *bi=getSelectedBranch();
1807 BranchObj *bo=(BranchObj*)(bi->getLMO());
1810 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1811 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1812 bo->setFramePadding (i);
1814 bo->updateLinkGeometry();
1819 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1821 BranchItem *bi=getSelectedBranch();
1824 BranchObj *bo=(BranchObj*)(bi->getLMO());
1827 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1828 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1829 bo->setFrameBorderWidth (i);
1831 bo->updateLinkGeometry();
1836 void VymModel::setIncludeImagesVer(bool b)
1838 BranchItem *bi=getSelectedBranch();
1841 QString u= b ? "false" : "true";
1842 QString r=!b ? "false" : "true";
1846 QString("setIncludeImagesVertically (%1)").arg(u),
1848 QString("setIncludeImagesVertically (%1)").arg(r),
1849 QString("Include images vertically in %1").arg(getObjectName(bi))
1851 bi->setIncludeImagesVer(b);
1852 emitDataHasChanged ( bi);
1857 void VymModel::setIncludeImagesHor(bool b)
1859 BranchItem *bi=getSelectedBranch();
1862 QString u= b ? "false" : "true";
1863 QString r=!b ? "false" : "true";
1867 QString("setIncludeImagesHorizontally (%1)").arg(u),
1869 QString("setIncludeImagesHorizontally (%1)").arg(r),
1870 QString("Include images horizontally in %1").arg(getObjectName(bi))
1872 bi->setIncludeImagesHor(b);
1873 emitDataHasChanged ( bi);
1878 void VymModel::setHideLinkUnselected (bool b)
1880 TreeItem *ti=getSelectedItem();
1881 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1883 QString u= b ? "false" : "true";
1884 QString r=!b ? "false" : "true";
1888 QString("setHideLinkUnselected (%1)").arg(u),
1890 QString("setHideLinkUnselected (%1)").arg(r),
1891 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1893 ((MapItem*)ti)->setHideLinkUnselected(b);
1897 void VymModel::setHideExport(bool b)
1899 TreeItem *ti=getSelectedItem();
1901 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1903 ti->setHideInExport (b);
1904 QString u= b ? "false" : "true";
1905 QString r=!b ? "false" : "true";
1909 QString ("setHideExport (%1)").arg(u),
1911 QString ("setHideExport (%1)").arg(r),
1912 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1914 emitDataHasChanged(ti);
1915 emitSelectionChanged();
1918 // emitSelectionChanged();
1919 // FIXME-3 VM needed? scene()->update();
1923 void VymModel::toggleHideExport()
1925 TreeItem *selti=getSelectedItem();
1927 setHideExport ( !selti->hideInExport() );
1930 void VymModel::addTimestamp() //FIXME-3 new function, localize
1932 BranchItem *selbi=addNewBranch();
1935 QDate today=QDate::currentDate();
1937 selbi->setHeading (QString ("%1-%2-%3")
1938 .arg(today.year(),4,10,c)
1939 .arg(today.month(),2,10,c)
1940 .arg(today.day(),2,10,c));
1941 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1948 void VymModel::copy()
1950 TreeItem *selti=getSelectedItem();
1952 (selti->getType() == TreeItem::Branch ||
1953 selti->getType() == TreeItem::MapCenter ||
1954 selti->getType() == TreeItem::Image ))
1956 if (redosAvail == 0)
1959 QString s=getSelectString(selti);
1960 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1961 curClipboard=curStep;
1964 // Copy also to global clipboard, because we are at last step in history
1965 QString bakMapName(QString("history-%1").arg(curStep));
1966 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1967 copyDir (bakMapDir,clipboardDir );
1969 clipboardEmpty=false;
1975 void VymModel::pasteNoSave(const int &n)
1977 bool old=blockSaveState;
1978 blockSaveState=true;
1979 bool zippedOrg=zipped;
1980 if (redosAvail > 0 || n!=0)
1982 // Use the "historical" buffer
1983 QString bakMapName(QString("history-%1").arg(n));
1984 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1985 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1987 // Use the global buffer
1988 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1993 void VymModel::paste()
1995 BranchItem *selbi=getSelectedBranch();
1998 saveStateChangingPart(
2001 QString ("paste (%1)").arg(curClipboard),
2002 QString("Paste to %1").arg( getObjectName(selbi))
2009 void VymModel::cut()
2011 TreeItem *selti=getSelectedItem();
2012 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
2020 bool VymModel::moveUp(BranchItem *bi)
2022 if (bi && bi->canMoveUp())
2023 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
2028 void VymModel::moveUp()
2030 BranchItem *selbi=getSelectedBranch();
2033 QString oldsel=getSelectString();
2036 getSelectString(),"moveDown ()",
2038 QString("Move up %1").arg(getObjectName(selbi)));
2042 bool VymModel::moveDown(BranchItem *bi)
2044 if (bi && bi->canMoveDown())
2045 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2050 void VymModel::moveDown()
2052 BranchItem *selbi=getSelectedBranch();
2055 QString oldsel=getSelectString();
2056 if ( moveDown(selbi))
2058 getSelectString(),"moveUp ()",
2059 oldsel,"moveDown ()",
2060 QString("Move down %1").arg(getObjectName(selbi)));
2064 void VymModel::detach()
2066 BranchItem *selbi=getSelectedBranch();
2067 if (selbi && selbi->depth()>0)
2069 // if no relPos have been set before, try to use current rel positions
2070 if (selbi->getLMO())
2071 for (int i=0; i<selbi->branchCount();++i)
2072 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2074 QString oldsel=getSelectString();
2077 BranchObj *bo=selbi->getBranchObj();
2078 if (bo) p=bo->getAbsPos();
2079 QString parsel=getSelectString(selbi->parent());
2080 if ( relinkBranch (selbi,rootItem,-1) )
2082 getSelectString (selbi),
2083 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2086 QString("Detach %1").arg(getObjectName(selbi))
2091 void VymModel::sortChildren(bool inverse)
2093 BranchItem* selbi=getSelectedBranch();
2096 if(selbi->branchCount()>1)
2100 saveStateChangingPart(
2101 selbi,selbi, "sortChildren ()",
2102 QString("Sort children of %1").arg(getObjectName(selbi)));
2104 selbi->sortChildren(inverse);
2106 emitShowSelection();
2111 BranchItem* VymModel::createMapCenter()
2113 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2117 BranchItem* VymModel::createBranch(BranchItem *dst)
2120 return addNewBranchInt (dst,-2);
2125 ImageItem* VymModel::createImage(BranchItem *dst)
2132 QList<QVariant> cData;
2133 cData << "new" << "undef";
2135 ImageItem *newii=new ImageItem(cData) ;
2136 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2138 emit (layoutAboutToBeChanged() );
2141 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2142 n=dst->getRowNumAppend(newii);
2143 beginInsertRows (parix,n,n);
2144 dst->appendChild (newii);
2147 emit (layoutChanged() );
2149 // save scroll state. If scrolled, automatically select
2150 // new branch in order to tmp unscroll parent...
2151 newii->createMapObj(mapScene);
2158 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2165 QList<QVariant> cData;
2166 cData << "new xLink"<<"undef";
2168 XLinkItem *newxli=new XLinkItem(cData) ;
2169 newxli->setBegin (bi);
2171 emit (layoutAboutToBeChanged() );
2174 n=bi->getRowNumAppend(newxli);
2175 beginInsertRows (parix,n,n);
2176 bi->appendChild (newxli);
2179 emit (layoutChanged() );
2181 // save scroll state. If scrolled, automatically select
2182 // new branch in order to tmp unscroll parent...
2185 newxli->createMapObj(mapScene);
2193 AttributeItem* VymModel::addAttribute()
2195 BranchItem *selbi=getSelectedBranch();
2198 QList<QVariant> cData;
2199 cData << "new attribute" << "undef";
2200 AttributeItem *a=new AttributeItem (cData);
2201 if (addAttribute (a)) return a;
2206 AttributeItem* VymModel::addAttribute(AttributeItem *ai) // FIXME-2 savestate missing
2208 BranchItem *selbi=getSelectedBranch();
2211 emit (layoutAboutToBeChanged() );
2213 QModelIndex parix=index(selbi);
2214 int n=selbi->getRowNumAppend (ai);
2215 beginInsertRows (parix,n,n);
2216 selbi->appendChild (ai);
2219 emit (layoutChanged() );
2221 ai->createMapObj(mapScene); //FIXME-2 check that...
2228 BranchItem* VymModel::addMapCenter ()
2230 BranchItem *bi=addMapCenter (contextPos);
2232 emitShowSelection();
2237 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2238 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2243 BranchItem* VymModel::addMapCenter(QPointF absPos)
2244 // createMapCenter could then probably be merged with createBranch
2248 QModelIndex parix=index(rootItem);
2250 QList<QVariant> cData;
2251 cData << "VM:addMapCenter" << "undef";
2252 BranchItem *newbi=new BranchItem (cData,rootItem);
2253 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2254 int n=rootItem->getRowNumAppend (newbi);
2256 emit (layoutAboutToBeChanged() );
2257 beginInsertRows (parix,n,n);
2259 rootItem->appendChild (newbi);
2262 emit (layoutChanged() );
2265 newbi->setPositionMode (MapItem::Absolute);
2266 BranchObj *bo=newbi->createMapObj(mapScene);
2267 if (bo) bo->move (absPos);
2272 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2274 // Depending on pos:
2275 // -3 insert in children of parent above selection
2276 // -2 add branch to selection
2277 // -1 insert in children of parent below selection
2278 // 0..n insert in children of parent at pos
2281 QList<QVariant> cData;
2282 cData << "" << "undef";
2287 BranchItem *newbi=new BranchItem (cData);
2288 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2290 emit (layoutAboutToBeChanged() );
2296 n=parbi->getRowNumAppend (newbi);
2297 beginInsertRows (parix,n,n);
2298 parbi->appendChild (newbi);
2300 }else if (num==-1 || num==-3)
2302 // insert below selection
2303 parbi=(BranchItem*)dst->parent();
2306 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2307 beginInsertRows (parix,n,n);
2308 parbi->insertBranch(n,newbi);
2311 emit (layoutChanged() );
2313 // Set color of heading to that of parent
2314 newbi->setHeadingColor (parbi->getHeadingColor());
2316 // save scroll state. If scrolled, automatically select
2317 // new branch in order to tmp unscroll parent...
2318 newbi->createMapObj(mapScene);
2323 BranchItem* VymModel::addNewBranch(int pos)
2325 // Different meaning than num in addNewBranchInt!
2329 BranchItem *newbi=NULL;
2330 BranchItem *selbi=getSelectedBranch();
2334 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2336 newbi=addNewBranchInt (selbi,pos-2);
2344 QString ("addBranch (%1)").arg(pos),
2345 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2348 // emitSelectionChanged(); FIXME-3
2349 latestAddedItem=newbi;
2350 // In Network mode, the client needs to know where the new branch is,
2351 // so we have to pass on this information via saveState.
2352 // TODO: Get rid of this positioning workaround
2353 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2354 sendData ("selectLatestAdded ()");
2355 sendData (QString("move %1").arg(ps));
2364 BranchItem* VymModel::addNewBranchBefore()
2366 BranchItem *newbi=NULL;
2367 BranchItem *selbi=getSelectedBranch();
2368 if (selbi && selbi->getType()==TreeItem::Branch)
2369 // We accept no MapCenter here, so we _have_ a parent
2371 //QPointF p=bo->getRelPos();
2374 // add below selection
2375 newbi=addNewBranchInt (selbi,-1);
2379 //newbi->move2RelPos (p);
2381 // Move selection to new branch
2382 relinkBranch (selbi,newbi,0);
2384 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2385 QString ("Add branch before %1").arg(getObjectName(selbi)));
2387 // FIXME-3 needed? reposition();
2388 // emitSelectionChanged(); FIXME-3
2394 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2400 // Do we need to update frame type?
2401 bool keepFrame=false;
2404 emit (layoutAboutToBeChanged() );
2405 BranchItem *branchpi=(BranchItem*)branch->parent();
2406 // Remove at current position
2407 int n=branch->childNum();
2409 /* FIXME-4 seg since 20091207, if ModelTest active. strange.
2410 // error occured if relinking branch to empty mainbranch
2411 cout<<"VM::relinkBranch:\n";
2412 cout<<" b="<<branch->getHeadingStd()<<endl;
2413 cout<<" dst="<<dst->getHeadingStd()<<endl;
2414 cout<<" pos="<<pos<<endl;
2415 cout<<" n1="<<n<<endl;
2417 beginRemoveRows (index(branchpi),n,n);
2418 branchpi->removeChild (n);
2421 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2423 // Append as last branch to dst
2424 if (dst->branchCount()==0)
2427 n=dst->getFirstBranch()->childNumber();
2428 beginInsertRows (index(dst),n+pos,n+pos);
2429 dst->insertBranch (pos,branch);
2432 // Correct type if necessesary
2433 if (branch->getType()==TreeItem::MapCenter)
2434 branch->setType(TreeItem::Branch);
2436 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2437 branch->updateStyles(keepFrame);
2439 emit (layoutChanged() );
2440 reposition(); // both for moveUp/Down and relinking
2441 if (dst->isScrolled() )
2444 branch->updateVisibility();
2453 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2457 emit (layoutAboutToBeChanged() );
2459 BranchItem *pi=(BranchItem*)(image->parent());
2460 QString oldParString=getSelectString (pi);
2461 // Remove at current position
2462 int n=image->childNum();
2463 beginRemoveRows (index(pi),n,n);
2464 pi->removeChild (n);
2468 QModelIndex dstix=index(dst);
2469 n=dst->getRowNumAppend (image);
2470 beginInsertRows (dstix,n,n+1);
2471 dst->appendChild (image);
2474 // Set new parent also for lmo
2475 if (image->getLMO() && dst->getLMO() )
2476 image->getLMO()->setParObj (dst->getLMO() );
2478 emit (layoutChanged() );
2481 QString("relinkTo (\"%1\")").arg(oldParString),
2483 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2484 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2490 void VymModel::deleteSelection() //FIXME-2 xLinks in a deleted subtree are not restored on undo
2492 BranchItem *selbi=getSelectedBranch();
2497 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2499 BranchItem *pi=(BranchItem*)(deleteItem (selbi));
2502 if (pi->isScrolled() && pi->branchCount()==0)
2505 emitDataHasChanged(pi);
2508 emitShowSelection();
2512 TreeItem *ti=getSelectedItem();
2514 { // Delete other item
2515 TreeItem *pi=ti->parent();
2517 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2519 saveStateChangingPart(
2523 QString("Delete %1").arg(getObjectName(ti))
2527 emitDataHasChanged (pi);
2530 emitShowSelection();
2531 } else if (ti->getType()==TreeItem::XLink)
2533 //FIXME-2 savestate for deleting xlink missing
2536 qWarning ("VymmModel::deleteSelection() unknown type?!");
2540 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2543 BranchItem *selbi=getSelectedBranch();
2547 // Don't use this on mapcenter
2548 if (selbi->depth()<2) return;
2550 pi=(BranchItem*)(selbi->parent());
2551 // Check if we have childs at all to keep
2552 if (selbi->branchCount()==0)
2559 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2560 saveStateChangingPart(
2563 "deleteKeepChildren ()",
2564 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2567 QString sel=getSelectString(selbi);
2569 int pos=selbi->num();
2570 BranchItem *bi=selbi->getFirstBranch();
2573 relinkBranch (bi,pi,pos);
2574 bi=selbi->getFirstBranch();
2580 BranchObj *bo=getSelectedBranchObj();
2583 bo->move2RelPos (p);
2589 void VymModel::deleteChildren()
2592 BranchItem *selbi=getSelectedBranch();
2595 saveStateChangingPart(
2598 "deleteChildren ()",
2599 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2601 emit (layoutAboutToBeChanged() );
2603 QModelIndex ix=index (selbi);
2604 int n=selbi->branchCount()-1;
2605 beginRemoveRows (ix,0,n);
2606 removeRows (0,n+1,ix);
2608 if (selbi->isScrolled()) selbi->unScroll();
2609 emit (layoutChanged() );
2614 TreeItem* VymModel::deleteItem (TreeItem *ti)
2618 TreeItem *pi=ti->parent();
2619 QModelIndex parentIndex=index(pi);
2621 emit (layoutAboutToBeChanged() );
2623 int n=ti->childNum();
2624 beginRemoveRows (parentIndex,n,n);
2625 removeRows (n,1,parentIndex);
2629 emit (layoutChanged() );
2630 if (pi->depth()>=0) return pi;
2635 void VymModel::clearItem (TreeItem *ti)
2639 QModelIndex parentIndex=index(ti);
2640 if (!parentIndex.isValid()) return;
2642 int n=ti->childCount();
2645 emit (layoutAboutToBeChanged() );
2647 beginRemoveRows (parentIndex,0,n-1);
2648 removeRows (0,n,parentIndex);
2652 emit (layoutChanged() );
2658 bool VymModel::scrollBranch(BranchItem *bi)
2662 if (bi->isScrolled()) return false;
2663 if (bi->branchCount()==0) return false;
2664 if (bi->depth()==0) return false;
2665 if (bi->toggleScroll())
2673 QString ("%1 ()").arg(u),
2675 QString ("%1 ()").arg(r),
2676 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2678 emitDataHasChanged(bi);
2679 emitSelectionChanged();
2680 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2687 bool VymModel::unscrollBranch(BranchItem *bi)
2691 if (!bi->isScrolled()) return false;
2692 if (bi->branchCount()==0) return false;
2693 if (bi->depth()==0) return false;
2694 if (bi->toggleScroll())
2702 QString ("%1 ()").arg(u),
2704 QString ("%1 ()").arg(r),
2705 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2707 emitDataHasChanged(bi);
2708 emitSelectionChanged();
2709 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2716 void VymModel::toggleScroll()
2718 BranchItem *bi=(BranchItem*)getSelectedBranch();
2719 if (bi && bi->isBranchLikeType() )
2721 if (bi->isScrolled())
2722 unscrollBranch (bi);
2726 // saveState & reposition are called in above functions
2729 void VymModel::unscrollChildren()
2731 BranchItem *selbi=getSelectedBranch();
2732 BranchItem *prev=NULL;
2733 BranchItem *cur=selbi;
2736 saveStateChangingPart(
2739 QString ("unscrollChildren ()"),
2740 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2744 if (cur->isScrolled())
2746 cur->toggleScroll();
2747 emitDataHasChanged (cur);
2749 cur=nextBranch (cur,prev,true,selbi);
2756 void VymModel::emitExpandAll()
2758 emit (expandAll() );
2761 void VymModel::emitExpandOneLevel()
2763 emit (expandOneLevel () );
2766 void VymModel::emitCollapseOneLevel()
2768 emit (collapseOneLevel () );
2771 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2773 BranchItem *bi=getSelectedBranch();
2777 if (bi->isActiveStandardFlag(name))
2789 QString("%1 (\"%2\")").arg(u).arg(name),
2791 QString("%1 (\"%2\")").arg(r).arg(name),
2792 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2793 bi->toggleStandardFlag (name, master);
2795 emitSelectionChanged();
2799 void VymModel::addFloatImage (const QPixmap &img)
2801 BranchItem *selbi=getSelectedBranch();
2804 ImageItem *ii=createImage (selbi);
2806 ii->setOriginalFilename("No original filename (image added by dropevent)");
2807 QString s=getSelectString(selbi);
2808 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2809 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2811 // FIXME-3 VM needed? scene()->update();
2816 void VymModel::colorBranch (QColor c)
2818 BranchItem *selbi=getSelectedBranch();
2823 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2825 QString ("colorBranch (\"%1\")").arg(c.name()),
2826 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2828 selbi->setHeadingColor(c); // color branch
2833 void VymModel::colorSubtree (QColor c)
2835 BranchItem *selbi=getSelectedBranch();
2838 saveStateChangingPart(
2841 QString ("colorSubtree (\"%1\")").arg(c.name()),
2842 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2844 BranchItem *prev=NULL;
2845 BranchItem *cur=selbi;
2848 cur->setHeadingColor(c); // color links, color children
2849 cur=nextBranch (cur,prev,true,selbi);
2855 QColor VymModel::getCurrentHeadingColor()
2857 BranchItem *selbi=getSelectedBranch();
2858 if (selbi) return selbi->getHeadingColor();
2860 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2866 void VymModel::editURL()
2868 TreeItem *selti=getSelectedItem();
2872 QString text = QInputDialog::getText(
2873 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2874 selti->getURL(), &ok, NULL);
2876 // user entered something and pressed OK
2881 void VymModel::editLocalURL()
2883 TreeItem *selti=getSelectedItem();
2886 QStringList filters;
2887 filters <<"All files (*)";
2888 filters << tr("Text","Filedialog") + " (*.txt)";
2889 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2890 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2891 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2892 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2893 fd->setFilters (filters);
2894 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2895 fd->setDirectory (lastFileDir);
2896 if (! selti->getVymLink().isEmpty() )
2897 fd->selectFile( selti->getURL() );
2900 if ( fd->exec() == QDialog::Accepted )
2902 lastFileDir=QDir (fd->directory().path());
2903 setURL (fd->selectedFile() );
2909 void VymModel::editHeading2URL()
2911 TreeItem *selti=getSelectedItem();
2913 setURL (selti->getHeading());
2916 void VymModel::editBugzilla2URL()
2918 TreeItem *selti=getSelectedItem();
2921 QString h=selti->getHeading();
2922 QRegExp rx("^(\\d+)");
2923 if (rx.indexIn(h) !=-1)
2924 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2928 void VymModel::getBugzillaData()
2930 BranchItem *selbi=getSelectedBranch();
2933 QString url=selbi->getURL();
2936 QRegExp rx("(\\d+)");
2937 if (rx.indexIn(url) !=-1)
2939 QString bugID=rx.cap(1);
2940 qDebug()<< "VM::getBugzillaData bug="<<bugID;
2942 new BugAgent (selbi,bugID);
2948 void VymModel::editFATE2URL()
2950 TreeItem *selti=getSelectedItem();
2953 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
2956 "setURL (\""+selti->getURL()+"\")",
2958 "setURL (\""+url+"\")",
2959 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
2961 selti->setURL (url);
2962 // FIXME-4 updateActions();
2966 void VymModel::editVymLink()
2968 BranchItem *bi=getSelectedBranch();
2971 QStringList filters;
2972 filters <<"VYM map (*.vym)";
2973 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2974 fd->setFilters (filters);
2975 fd->setCaption(vymName+" - " +tr("Link to another map"));
2976 fd->setDirectory (lastFileDir);
2977 if (! bi->getVymLink().isEmpty() )
2978 fd->selectFile( bi->getVymLink() );
2982 if ( fd->exec() == QDialog::Accepted )
2984 lastFileDir=QDir (fd->directory().path());
2987 "setVymLink (\""+bi->getVymLink()+"\")",
2989 "setVymLink (\""+fd->selectedFile()+"\")",
2990 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
2992 setVymLink (fd->selectedFile() );
2997 void VymModel::setVymLink (const QString &s)
2999 // Internal function, no saveState needed
3000 TreeItem *selti=getSelectedItem();
3003 selti->setVymLink(s);
3005 emitDataHasChanged (selti);
3006 emitShowSelection();
3010 void VymModel::deleteVymLink()
3012 BranchItem *bi=getSelectedBranch();
3017 "setVymLink (\""+bi->getVymLink()+"\")",
3019 "setVymLink (\"\")",
3020 QString("Unset vymlink of %1").arg(getObjectName(bi))
3022 bi->setVymLink ("" );
3028 QString VymModel::getVymLink()
3030 BranchItem *bi=getSelectedBranch();
3032 return bi->getVymLink();
3038 QStringList VymModel::getVymLinks()
3041 BranchItem *selbi=getSelectedBranch();
3042 BranchItem *cur=selbi;
3043 BranchItem *prev=NULL;
3046 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
3047 cur=nextBranch (cur,prev,true,selbi);
3053 void VymModel::followXLink(int i)
3056 BranchItem *selbi=getSelectedBranch();
3059 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
3060 if (selbi) select (selbi);
3064 void VymModel::editXLink(int i)
3067 BranchItem *selbi=getSelectedBranch();
3070 XLinkItem *xli=selbi->getXLinkNum(i);
3073 EditXLinkDialog dia;
3075 dia.setSelection(selbi);
3076 if (dia.exec() == QDialog::Accepted)
3078 if (dia.useSettingsGlobal() )
3080 setMapDefXLinkColor (xli->getColor() );
3081 setMapDefXLinkWidth (xli->getWidth() );
3083 if (dia.deleteXLink()) deleteItem (xli);
3093 //////////////////////////////////////////////
3095 //////////////////////////////////////////////
3097 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3099 TreeItem* selti=getSelectedItem();
3100 BranchItem *selbi=getSelectedBranch();
3105 QVariant returnValue;
3107 // Split string s into command and parameters
3108 parser.parseAtom (atom);
3109 QString com=parser.getCommand();
3111 // External commands
3112 /////////////////////////////////////////////////////////////////////
3113 if (com=="addBranch")
3117 parser.setError (Aborted,"Nothing selected");
3118 } else if (! selbi )
3120 parser.setError (Aborted,"Type of selection is not a branch");
3125 if (parser.checkParCount(pl))
3127 if (parser.parCount()==0)
3131 n=parser.parInt (ok,0);
3132 if (ok ) addNewBranch (n);
3136 /////////////////////////////////////////////////////////////////////
3137 } else if (com=="addBranchBefore")
3141 parser.setError (Aborted,"Nothing selected");
3142 } else if (! selbi )
3144 parser.setError (Aborted,"Type of selection is not a branch");
3147 if (parser.parCount()==0)
3149 addNewBranchBefore ();
3152 /////////////////////////////////////////////////////////////////////
3153 } else if (com==QString("addMapCenter"))
3155 if (parser.checkParCount(2))
3157 x=parser.parDouble (ok,0);
3160 y=parser.parDouble (ok,1);
3161 if (ok) addMapCenter (QPointF(x,y));
3164 /////////////////////////////////////////////////////////////////////
3165 } else if (com==QString("addMapReplace"))
3169 parser.setError (Aborted,"Nothing selected");
3170 } else if (! selbi )
3172 parser.setError (Aborted,"Type of selection is not a branch");
3173 } else if (parser.checkParCount(1))
3175 //s=parser.parString (ok,0); // selection
3176 t=parser.parString (ok,0); // path to map
3177 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3178 addMapReplaceInt(getSelectString(selbi),t);
3180 /////////////////////////////////////////////////////////////////////
3181 } else if (com==QString("addMapInsert"))
3183 if (parser.parCount()==2)
3188 parser.setError (Aborted,"Nothing selected");
3189 } else if (! selbi )
3191 parser.setError (Aborted,"Type of selection is not a branch");
3194 t=parser.parString (ok,0); // path to map
3195 n=parser.parInt(ok,1); // position
3196 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3197 addMapInsertInt(t,n);
3199 } else if (parser.parCount()==1)
3201 t=parser.parString (ok,0); // path to map
3202 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3205 parser.setError (Aborted,"Wrong number of parameters");
3206 /////////////////////////////////////////////////////////////////////
3207 } else if (com==QString("addXLink"))
3209 if (parser.parCount()>1)
3211 s=parser.parString (ok,0); // begin
3212 t=parser.parString (ok,1); // end
3213 BranchItem *begin=(BranchItem*)findBySelectString(s);
3214 BranchItem *end=(BranchItem*)findBySelectString(t);
3217 if (begin->isBranchLikeType() && end->isBranchLikeType())
3219 XLinkItem *xl=createXLink (begin,true);
3225 parser.setError (Aborted,"Failed to create xLink");
3228 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3231 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3233 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3234 /////////////////////////////////////////////////////////////////////
3235 } else if (com=="clearFlags")
3239 parser.setError (Aborted,"Nothing selected");
3240 } else if (! selbi )
3242 parser.setError (Aborted,"Type of selection is not a branch");
3243 } else if (parser.checkParCount(0))
3245 selbi->deactivateAllStandardFlags(); //FIXME-2 this probably should emitDataChanged and also setChanged. Similar all other direct changes should be done...
3247 /////////////////////////////////////////////////////////////////////
3248 } else if (com=="colorBranch")
3252 parser.setError (Aborted,"Nothing selected");
3253 } else if (! selbi )
3255 parser.setError (Aborted,"Type of selection is not a branch");
3256 } else if (parser.checkParCount(1))
3258 QColor c=parser.parColor (ok,0);
3259 if (ok) colorBranch (c);
3261 /////////////////////////////////////////////////////////////////////
3262 } else if (com=="colorSubtree")
3266 parser.setError (Aborted,"Nothing selected");
3267 } else if (! selbi )
3269 parser.setError (Aborted,"Type of selection is not a branch");
3270 } else if (parser.checkParCount(1))
3272 QColor c=parser.parColor (ok,0);
3273 if (ok) colorSubtree (c);
3275 /////////////////////////////////////////////////////////////////////
3276 } else if (com=="copy")
3280 parser.setError (Aborted,"Nothing selected");
3281 } else if ( selectionType()!=TreeItem::Branch &&
3282 selectionType()!=TreeItem::MapCenter &&
3283 selectionType()!=TreeItem::Image )
3285 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3286 } else if (parser.checkParCount(0))
3290 /////////////////////////////////////////////////////////////////////
3291 } else if (com=="cut")
3295 parser.setError (Aborted,"Nothing selected");
3296 } else if ( selectionType()!=TreeItem::Branch &&
3297 selectionType()!=TreeItem::MapCenter &&
3298 selectionType()!=TreeItem::Image )
3300 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3301 } else if (parser.checkParCount(0))
3305 /////////////////////////////////////////////////////////////////////
3306 } else if (com=="delete")
3310 parser.setError (Aborted,"Nothing selected");
3312 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3314 parser.setError (Aborted,"Type of selection is wrong.");
3317 else if (parser.checkParCount(0))
3321 /////////////////////////////////////////////////////////////////////
3322 } else if (com=="deleteKeepChildren")
3326 parser.setError (Aborted,"Nothing selected");
3327 } else if (! selbi )
3329 parser.setError (Aborted,"Type of selection is not a branch");
3330 } else if (parser.checkParCount(0))
3332 deleteKeepChildren();
3334 /////////////////////////////////////////////////////////////////////
3335 } else if (com=="deleteChildren")
3339 parser.setError (Aborted,"Nothing selected");
3342 parser.setError (Aborted,"Type of selection is not a branch");
3343 } else if (parser.checkParCount(0))
3347 /////////////////////////////////////////////////////////////////////
3348 } else if (com=="exportAO")
3352 if (parser.parCount()>=1)
3353 // Hey, we even have a filename
3354 fname=parser.parString(ok,0);
3357 parser.setError (Aborted,"Could not read filename");
3360 exportAO (fname,false);
3362 /////////////////////////////////////////////////////////////////////
3363 } else if (com=="exportASCII")
3367 if (parser.parCount()>=1)
3368 // Hey, we even have a filename
3369 fname=parser.parString(ok,0);
3372 parser.setError (Aborted,"Could not read filename");
3375 exportASCII (fname,false);
3377 /////////////////////////////////////////////////////////////////////
3378 } else if (com=="exportImage")
3382 if (parser.parCount()>=2)
3383 // Hey, we even have a filename
3384 fname=parser.parString(ok,0);
3387 parser.setError (Aborted,"Could not read filename");
3390 QString format="PNG";
3391 if (parser.parCount()>=2)
3393 format=parser.parString(ok,1);
3395 exportImage (fname,false,format);
3397 /////////////////////////////////////////////////////////////////////
3398 } else if (com=="exportXHTML")
3402 if (parser.parCount()>=2)
3403 // Hey, we even have a filename
3404 fname=parser.parString(ok,1);
3407 parser.setError (Aborted,"Could not read filename");
3410 exportXHTML (fname,false);
3412 /////////////////////////////////////////////////////////////////////
3413 } else if (com=="exportXML")
3417 if (parser.parCount()>=2)
3418 // Hey, we even have a filename
3419 fname=parser.parString(ok,1);
3422 parser.setError (Aborted,"Could not read filename");
3425 exportXML (fname,false);
3427 /////////////////////////////////////////////////////////////////////
3428 } else if (com=="getHeading")
3432 parser.setError (Aborted,"Nothing selected");
3433 } else if (parser.checkParCount(0))
3434 returnValue=selti->getHeading();
3435 /////////////////////////////////////////////////////////////////////
3436 } else if (com=="importDir")
3440 parser.setError (Aborted,"Nothing selected");
3441 } else if (! selbi )
3443 parser.setError (Aborted,"Type of selection is not a branch");
3444 } else if (parser.checkParCount(1))
3446 s=parser.parString(ok,0);
3447 if (ok) importDirInt(s);
3449 /////////////////////////////////////////////////////////////////////
3450 } else if (com=="relinkTo")
3454 parser.setError (Aborted,"Nothing selected");
3457 if (parser.checkParCount(4))
3459 // 0 selectstring of parent
3460 // 1 num in parent (for branches)
3461 // 2,3 x,y of mainbranch or mapcenter
3462 s=parser.parString(ok,0);
3463 TreeItem *dst=findBySelectString (s);
3466 if (dst->getType()==TreeItem::Branch)
3468 // Get number in parent
3469 n=parser.parInt (ok,1);
3472 relinkBranch (selbi,(BranchItem*)dst,n);
3473 emitSelectionChanged();
3475 } else if (dst->getType()==TreeItem::MapCenter)
3477 relinkBranch (selbi,(BranchItem*)dst);
3478 // Get coordinates of mainbranch
3479 x=parser.parDouble(ok,2);
3482 y=parser.parDouble(ok,3);
3485 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3486 emitSelectionChanged();
3492 } else if ( selti->getType() == TreeItem::Image)
3494 if (parser.checkParCount(1))
3496 // 0 selectstring of parent
3497 s=parser.parString(ok,0);
3498 TreeItem *dst=findBySelectString (s);
3501 if (dst->isBranchLikeType())
3502 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3504 parser.setError (Aborted,"Destination is not a branch");
3507 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3508 /////////////////////////////////////////////////////////////////////
3509 } else if (com=="loadImage")
3513 parser.setError (Aborted,"Nothing selected");
3514 } else if (! selbi )
3516 parser.setError (Aborted,"Type of selection is not a branch");
3517 } else if (parser.checkParCount(1))
3519 s=parser.parString(ok,0);
3520 if (ok) loadFloatImageInt (selbi,s);
3522 /////////////////////////////////////////////////////////////////////
3523 } else if (com=="moveUp")
3527 parser.setError (Aborted,"Nothing selected");
3528 } else if (! selbi )
3530 parser.setError (Aborted,"Type of selection is not a branch");
3531 } else if (parser.checkParCount(0))
3535 /////////////////////////////////////////////////////////////////////
3536 } else if (com=="moveDown")
3540 parser.setError (Aborted,"Nothing selected");
3541 } else if (! selbi )
3543 parser.setError (Aborted,"Type of selection is not a branch");
3544 } else if (parser.checkParCount(0))
3548 /////////////////////////////////////////////////////////////////////
3549 } else if (com=="move")
3553 parser.setError (Aborted,"Nothing selected");
3554 } else if ( selectionType()!=TreeItem::Branch &&
3555 selectionType()!=TreeItem::MapCenter &&
3556 selectionType()!=TreeItem::Image )
3558 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3559 } else if (parser.checkParCount(2))
3561 x=parser.parDouble (ok,0);
3564 y=parser.parDouble (ok,1);
3568 /////////////////////////////////////////////////////////////////////
3569 } else if (com=="moveRel")
3573 parser.setError (Aborted,"Nothing selected");
3574 } else if ( selectionType()!=TreeItem::Branch &&
3575 selectionType()!=TreeItem::MapCenter &&
3576 selectionType()!=TreeItem::Image )
3578 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3579 } else if (parser.checkParCount(2))
3581 x=parser.parDouble (ok,0);
3584 y=parser.parDouble (ok,1);
3585 if (ok) moveRel (x,y);
3588 /////////////////////////////////////////////////////////////////////
3589 } else if (com=="nop")
3591 /////////////////////////////////////////////////////////////////////
3592 } else if (com=="paste")
3596 parser.setError (Aborted,"Nothing selected");
3597 } else if (! selbi )
3599 parser.setError (Aborted,"Type of selection is not a branch");
3600 } else if (parser.checkParCount(1))
3602 n=parser.parInt (ok,0);
3603 if (ok) pasteNoSave(n);
3605 /////////////////////////////////////////////////////////////////////
3606 } else if (com=="qa")
3610 parser.setError (Aborted,"Nothing selected");
3611 } else if (! selbi )
3613 parser.setError (Aborted,"Type of selection is not a branch");
3614 } else if (parser.checkParCount(4))
3617 c=parser.parString (ok,0);
3620 parser.setError (Aborted,"No comment given");
3623 s=parser.parString (ok,1);
3626 parser.setError (Aborted,"First parameter is not a string");
3629 t=parser.parString (ok,2);
3632 parser.setError (Aborted,"Condition is not a string");
3635 u=parser.parString (ok,3);
3638 parser.setError (Aborted,"Third parameter is not a string");
3643 parser.setError (Aborted,"Unknown type: "+s);
3648 parser.setError (Aborted,"Unknown operator: "+t);
3653 parser.setError (Aborted,"Type of selection is not a branch");
3656 if (selbi->getHeading() == u)
3658 cout << "PASSED: " << qPrintable (c) << endl;
3661 cout << "FAILED: " << qPrintable (c) << endl;
3671 /////////////////////////////////////////////////////////////////////
3672 } else if (com=="saveImage")
3674 ImageItem *ii=getSelectedImage();
3677 parser.setError (Aborted,"No image selected");
3678 } else if (parser.checkParCount(2))
3680 s=parser.parString(ok,0);
3683 t=parser.parString(ok,1);
3684 if (ok) saveFloatImageInt (ii,t,s);
3687 /////////////////////////////////////////////////////////////////////
3688 } else if (com=="scroll")
3692 parser.setError (Aborted,"Nothing selected");
3693 } else if (! selbi )
3695 parser.setError (Aborted,"Type of selection is not a branch");
3696 } else if (parser.checkParCount(0))
3698 if (!scrollBranch (selbi))
3699 parser.setError (Aborted,"Could not scroll branch");
3701 /////////////////////////////////////////////////////////////////////
3702 } else if (com=="select")
3704 if (parser.checkParCount(1))
3706 s=parser.parString(ok,0);
3709 /////////////////////////////////////////////////////////////////////
3710 } else if (com=="selectLastBranch")
3714 parser.setError (Aborted,"Nothing selected");
3715 } else if (! selbi )
3717 parser.setError (Aborted,"Type of selection is not a branch");
3718 } else if (parser.checkParCount(0))
3720 BranchItem *bi=selbi->getLastBranch();
3722 parser.setError (Aborted,"Could not select last branch");
3723 select (bi); // FIXME-3 was selectInt
3726 /////////////////////////////////////////////////////////////////////
3727 } else /* FIXME-2 if (com=="selectLastImage")
3731 parser.setError (Aborted,"Nothing selected");
3732 } else if (! selbi )
3734 parser.setError (Aborted,"Type of selection is not a branch");
3735 } else if (parser.checkParCount(0))
3737 FloatImageObj *fio=selb->getLastFloatImage();
3739 parser.setError (Aborted,"Could not select last image");
3740 select (fio); // FIXME-3 was selectInt
3743 /////////////////////////////////////////////////////////////////////
3744 } else */ if (com=="selectLatestAdded")
3746 if (!latestAddedItem)
3748 parser.setError (Aborted,"No latest added object");
3751 if (!select (latestAddedItem))
3752 parser.setError (Aborted,"Could not select latest added object ");
3754 /////////////////////////////////////////////////////////////////////
3755 } else if (com=="setFlag")
3759 parser.setError (Aborted,"Nothing selected");
3760 } else if (! selbi )
3762 parser.setError (Aborted,"Type of selection is not a branch");
3763 } else if (parser.checkParCount(1))
3765 s=parser.parString(ok,0);
3767 selbi->activateStandardFlag(s);
3769 /////////////////////////////////////////////////////////////////////
3770 } else if (com=="setFrameType")
3772 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3774 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3776 else if (parser.checkParCount(1))
3778 s=parser.parString(ok,0);
3779 if (ok) setFrameType (s);
3781 /////////////////////////////////////////////////////////////////////
3782 } else if (com=="setFramePenColor")
3784 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3786 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3788 else if (parser.checkParCount(1))
3790 QColor c=parser.parColor(ok,0);
3791 if (ok) setFramePenColor (c);
3793 /////////////////////////////////////////////////////////////////////
3794 } else if (com=="setFrameBrushColor")
3796 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3798 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3800 else if (parser.checkParCount(1))
3802 QColor c=parser.parColor(ok,0);
3803 if (ok) setFrameBrushColor (c);
3805 /////////////////////////////////////////////////////////////////////
3806 } else if (com=="setFramePadding")
3808 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3810 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3812 else if (parser.checkParCount(1))
3814 n=parser.parInt(ok,0);
3815 if (ok) setFramePadding(n);
3817 /////////////////////////////////////////////////////////////////////
3818 } else if (com=="setFrameBorderWidth")
3820 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3822 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3824 else if (parser.checkParCount(1))
3826 n=parser.parInt(ok,0);
3827 if (ok) setFrameBorderWidth (n);
3829 /////////////////////////////////////////////////////////////////////
3830 /* FIXME-2 else if (com=="setFrameType")
3834 parser.setError (Aborted,"Nothing selected");
3837 parser.setError (Aborted,"Type of selection is not a branch");
3838 } else if (parser.checkParCount(1))
3840 s=parser.parString(ok,0);
3844 /////////////////////////////////////////////////////////////////////
3846 /////////////////////////////////////////////////////////////////////
3847 } else if (com=="setHeading")
3851 parser.setError (Aborted,"Nothing selected");
3852 } else if (! selbi )
3854 parser.setError (Aborted,"Type of selection is not a branch");
3855 } else if (parser.checkParCount(1))
3857 s=parser.parString (ok,0);
3861 /////////////////////////////////////////////////////////////////////
3862 } else if (com=="setHideExport")
3866 parser.setError (Aborted,"Nothing selected");
3867 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3869 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3870 } else if (parser.checkParCount(1))
3872 b=parser.parBool(ok,0);
3873 if (ok) setHideExport (b);
3875 /////////////////////////////////////////////////////////////////////
3876 } else if (com=="setIncludeImagesHorizontally")
3880 parser.setError (Aborted,"Nothing selected");
3883 parser.setError (Aborted,"Type of selection is not a branch");
3884 } else if (parser.checkParCount(1))
3886 b=parser.parBool(ok,0);
3887 if (ok) setIncludeImagesHor(b);
3889 /////////////////////////////////////////////////////////////////////
3890 } else if (com=="setIncludeImagesVertically")
3894 parser.setError (Aborted,"Nothing selected");
3897 parser.setError (Aborted,"Type of selection is not a branch");
3898 } else if (parser.checkParCount(1))
3900 b=parser.parBool(ok,0);
3901 if (ok) setIncludeImagesVer(b);
3903 /////////////////////////////////////////////////////////////////////
3904 } else if (com=="setHideLinkUnselected")
3908 parser.setError (Aborted,"Nothing selected");
3909 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3911 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3912 } else if (parser.checkParCount(1))
3914 b=parser.parBool(ok,0);
3915 if (ok) setHideLinkUnselected(b);
3917 /////////////////////////////////////////////////////////////////////
3918 } else if (com=="setMapAuthor")
3920 if (parser.checkParCount(1))
3922 s=parser.parString(ok,0);
3923 if (ok) setAuthor (s);
3925 /////////////////////////////////////////////////////////////////////
3926 } else if (com=="setMapComment")
3928 if (parser.checkParCount(1))
3930 s=parser.parString(ok,0);
3931 if (ok) setComment(s);
3933 /////////////////////////////////////////////////////////////////////
3934 } else if (com=="setMapBackgroundColor")
3938 parser.setError (Aborted,"Nothing selected");
3939 } else if (! selbi )
3941 parser.setError (Aborted,"Type of selection is not a branch");
3942 } else if (parser.checkParCount(1))
3944 QColor c=parser.parColor (ok,0);
3945 if (ok) setMapBackgroundColor (c);
3947 /////////////////////////////////////////////////////////////////////
3948 } else if (com=="setMapDefLinkColor")
3952 parser.setError (Aborted,"Nothing selected");
3953 } else if (! selbi )
3955 parser.setError (Aborted,"Type of selection is not a branch");
3956 } else if (parser.checkParCount(1))
3958 QColor c=parser.parColor (ok,0);
3959 if (ok) setMapDefLinkColor (c);
3961 /////////////////////////////////////////////////////////////////////
3962 } else if (com=="setMapLinkStyle")
3964 if (parser.checkParCount(1))
3966 s=parser.parString (ok,0);
3967 if (ok) setMapLinkStyle(s);
3969 /////////////////////////////////////////////////////////////////////
3970 } else if (com=="setNote")
3974 parser.setError (Aborted,"Nothing selected");
3975 } else if (! selbi )
3977 parser.setError (Aborted,"Type of selection is not a branch");
3978 } else if (parser.checkParCount(1))
3980 s=parser.parString (ok,0);
3984 /////////////////////////////////////////////////////////////////////
3985 } else if (com=="setSelectionColor")
3987 if (parser.checkParCount(1))
3989 QColor c=parser.parColor (ok,0);
3990 if (ok) setSelectionColorInt (c);
3992 /////////////////////////////////////////////////////////////////////
3993 } else if (com=="setURL")
3997 parser.setError (Aborted,"Nothing selected");
3998 } else if (! selbi )
4000 parser.setError (Aborted,"Type of selection is not a branch");
4001 } else if (parser.checkParCount(1))
4003 s=parser.parString (ok,0);
4006 /////////////////////////////////////////////////////////////////////
4007 } else if (com=="setVymLink")
4011 parser.setError (Aborted,"Nothing selected");
4012 } else if (! selbi )
4014 parser.setError (Aborted,"Type of selection is not a branch");
4015 } else if (parser.checkParCount(1))
4017 s=parser.parString (ok,0);
4018 if (ok) setVymLink(s);
4020 } else if (com=="sortChildren")
4024 parser.setError (Aborted,"Nothing selected");
4025 } else if (! selbi )
4027 parser.setError (Aborted,"Type of selection is not a branch");
4028 } else if (parser.checkParCount(0))
4031 } else if (parser.checkParCount(1))
4033 b=parser.parBool(ok,0);
4034 if (ok) sortChildren(b);
4036 /////////////////////////////////////////////////////////////////////
4037 } else if (com=="toggleFlag")
4041 parser.setError (Aborted,"Nothing selected");
4042 } else if (! selbi )
4044 parser.setError (Aborted,"Type of selection is not a branch");
4045 } else if (parser.checkParCount(1))
4047 s=parser.parString(ok,0);
4049 selbi->toggleStandardFlag(s);
4051 /////////////////////////////////////////////////////////////////////
4052 } else if (com=="unscroll")
4056 parser.setError (Aborted,"Nothing selected");
4057 } else if (! selbi )
4059 parser.setError (Aborted,"Type of selection is not a branch");
4060 } else if (parser.checkParCount(0))
4062 if (!unscrollBranch (selbi))
4063 parser.setError (Aborted,"Could not unscroll branch");
4065 /////////////////////////////////////////////////////////////////////
4066 } else if (com=="unscrollChildren")
4070 parser.setError (Aborted,"Nothing selected");
4071 } else if (! selbi )
4073 parser.setError (Aborted,"Type of selection is not a branch");
4074 } else if (parser.checkParCount(0))
4076 unscrollChildren ();
4078 /////////////////////////////////////////////////////////////////////
4079 } else if (com=="unsetFlag")
4083 parser.setError (Aborted,"Nothing selected");
4084 } else if (! selbi )
4086 parser.setError (Aborted,"Type of selection is not a branch");
4087 } else if (parser.checkParCount(1))
4089 s=parser.parString(ok,0);
4091 selbi->deactivateStandardFlag(s);
4094 parser.setError (Aborted,"Unknown command");
4097 if (parser.errorLevel()==NoError)
4105 // TODO Error handling
4106 qWarning("VymModel::parseAtom: Error!");
4108 qWarning(parser.errorMessage());
4110 errorMsg=parser.errorMessage();
4115 QVariant VymModel::runScript (const QString &script)
4117 parser.setScript (script);
4122 while (parser.next() && noErr)
4124 r=parseAtom(parser.getAtom(),noErr,errMsg);
4125 if (!noErr) //FIXME-3 need dialog box here
4126 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4131 void VymModel::setExportMode (bool b)
4133 // should be called before and after exports
4134 // depending on the settings
4135 if (b && settings.value("/export/useHideExport","true")=="true")
4136 setHideTmpMode (TreeItem::HideExport);
4138 setHideTmpMode (TreeItem::HideNone);
4141 void VymModel::exportImage(QString fname, bool askName, QString format)
4145 fname=getMapName()+".png";
4152 QFileDialog *fd=new QFileDialog (NULL);
4153 fd->setCaption (tr("Export map as image"));
4154 fd->setDirectory (lastImageDir);
4155 fd->setFileMode(QFileDialog::AnyFile);
4156 fd->setFilters (imageIO.getFilters() );
4159 fl=fd->selectedFiles();
4161 format=imageIO.getType(fd->selectedFilter());
4165 setExportMode (true);
4166 mapEditor->getScene()->update(); // FIXME-3 check this...
4167 QImage img (mapEditor->getImage()); //FIXME-3 calls getTotalBBox, but also in ExportHTML::doExport()
4168 img.save(fname, format);
4169 setExportMode (false);
4173 void VymModel::exportXML(QString dir, bool askForName)
4177 dir=browseDirectory(NULL,tr("Export XML to directory"));
4178 if (dir =="" && !reallyWriteDirectory(dir) )
4182 // Hide stuff during export, if settings want this
4183 setExportMode (true);
4185 // Create subdirectories
4188 // write to directory //FIXME-4 check totalBBox here...
4189 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4192 file.setName ( dir + "/"+mapName+".xml");
4193 if ( !file.open( QIODevice::WriteOnly ) )
4195 // This should neverever happen
4196 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4200 // Write it finally, and write in UTF8, no matter what
4201 QTextStream ts( &file );
4202 ts.setEncoding (QTextStream::UnicodeUTF8);
4206 // Now write image, too
4207 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4209 setExportMode (false);
4212 void VymModel::exportAO (QString fname,bool askName)
4217 ex.setFile (mapName+".txt");
4223 //ex.addFilter ("TXT (*.txt)");
4224 ex.setDir(lastImageDir);
4225 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4230 setExportMode(true);
4232 setExportMode(false);
4236 void VymModel::exportASCII(QString fname,bool askName)
4241 ex.setFile (mapName+".txt");
4247 //ex.addFilter ("TXT (*.txt)");
4248 ex.setDir(lastImageDir);
4249 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4254 setExportMode(true);
4256 setExportMode(false);
4260 void VymModel::exportHTML (const QString &dir, bool askForName) //FIXME-2 own dialogue missing and also option to save settings in map
4262 ExportXHTMLDialog dia(NULL);
4263 dia.setFilePath (filePath );
4264 dia.setMapName (mapName );
4266 if (dir!="") dia.setDir (dir);
4272 if (dia.exec()!=QDialog::Accepted)
4277 // Check, if warnings should be used before overwriting
4278 // the output directory
4279 if (d.exists() && d.count()>0)
4282 warn.showCancelButton (true);
4283 warn.setText(QString(
4284 "The directory %1 is not empty.\n"
4285 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4286 warn.setCaption("Warning: Directory not empty");
4287 warn.setShowAgainName("mainwindow/export-XML-overwrite-dir");
4289 if (warn.exec()!=QDialog::Accepted) ok=false;
4295 // Hide stuff during export, if settings want this
4296 setExportMode (true);
4298 ExportHTML ex (this);
4299 ex.setFile (d.path()+"/"+mapName+".html");
4300 cout << "VM::exportHTML writing "<<ex.getFile().toStdString()<<endl;
4302 setExportMode (false);
4304 //exportXML (dia.getDir(),false );
4305 //dia.doExport(mapName );
4306 //if (dia.hasChanged()) setChanged();
4309 exportImage (d.path()+"/"+mapName+".png",false,"PNG");
4314 void VymModel::exportXHTML (const QString &dir, bool askForName)
4316 ExportXHTMLDialog dia(NULL);
4317 dia.setFilePath (filePath );
4318 dia.setMapName (mapName );
4320 if (dir!="") dia.setDir (dir);
4326 if (dia.exec()!=QDialog::Accepted)
4330 QDir d (dia.getDir());
4331 // Check, if warnings should be used before overwriting
4332 // the output directory
4333 if (d.exists() && d.count()>0)
4336 warn.showCancelButton (true);
4337 warn.setText(QString(
4338 "The directory %1 is not empty.\n"
4339 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4340 warn.setCaption("Warning: Directory not empty");
4341 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4343 if (warn.exec()!=QDialog::Accepted) ok=false;
4350 exportXML (dia.getDir(),false );
4351 dia.doExport(mapName );
4352 //if (dia.hasChanged()) setChanged();
4356 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4361 if (ex.setConfigFile(cf))
4363 setExportMode (true);
4364 ex.exportPresentation();
4365 setExportMode (false);
4372 //////////////////////////////////////////////
4374 //////////////////////////////////////////////
4376 void VymModel::registerEditor(QWidget *me)
4378 mapEditor=(MapEditor*)me;
4381 void VymModel::unregisterEditor(QWidget *)
4386 void VymModel::setContextPos(QPointF p)
4391 void VymModel::unsetContextPos()
4393 contextPos=QPointF();
4396 void VymModel::updateNoteFlag()
4398 TreeItem *selti=getSelectedItem();
4407 if (textEditor->isEmpty())
4410 selti->setNote (textEditor->getText());
4411 emitDataHasChanged(selti);
4415 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4417 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4418 if (blockReposition) return;
4420 for (int i=0;i<rootItem->branchCount(); i++)
4421 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4422 //emitSelectionChanged();
4426 void VymModel::setMapLinkStyle (const QString & s)
4431 case LinkableMapObj::Line :
4434 case LinkableMapObj::Parabel:
4435 snow="StyleParabel";
4437 case LinkableMapObj::PolyLine:
4438 snow="StylePolyLine";
4440 case LinkableMapObj::PolyParabel:
4441 snow="StylePolyParabel";
4444 snow="UndefinedStyle";
4449 QString("setMapLinkStyle (\"%1\")").arg(s),
4450 QString("setMapLinkStyle (\"%1\")").arg(snow),
4451 QString("Set map link style (\"%1\")").arg(s)
4455 linkstyle=LinkableMapObj::Line;
4456 else if (s=="StyleParabel")
4457 linkstyle=LinkableMapObj::Parabel;
4458 else if (s=="StylePolyLine")
4459 linkstyle=LinkableMapObj::PolyLine;
4460 else if (s=="StylePolyParabel")
4461 linkstyle=LinkableMapObj::PolyParabel;
4463 linkstyle=LinkableMapObj::UndefinedStyle;
4465 BranchItem *cur=NULL;
4466 BranchItem *prev=NULL;
4468 nextBranch (cur,prev);
4471 bo=(BranchObj*)(cur->getLMO() );
4472 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4473 cur=nextBranch(cur,prev);
4478 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4483 uint VymModel::getID()
4488 void VymModel::setMapDefLinkColor(QColor col)
4490 if ( !col.isValid() ) return;
4492 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4493 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4494 QString("Set map link color to %1").arg(col.name())
4498 BranchItem *cur=NULL;
4499 BranchItem *prev=NULL;
4501 cur=nextBranch(cur,prev);
4504 bo=(BranchObj*)(cur->getLMO() );
4506 nextBranch(cur,prev);
4511 void VymModel::setMapLinkColorHintInt()
4513 // called from setMapLinkColorHint(lch) or at end of parse
4514 BranchItem *cur=NULL;
4515 BranchItem *prev=NULL;
4517 cur=nextBranch(cur,prev);
4520 bo=(BranchObj*)(cur->getLMO() );
4522 cur=nextBranch(cur,prev);
4526 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4529 setMapLinkColorHintInt();
4532 void VymModel::toggleMapLinkColorHint()
4534 if (linkcolorhint==LinkableMapObj::HeadingColor)
4535 linkcolorhint=LinkableMapObj::DefaultColor;
4537 linkcolorhint=LinkableMapObj::HeadingColor;
4538 BranchItem *cur=NULL;
4539 BranchItem *prev=NULL;
4541 cur=nextBranch(cur,prev);
4544 bo=(BranchObj*)(cur->getLMO() );
4546 nextBranch(cur,prev);
4550 void VymModel::selectMapBackgroundImage () // FIXME-3 for using background image: view.setCacheMode(QGraphicsView::CacheBackground); Also this belongs into ME
4552 Q3FileDialog *fd=new Q3FileDialog( NULL);
4553 fd->setMode (Q3FileDialog::ExistingFile);
4554 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4555 ImagePreview *p =new ImagePreview (fd);
4556 fd->setContentsPreviewEnabled( TRUE );
4557 fd->setContentsPreview( p, p );
4558 fd->setPreviewMode( Q3FileDialog::Contents );
4559 fd->setCaption(vymName+" - " +tr("Load background image"));
4560 fd->setDir (lastImageDir);
4563 if ( fd->exec() == QDialog::Accepted )
4565 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4566 lastImageDir=QDir (fd->dirPath());
4567 setMapBackgroundImage (fd->selectedFile());
4571 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4573 QColor oldcol=mapScene->backgroundBrush().color();
4577 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4579 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4580 QString("Set background color of map to %1").arg(col.name()));
4583 brush.setTextureImage (QPixmap (fn));
4584 mapScene->setBackgroundBrush(brush);
4587 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4589 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4590 if ( !col.isValid() ) return;
4591 setMapBackgroundColor( col );
4595 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4597 QColor oldcol=mapScene->backgroundBrush().color();
4599 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4600 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4601 QString("Set background color of map to %1").arg(col.name()));
4602 mapScene->setBackgroundBrush(col);
4605 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4607 return mapScene->backgroundBrush().color();
4611 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4613 return linkcolorhint;
4616 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4618 return defLinkColor;
4621 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4626 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4628 return defXLinkColor;
4631 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4636 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4638 return defXLinkWidth;
4641 void VymModel::move(const double &x, const double &y)
4644 MapItem *seli = (MapItem*)getSelectedItem();
4645 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4647 LinkableMapObj *lmo=seli->getLMO();
4650 QPointF ap(lmo->getAbsPos());
4654 QString ps=qpointFToString(ap);
4655 QString s=getSelectString(seli);
4658 s, "move "+qpointFToString(to),
4659 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4662 emitSelectionChanged();
4668 void VymModel::moveRel (const double &x, const double &y)
4671 MapItem *seli = (MapItem*)getSelectedItem();
4672 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4674 LinkableMapObj *lmo=seli->getLMO();
4677 QPointF rp(lmo->getRelPos());
4681 QString ps=qpointFToString (lmo->getRelPos());
4682 QString s=getSelectString(seli);
4685 s, "moveRel "+qpointFToString(to),
4686 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4687 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4689 lmo->updateLinkGeometry();
4690 emitSelectionChanged();
4697 void VymModel::animate()
4699 animationTimer->stop();
4702 while (i<animObjList.size() )
4704 bo=(BranchObj*)animObjList.at(i);
4709 animObjList.removeAt(i);
4716 QItemSelection sel=selModel->selection();
4717 emit (selectionChanged(sel,sel));
4720 if (!animObjList.isEmpty()) animationTimer->start();
4724 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4726 if (start==dest) return;
4727 if (bo && bo->getTreeItem()->depth()>0)
4730 ap.setStart (start);
4732 ap.setTicks (animationTicks);
4733 ap.setAnimated (true);
4734 bo->setAnimation (ap);
4735 animObjList.append( bo );
4736 animationTimer->setSingleShot (true);
4737 animationTimer->start(animationInterval);
4741 void VymModel::stopAnimation (MapObj *mo)
4743 int i=animObjList.indexOf(mo);
4745 animObjList.removeAt (i);
4748 void VymModel::sendSelection()
4750 if (netstate!=Server) return;
4751 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4754 void VymModel::newServer()
4758 tcpServer = new QTcpServer(this);
4759 if (!tcpServer->listen(QHostAddress::Any,port)) {
4760 QMessageBox::critical(NULL, "vym server",
4761 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4762 //FIXME-3 needed? we are no widget any longer... close();
4765 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4767 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4770 void VymModel::connectToServer()
4773 server="salam.suse.de";
4775 clientSocket = new QTcpSocket (this);
4776 clientSocket->abort();
4777 clientSocket->connectToHost(server ,port);
4778 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4779 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4780 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4782 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4787 void VymModel::newClient()
4789 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4790 connect(newClient, SIGNAL(disconnected()),
4791 newClient, SLOT(deleteLater()));
4793 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4795 clientList.append (newClient);
4799 void VymModel::sendData(const QString &s)
4801 if (clientList.size()==0) return;
4803 // Create bytearray to send
4805 QDataStream out(&block, QIODevice::WriteOnly);
4806 out.setVersion(QDataStream::Qt_4_0);
4808 // Reserve some space for blocksize
4811 // Write sendCounter
4812 out << sendCounter++;
4817 // Go back and write blocksize so far
4818 out.device()->seek(0);
4819 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4823 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4825 for (int i=0; i<clientList.size(); ++i)
4827 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4828 clientList.at(i)->write (block);
4832 void VymModel::readData ()
4834 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4837 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4841 QDataStream in(clientSocket);
4842 in.setVersion(QDataStream::Qt_4_0);
4850 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4853 parseAtom (t,noErr,errMsg);
4859 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4861 switch (socketError) {
4862 case QAbstractSocket::RemoteHostClosedError:
4864 case QAbstractSocket::HostNotFoundError:
4865 QMessageBox::information(NULL, vymName +" Network client",
4866 "The host was not found. Please check the "
4867 "host name and port settings.");
4869 case QAbstractSocket::ConnectionRefusedError:
4870 QMessageBox::information(NULL, vymName + " Network client",
4871 "The connection was refused by the peer. "
4872 "Make sure the fortune server is running, "
4873 "and check that the host name and port "
4874 "settings are correct.");
4877 QMessageBox::information(NULL, vymName + " Network client",
4878 QString("The following error occurred: %1.")
4879 .arg(clientSocket->errorString()));
4883 /* FIXME-3 Playing with DBUS...
4884 QDBusVariant VymModel::query (const QString &query)
4886 TreeItem *selti=getSelectedItem();
4888 return QDBusVariant (selti->getHeading());
4890 return QDBusVariant ("Nothing selected.");
4894 void VymModel::testslot() //FIXME-3 Playing with DBUS
4896 cout << "VM::testslot called\n";
4899 void VymModel::selectMapSelectionColor()
4901 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4902 setSelectionColor (col);
4905 void VymModel::setSelectionColorInt (QColor col)
4907 if ( !col.isValid() ) return;
4909 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4910 QString("setSelectionColor (%1)").arg(col.name()),
4911 QString("Set color of selection box to %1").arg(col.name())
4914 mapEditor->setSelectionColor (col);
4917 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4919 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4920 //FIXME-3 emitShowSelection();
4924 void VymModel::emitSelectionChanged()
4926 QItemSelection newsel=selModel->selection();
4927 emitSelectionChanged (newsel);
4930 void VymModel::setSelectionColor(QColor col)
4932 if ( !col.isValid() ) return;
4934 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4935 QString("setSelectionColor (%1)").arg(col.name()),
4936 QString("Set color of selection box to %1").arg(col.name())
4938 setSelectionColorInt (col);
4941 QColor VymModel::getSelectionColor()
4943 return mapEditor->getSelectionColor();
4946 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4949 for (int i=0;i<rootItem->branchCount();i++)
4950 rootItem->getBranchNum(i)->setHideTmp (mode);
4952 if (mode==TreeItem::HideExport)
4958 //////////////////////////////////////////////
4959 // Selection related
4960 //////////////////////////////////////////////
4962 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4967 QItemSelectionModel* VymModel::getSelectionModel()
4972 void VymModel::setSelectionBlocked (bool b)
4977 bool VymModel::isSelectionBlocked()
4979 return selectionBlocked;
4982 bool VymModel::select ()
4984 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
4987 bool VymModel::select (const QString &s)
4994 TreeItem *ti=findBySelectString(s);
4995 if (ti) return select (index(ti));
4999 bool VymModel::select (LinkableMapObj *lmo)
5001 QItemSelection oldsel=selModel->selection();
5004 return select (index (lmo->getTreeItem()) );
5009 bool VymModel::select (TreeItem *ti)
5011 if (ti) return select (index(ti));
5015 bool VymModel::select (const QModelIndex &index)
5017 if (index.isValid() )
5019 selModel->select (index,QItemSelectionModel::ClearAndSelect );
5020 BranchItem *bi=getSelectedBranch();
5021 if (bi) bi->setLastSelectedBranch();
5027 void VymModel::unselect()
5029 if (!selModel->selectedIndexes().isEmpty())
5031 lastSelectString=getSelectString();
5032 selModel->clearSelection();
5036 bool VymModel::reselect()
5038 return select (lastSelectString);
5041 void VymModel::emitShowSelection()
5043 if (!blockReposition)
5044 emit (showSelection() );
5047 void VymModel::emitNoteHasChanged (TreeItem *ti)
5049 QModelIndex ix=index(ti);
5050 emit (noteHasChanged (ix) );
5053 void VymModel::emitDataHasChanged (TreeItem *ti)
5055 QModelIndex ix=index(ti);
5056 emit (dataChanged (ix,ix) );
5060 bool VymModel::selectFirstBranch()
5062 TreeItem *ti=getSelectedBranch();
5065 TreeItem *par=ti->parent();
5068 TreeItem *ti2=par->getFirstBranch();
5069 if (ti2) return select(ti2);
5075 bool VymModel::selectLastBranch()
5077 TreeItem *ti=getSelectedBranch();
5080 TreeItem *par=ti->parent();
5083 TreeItem *ti2=par->getLastBranch();
5084 if (ti2) return select(ti2);
5090 bool VymModel::selectLastSelectedBranch()
5092 BranchItem *bi=getSelectedBranch();
5095 bi=bi->getLastSelectedBranch();
5096 if (bi) return select (bi);
5101 bool VymModel::selectParent()
5103 TreeItem *ti=getSelectedItem();
5114 TreeItem::Type VymModel::selectionType()
5116 QModelIndexList list=selModel->selectedIndexes();
5117 if (list.isEmpty()) return TreeItem::Undefined;
5118 TreeItem *ti = getItem (list.first() );
5119 return ti->getType();
5123 LinkableMapObj* VymModel::getSelectedLMO()
5125 QModelIndexList list=selModel->selectedIndexes();
5126 if (!list.isEmpty() )
5128 TreeItem *ti = getItem (list.first() );
5129 TreeItem::Type type=ti->getType();
5130 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5131 return ((MapItem*)ti)->getLMO();
5136 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5138 TreeItem *ti = getSelectedBranch();
5140 return (BranchObj*)( ((MapItem*)ti)->getLMO());
5145 BranchItem* VymModel::getSelectedBranch()
5147 QModelIndexList list=selModel->selectedIndexes();
5148 if (!list.isEmpty() )
5150 TreeItem *ti = getItem (list.first() );
5151 TreeItem::Type type=ti->getType();
5152 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5153 return (BranchItem*)ti;
5158 ImageItem* VymModel::getSelectedImage()
5160 QModelIndexList list=selModel->selectedIndexes();
5161 if (!list.isEmpty())
5163 TreeItem *ti=getItem (list.first());
5164 if (ti && ti->getType()==TreeItem::Image)
5165 return (ImageItem*)ti;
5170 AttributeItem* VymModel::getSelectedAttribute()
5172 QModelIndexList list=selModel->selectedIndexes();
5173 if (!list.isEmpty() )
5175 TreeItem *ti = getItem (list.first() );
5176 TreeItem::Type type=ti->getType();
5177 if (type ==TreeItem::Attribute)
5178 return (AttributeItem*)ti;
5183 TreeItem* VymModel::getSelectedItem()
5185 QModelIndexList list=selModel->selectedIndexes();
5186 if (!list.isEmpty() )
5187 return getItem (list.first() );
5192 QModelIndex VymModel::getSelectedIndex()
5194 QModelIndexList list=selModel->selectedIndexes();
5195 if (list.isEmpty() )
5196 return QModelIndex();
5198 return list.first();
5201 QString VymModel::getSelectString ()
5203 return getSelectString (getSelectedItem());
5206 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5208 if (!lmo) return QString();
5209 return getSelectString (lmo->getTreeItem() );
5212 QString VymModel::getSelectString (TreeItem *ti)
5216 switch (ti->getType())
5218 case TreeItem::MapCenter: s="mc:"; break;
5219 case TreeItem::Branch: s="bo:";break;
5220 case TreeItem::Image: s="fi:";break;
5221 case TreeItem::Attribute: s="ai:";break;
5222 case TreeItem::XLink: s="xl:";break;
5224 s="unknown type in VymModel::getSelectString()";
5227 s= s + QString("%1").arg(ti->num());
5229 // call myself recursively
5230 s= getSelectString(ti->parent()) +","+s;