1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
10 #include "editxlinkdialog.h"
12 #include "exporthtmldialog.h"
13 #include "exportxhtmldialog.h"
15 #include "findresultmodel.h"
16 #include "geometry.h" // for addBBox
17 #include "mainwindow.h"
22 #include "warningdialog.h"
23 #include "xlinkitem.h"
24 #include "xml-freemind.h"
30 extern Main *mainWindow;
31 extern QDBusConnection dbusConnection;
33 extern Settings settings;
34 extern QString tmpVymDir;
36 extern TextEditor *textEditor;
37 extern FlagRow *standardFlagsMaster;
39 extern QString clipboardDir;
40 extern QString clipboardFile;
41 extern bool clipboardEmpty;
43 extern ImageIO imageIO;
45 extern QString vymName;
46 extern QString vymVersion;
47 extern QDir vymBaseDir;
49 extern QDir lastImageDir;
50 extern QDir lastFileDir;
52 extern Settings settings;
54 uint VymModel::idLast=0; // make instance
58 //cout << "Const VymModel\n";
60 rootItem->setModel (this);
66 //cout << "Destr VymModel\n";
67 autosaveTimer->stop();
68 fileChangedTimer->stop();
72 void VymModel::clear()
74 while (rootItem->childCount() >0)
75 deleteItem (rootItem->getChildNum(0) );
78 void VymModel::init ()
83 // Also no scene yet (should not be needed anyway) FIXME-3 VM
97 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
98 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
99 mainWindow->updateHistory (undoSet);
102 makeTmpDirectories();
107 fileName=tr("unnamed");
109 blockReposition=false;
110 blockSaveState=false;
112 autosaveTimer=new QTimer (this);
113 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
115 fileChangedTimer=new QTimer (this);
116 fileChangedTimer->start(3000);
117 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
122 selectionBlocked=false;
127 // animations // FIXME-3 switch to new animation system
128 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
129 animationTicks=settings.readNumEntry("/animation/ticks",10);
130 animationInterval=settings.readNumEntry("/animation/interval",50);
132 animationTimer=new QTimer (this);
133 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
136 defLinkColor=QColor (0,0,255);
137 defXLinkColor=QColor (180,180,180);
138 linkcolorhint=LinkableMapObj::DefaultColor;
139 linkstyle=LinkableMapObj::PolyParabel;
141 defXLinkColor=QColor (230,230,230);
144 hidemode=TreeItem::HideNone;
149 //Initialize DBUS object
150 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
151 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapID),this))
152 qWarning ("VymModel: Couldn't register DBUS object!");
155 void VymModel::makeTmpDirectories()
157 // Create unique temporary directories
158 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapID);
159 histPath = tmpMapDir+"/history";
165 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
170 bool VymModel::isRepositionBlocked()
172 return blockReposition;
175 void VymModel::updateActions() // FIXME-4 maybe don't update if blockReposition is set
177 //cout << "VM::updateActions \n";
178 // Tell mainwindow to update states of actions
179 mainWindow->updateActions();
184 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
186 // tmpdir temporary directory to which data will be written
187 // prefix mapname, which will be appended to images etc.
188 // writeflags Only write flags for "real" save of map, not undo
189 // offset offset of bbox of whole map in scene.
190 // Needed for XML export
199 case LinkableMapObj::Line:
202 case LinkableMapObj::Parabel:
205 case LinkableMapObj::PolyLine:
209 ls="StylePolyParabel";
213 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
215 if (linkcolorhint==LinkableMapObj::HeadingColor)
216 colhint=xml.attribut("linkColorHint","HeadingColor");
218 QString mapAttr=xml.attribut("version",vymVersion);
220 mapAttr+= xml.attribut("author",author) +
221 xml.attribut("comment",comment) +
222 xml.attribut("date",getDate()) +
223 xml.attribut("branchCount", QString().number(branchCount())) +
224 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
225 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
226 xml.attribut("linkStyle", ls ) +
227 xml.attribut("linkColor", defLinkColor.name() ) +
228 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
229 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
230 xml.attribut("mapZoomFactor", QString().setNum(mapEditor->getZoomFactorTarget()) ) +
232 s+=xml.beginElement("vymmap",mapAttr);
235 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
236 standardFlagsMaster->resetUsedCounter();
238 // Build xml recursivly
240 // Save all mapcenters as complete map, if saveSel not set
241 s+=saveTreeToDir(tmpdir,prefix,offset);
244 switch (saveSel->getType())
246 case TreeItem::Branch:
248 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
250 case TreeItem::MapCenter:
252 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
254 case TreeItem::Image:
256 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
259 // other types shouldn't be safed directly...
264 // Save local settings
265 s+=settings.getDataXML (destPath);
268 if (getSelectedItem() && !saveSel )
269 s+=xml.valueElement("select",getSelectString());
272 s+=xml.endElement("vymmap");
274 //cout << s.toStdString() << endl;
276 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
280 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset)
284 for (int i=0; i<rootItem->branchCount(); i++)
285 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
289 void VymModel::setFilePath(QString fpath, QString destname)
291 if (fpath.isEmpty() || fpath=="")
298 filePath=fpath; // becomes absolute path
299 fileName=fpath; // gets stripped of path
300 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
302 // If fpath is not an absolute path, complete it
303 filePath=QDir(fpath).absPath();
304 fileDir=filePath.left (1+filePath.findRev ("/"));
306 // Set short name, too. Search from behind:
307 int i=fileName.findRev("/");
308 if (i>=0) fileName=fileName.remove (0,i+1);
310 // Forget the .vym (or .xml) for name of map
311 mapName=fileName.left(fileName.findRev(".",-1,true) );
315 void VymModel::setFilePath(QString fpath)
317 setFilePath (fpath,fpath);
320 QString VymModel::getFilePath()
325 QString VymModel::getFileName()
330 QString VymModel::getMapName()
335 QString VymModel::getDestPath()
340 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
342 ErrorCode err=success;
344 parseBaseHandler *handler;
348 case VymMap: handler=new parseVYMHandler; break;
349 case FreemindMap : handler=new parseFreemindHandler; break;
351 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
352 "Unknown FileType in VymModel::load()");
356 bool zipped_org=zipped;
360 selModel->clearSelection();
363 BranchItem *bi=getSelectedBranch();
364 if (!bi) return aborted;
365 if (lmode==ImportAdd)
366 saveStateChangingPart(
369 QString("addMapInsert (%1)").arg(fname),
370 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
372 saveStateChangingPart(
375 QString("addMapReplace(%1)").arg(fname),
376 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
380 // Create temporary directory for packing
382 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
385 QMessageBox::critical( 0, tr( "Critical Load Error" ),
386 tr("Couldn't create temporary directory before load\n"));
391 err=unzipDir (tmpZipDir,fname);
401 // Look for mapname.xml
402 xmlfile= fname.left(fname.findRev(".",-1,true));
403 xmlfile=xmlfile.section( '/', -1 );
404 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
405 if (!mfile.exists() )
407 // mapname.xml does not exist, well,
408 // maybe someone renamed the mapname.vym file...
409 // Try to find any .xml in the toplevel
410 // directory of the .vym file
411 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
412 if (flist.count()==1)
414 // Only one entry, take this one
415 xmlfile=tmpZipDir + "/"+flist.first();
418 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
419 *it=tmpZipDir + "/" + *it;
420 // TODO Multiple entries, load all (but only the first one into this ME)
421 //mainWindow->fileLoadFromTmp (flist);
422 //returnCode=1; // Silently forget this attempt to load
423 qWarning ("MainWindow::load (fn) multimap found...");
426 if (flist.isEmpty() )
428 QMessageBox::critical( 0, tr( "Critical Load Error" ),
429 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
432 } //file doesn't exist
434 xmlfile=mfile.name();
437 QFile file( xmlfile);
439 // I am paranoid: file should exist anyway
440 // according to check in mainwindow.
443 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
444 tr(QString("Couldn't open map %1").arg(file.name())));
448 bool blockSaveStateOrg=blockSaveState;
449 blockReposition=true;
451 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
452 QXmlInputSource source( file);
453 QXmlSimpleReader reader;
454 reader.setContentHandler( handler );
455 reader.setErrorHandler( handler );
456 handler->setModel ( this);
459 // We need to set the tmpDir in order to load files with rel. path
464 tmpdir=fname.left(fname.findRev("/",-1));
465 handler->setTmpDir (tmpdir);
466 handler->setInputFile (file.name());
467 handler->setLoadMode (lmode);
468 bool ok = reader.parse( source );
469 blockReposition=false;
470 blockSaveState=blockSaveStateOrg;
471 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
476 emitSelectionChanged();
482 autosaveTimer->stop();
485 // Reset timestamp to check for later updates of file
486 fileChangedTime=QFileInfo (destPath).lastModified();
489 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
490 tr( handler->errorProtocol() ) );
492 // Still return "success": the map maybe at least
493 // partially read by the parser
498 removeDir (QDir(tmpZipDir));
500 // Restore original zip state
505 if (mapEditor) mapEditor->setZoomFactorTarget (zoomFactor);
509 ErrorCode VymModel::save (const SaveMode &savemode)
513 QString safeFilePath;
515 ErrorCode err=success;
519 mapFileName=mapName+".xml";
521 // use name given by user, even if he chooses .doc
522 mapFileName=fileName;
524 // Look, if we should zip the data:
527 QMessageBox mb( vymName,
528 tr("The map %1\ndid not use the compressed "
529 "vym file format.\nWriting it uncompressed will also write images \n"
530 "and flags and thus may overwrite files in the "
531 "given directory\n\nDo you want to write the map").arg(filePath),
532 QMessageBox::Warning,
533 QMessageBox::Yes | QMessageBox::Default,
535 QMessageBox::Cancel | QMessageBox::Escape);
536 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
537 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
538 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
541 case QMessageBox::Yes:
542 // save compressed (default file format)
545 case QMessageBox::No:
549 case QMessageBox::Cancel:
556 // First backup existing file, we
557 // don't want to add to old zip archives
561 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
563 QString backupFileName(destPath + "~");
564 QFile backupFile(backupFileName);
565 if (backupFile.exists() && !backupFile.remove())
567 QMessageBox::warning(0, tr("Save Error"),
568 tr("%1\ncould not be removed before saving").arg(backupFileName));
570 else if (!f.rename(backupFileName))
572 QMessageBox::warning(0, tr("Save Error"),
573 tr("%1\ncould not be renamed before saving").arg(destPath));
580 // Create temporary directory for packing
582 tmpZipDir=makeTmpDir (ok,"vym-zip");
585 QMessageBox::critical( 0, tr( "Critical Load Error" ),
586 tr("Couldn't create temporary directory before save\n"));
590 safeFilePath=filePath;
591 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
594 // Create mapName and fileDir
595 makeSubDirs (fileDir);
598 if (savemode==CompleteMap || selModel->selection().isEmpty())
601 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
604 autosaveTimer->stop();
609 if (selectionType()==TreeItem::Image)
612 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
613 // TODO take care of multiselections
616 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
619 qWarning ("ME::saveStringToDisk failed!");
625 if (err==success) err=zipDir (tmpZipDir,destPath);
628 removeDir (QDir(tmpZipDir));
630 // Restore original filepath outside of tmp zip dir
631 setFilePath (safeFilePath);
635 fileChangedTime=QFileInfo (destPath).lastModified();
639 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
641 QString pathDir=path.left(path.findRev("/"));
647 // We need to parse saved XML data
648 parseVYMHandler handler;
649 QXmlInputSource source( file);
650 QXmlSimpleReader reader;
651 reader.setContentHandler( &handler );
652 reader.setErrorHandler( &handler );
653 handler.setModel ( this);
654 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
655 if (undoSel.isEmpty())
659 handler.setLoadMode (NewMap);
663 handler.setLoadMode (ImportReplace);
665 blockReposition=true;
666 bool ok = reader.parse( source );
667 blockReposition=false;
670 // This should never ever happen
671 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
672 handler.errorProtocol());
675 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
678 bool VymModel::addMapInsertInt (const QString &path)
680 QString pathDir=path.left(path.findRev("/"));
686 // We need to parse saved XML data
687 parseVYMHandler handler;
688 QXmlInputSource source( file);
689 QXmlSimpleReader reader;
690 reader.setContentHandler( &handler );
691 reader.setErrorHandler( &handler );
692 handler.setModel (this);
693 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
694 handler.setLoadMode (ImportAdd);
695 blockReposition=true;
696 bool ok = reader.parse( source );
697 blockReposition=false;
698 if ( ok ) return true;
700 // This should never ever happen
701 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
702 handler.errorProtocol());
705 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
709 bool VymModel::addMapInsertInt (const QString &path, int pos)
711 BranchItem *selbi=getSelectedBranch();
714 if (addMapInsertInt (path))
716 if (selbi->depth()>0)
717 relinkBranch (selbi->getLastBranch(), selbi,pos);
721 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
725 qWarning ("ME::addMapInsertInt nothing selected");
729 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
731 ImageItem *ii=createImage(dst);
741 void VymModel::loadFloatImage ()
743 BranchItem *selbi=getSelectedBranch();
747 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
748 fd->setMode (Q3FileDialog::ExistingFiles);
749 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
750 ImagePreview *p =new ImagePreview (fd);
751 fd->setContentsPreviewEnabled( TRUE );
752 fd->setContentsPreview( p, p );
753 fd->setPreviewMode( Q3FileDialog::Contents );
754 fd->setCaption(vymName+" - " +tr("Load image"));
755 fd->setDir (lastImageDir);
758 if ( fd->exec() == QDialog::Accepted )
760 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
761 lastImageDir=QDir (fd->dirPath());
764 for (int j=0; j<fd->selectedFiles().count(); j++)
766 s=fd->selectedFiles().at(j);
767 ii=loadFloatImageInt (selbi,s);
768 //FIXME-3 check savestate for loadImage
774 QString ("loadImage (%1)").arg(s ),
775 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
778 // TODO loadFIO error handling
779 qWarning ("Failed to load "+s);
787 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
792 void VymModel::saveFloatImage ()
794 ImageItem *ii=getSelectedImage();
797 QFileDialog *fd=new QFileDialog( NULL);
798 fd->setFilters (imageIO.getFilters());
799 fd->setCaption(vymName+" - " +tr("Save image"));
800 fd->setFileMode( QFileDialog::AnyFile );
801 fd->setDirectory (lastImageDir);
802 // fd->setSelection (fio->getOriginalFilename());
806 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
808 fn=fd->selectedFiles().at(0);
809 if (QFile (fn).exists() )
811 QMessageBox mb( vymName,
812 tr("The file %1 exists already.\n"
813 "Do you want to overwrite it?").arg(fn),
814 QMessageBox::Warning,
815 QMessageBox::Yes | QMessageBox::Default,
816 QMessageBox::Cancel | QMessageBox::Escape,
817 QMessageBox::NoButton );
819 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
820 mb.setButtonText( QMessageBox::No, tr("Cancel"));
823 case QMessageBox::Yes:
826 case QMessageBox::Cancel:
833 saveFloatImageInt (ii,fd->selectedFilter(),fn );
840 void VymModel::importDirInt(BranchItem *dst, QDir d)
842 BranchItem *selbi=getSelectedBranch();
846 // Traverse directories
847 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
848 QFileInfoList list = d.entryInfoList();
851 for (int i = 0; i < list.size(); ++i)
854 if (fi.fileName() != "." && fi.fileName() != ".." )
856 bi=addNewBranchInt(dst,-2);
857 bi->setHeading (fi.fileName() ); // FIXME-3 check this
858 bi->setHeadingColor (QColor("blue"));
860 if ( !d.cd(fi.fileName()) )
861 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
864 // Recursively add subdirs
871 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
872 list = d.entryInfoList();
874 for (int i = 0; i < list.size(); ++i)
877 bi=addNewBranchInt (dst,-2);
878 bi->setHeading (fi.fileName() );
879 bi->setHeadingColor (QColor("black"));
880 if (fi.fileName().right(4) == ".vym" )
881 bi->setVymLink (fi.filePath());
886 void VymModel::importDirInt (const QString &s)
888 BranchItem *selbi=getSelectedBranch();
891 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
894 importDirInt (selbi,d);
898 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
900 BranchItem *selbi=getSelectedBranch();
904 filters <<"VYM map (*.vym)";
905 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
906 fd->setMode (QFileDialog::DirectoryOnly);
907 fd->setFilters (filters);
908 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
912 if ( fd->exec() == QDialog::Accepted )
914 importDirInt (fd->selectedFile() );
916 //FIXME-3 VM needed? scene()->update();
922 void VymModel::autosave()
927 cout << "VymModel::autosave rejected due to missing filePath\n";
930 QDateTime now=QDateTime().currentDateTime();
932 // Disable autosave, while we have gone back in history
933 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
934 if (redosAvail>0) return;
936 // Also disable autosave for new map without filename
937 if (filePath.isEmpty()) return;
940 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
942 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
943 mainWindow->fileSave (this);
946 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
951 void VymModel::fileChanged()
953 // Check if file on disk has changed meanwhile
954 if (!filePath.isEmpty())
956 QDateTime tmod=QFileInfo (filePath).lastModified();
957 if (tmod>fileChangedTime)
959 // FIXME-3 VM switch to current mapeditor and finish lineedits...
960 QMessageBox mb( vymName,
961 tr("The file of the map on disk has changed:\n\n"
962 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
963 QMessageBox::Question,
965 QMessageBox::Cancel | QMessageBox::Default,
966 QMessageBox::NoButton );
968 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
969 mb.setButtonText( QMessageBox::No, tr("Ignore"));
972 case QMessageBox::Yes:
974 load (filePath,NewMap,fileType);
975 case QMessageBox::Cancel:
976 fileChangedTime=tmod; // allow autosave to overwrite newer file!
982 bool VymModel::isDefault()
987 void VymModel::makeDefault()
993 bool VymModel::hasChanged()
998 void VymModel::setChanged()
1001 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1005 latestAddedItem=NULL;
1009 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1011 if (!lmo || !lmo->getTreeItem() ) return QString();
1012 return getObjectName (lmo->getTreeItem() );
1016 QString VymModel::getObjectName (TreeItem *ti)
1019 if (!ti) return QString("Error: NULL has no name!");
1021 if (s=="") s="unnamed";
1023 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1026 void VymModel::redo()
1028 // Can we undo at all?
1029 if (redosAvail<1) return;
1031 bool blockSaveStateOrg=blockSaveState;
1032 blockSaveState=true;
1036 if (undosAvail<stepsTotal) undosAvail++;
1038 if (curStep>stepsTotal) curStep=1;
1039 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1040 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1041 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1042 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1043 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1044 QString version=undoSet.readEntry ("/history/version");
1046 /* TODO Maybe check for version, if we save the history
1047 if (!checkVersion(version))
1048 QMessageBox::warning(0,tr("Warning"),
1049 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1052 // Find out current undo directory
1053 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1057 cout << "VymModel::redo() begin\n";
1058 cout << " undosAvail="<<undosAvail<<endl;
1059 cout << " redosAvail="<<redosAvail<<endl;
1060 cout << " curStep="<<curStep<<endl;
1061 cout << " ---------------------------"<<endl;
1062 cout << " comment="<<comment.toStdString()<<endl;
1063 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1064 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1065 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1066 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1067 cout << " ---------------------------"<<endl<<endl;
1070 // select object before redo
1071 if (!redoSelection.isEmpty())
1072 select (redoSelection);
1077 parseAtom (redoCommand,noErr,errMsg);
1079 blockSaveState=blockSaveStateOrg;
1081 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1082 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1083 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1084 undoSet.writeSettings(histPath);
1086 mainWindow->updateHistory (undoSet);
1089 /* TODO remove testing
1090 cout << "ME::redo() end\n";
1091 cout << " undosAvail="<<undosAvail<<endl;
1092 cout << " redosAvail="<<redosAvail<<endl;
1093 cout << " curStep="<<curStep<<endl;
1094 cout << " ---------------------------"<<endl<<endl;
1100 bool VymModel::isRedoAvailable()
1102 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1108 void VymModel::undo()
1110 // Can we undo at all?
1111 if (undosAvail<1) return;
1113 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1115 bool blockSaveStateOrg=blockSaveState;
1116 blockSaveState=true;
1118 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1119 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1120 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1121 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1122 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1123 QString version=undoSet.readEntry ("/history/version");
1125 /* TODO Maybe check for version, if we save the history
1126 if (!checkVersion(version))
1127 QMessageBox::warning(0,tr("Warning"),
1128 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1131 // Find out current undo directory
1132 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1134 // select object before undo
1135 if (!select (undoSelection))
1137 qWarning ("VymModel::undo() Could not select object for undo");
1144 cout << "VymModel::undo() begin\n";
1145 cout << " undosAvail="<<undosAvail<<endl;
1146 cout << " redosAvail="<<redosAvail<<endl;
1147 cout << " curStep="<<curStep<<endl;
1148 cout << " ---------------------------"<<endl;
1149 cout << " comment="<<comment.toStdString()<<endl;
1150 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1151 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1152 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1153 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1154 cout << " ---------------------------"<<endl<<endl;
1159 parseAtom (undoCommand,noErr,errMsg);
1163 if (curStep<1) curStep=stepsTotal;
1167 blockSaveState=blockSaveStateOrg;
1169 cout << "VymModel::undo() end\n";
1170 cout << " undosAvail="<<undosAvail<<endl;
1171 cout << " redosAvail="<<redosAvail<<endl;
1172 cout << " curStep="<<curStep<<endl;
1173 cout << " ---------------------------"<<endl<<endl;
1176 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1177 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1178 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1179 undoSet.writeSettings(histPath);
1181 mainWindow->updateHistory (undoSet);
1183 //emitSelectionChanged();
1186 bool VymModel::isUndoAvailable()
1188 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1194 void VymModel::gotoHistoryStep (int i)
1196 // Restore variables
1197 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1198 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1200 if (i<0) i=undosAvail+redosAvail;
1202 // Clicking above current step makes us undo things
1205 for (int j=0; j<undosAvail-i; j++) undo();
1208 // Clicking below current step makes us redo things
1210 for (int j=undosAvail; j<i; j++)
1212 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1216 // And ignore clicking the current row ;-)
1220 QString VymModel::getHistoryPath()
1222 QString histName(QString("history-%1").arg(curStep));
1223 return (tmpMapDir+"/"+histName);
1226 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1228 sendData(redoCom); //FIXME-3 testing
1233 if (blockSaveState) return;
1235 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1237 // Find out current undo directory
1238 if (undosAvail<stepsTotal) undosAvail++;
1240 if (curStep>stepsTotal) curStep=1;
1242 QString backupXML="";
1243 QString histDir=getHistoryPath();
1244 QString bakMapPath=histDir+"/map.xml";
1246 // Create histDir if not available
1249 makeSubDirs (histDir);
1251 // Save depending on how much needs to be saved
1253 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1255 QString undoCommand="";
1256 if (savemode==UndoCommand)
1258 undoCommand=undoCom;
1260 else if (savemode==PartOfMap )
1262 undoCommand=undoCom;
1263 undoCommand.replace ("PATH",bakMapPath);
1267 if (!backupXML.isEmpty())
1268 // Write XML Data to disk
1269 saveStringToDisk (bakMapPath,backupXML);
1271 // We would have to save all actions in a tree, to keep track of
1272 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1275 // Write the current state to disk
1276 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1277 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1278 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1279 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1280 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1281 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1282 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1283 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1284 undoSet.setEntry (QString("/history/version"),vymVersion);
1285 undoSet.writeSettings(histPath);
1289 // TODO remove after testing
1290 //cout << " into="<< histPath.toStdString()<<endl;
1291 cout << " stepsTotal="<<stepsTotal<<
1292 ", undosAvail="<<undosAvail<<
1293 ", redosAvail="<<redosAvail<<
1294 ", curStep="<<curStep<<endl;
1295 cout << " ---------------------------"<<endl;
1296 cout << " comment="<<comment.toStdString()<<endl;
1297 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1298 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1299 cout << " redoCom="<<redoCom.toStdString()<<endl;
1300 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1301 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1302 cout << " ---------------------------"<<endl;
1305 mainWindow->updateHistory (undoSet);
1311 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1313 // save the selected part of the map, Undo will replace part of map
1314 QString undoSelection="";
1316 undoSelection=getSelectString(undoSel);
1318 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1319 QString redoSelection="";
1321 redoSelection=getSelectString(undoSel);
1323 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1326 saveState (PartOfMap,
1327 undoSelection, "addMapReplace (\"PATH\")",
1333 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1337 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1340 QString undoSelection;
1341 QString redoSelection=getSelectString(redoSel);
1342 if (redoSel->getType()==TreeItem::Branch)
1344 undoSelection=getSelectString (redoSel->parent());
1345 // save the selected branch of the map, Undo will insert part of map
1346 saveState (PartOfMap,
1347 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1348 redoSelection, "delete ()",
1352 if (redoSel->getType()==TreeItem::MapCenter)
1354 // save the selected branch of the map, Undo will insert part of map
1355 saveState (PartOfMap,
1356 undoSelection, QString("addMapInsert (\"PATH\")"),
1357 redoSelection, "delete ()",
1364 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1366 // "Normal" savestate: save commands, selections and comment
1367 // so just save commands for undo and redo
1368 // and use current selection
1370 QString redoSelection="";
1371 if (redoSel) redoSelection=getSelectString(redoSel);
1372 QString undoSelection="";
1373 if (undoSel) undoSelection=getSelectString(undoSel);
1375 saveState (UndoCommand,
1382 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1384 // "Normal" savestate: save commands, selections and comment
1385 // so just save commands for undo and redo
1386 // and use current selection
1387 saveState (UndoCommand,
1394 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1396 // "Normal" savestate applied to model (no selection needed):
1397 // save commands and comment
1398 saveState (UndoCommand,
1406 QGraphicsScene* VymModel::getScene ()
1411 TreeItem* VymModel::findBySelectString(QString s)
1413 if (s.isEmpty() ) return NULL;
1415 // Old maps don't have multiple mapcenters and don't save full path
1416 if (s.left(2) !="mc")
1419 QStringList parts=s.split (",");
1422 TreeItem *ti=rootItem;
1424 while (!parts.isEmpty() )
1426 typ=parts.first().left(2);
1427 n=parts.first().right(parts.first().length() - 3).toInt();
1428 parts.removeFirst();
1429 if (typ=="mc" || typ=="bo")
1430 ti=ti->getBranchNum (n);
1432 ti=ti->getImageNum (n);
1434 ti=ti->getAttributeNum (n);
1436 ti=ti->getXLinkNum (n);
1437 if(!ti) return NULL;
1442 TreeItem* VymModel::findID (const uint &i) //FIXME-3 Search also other types...
1444 BranchItem *cur=NULL;
1445 BranchItem *prev=NULL;
1446 nextBranch(cur,prev);
1449 if (i==cur->getID() ) return cur;
1450 nextBranch(cur,prev);
1455 //////////////////////////////////////////////
1457 //////////////////////////////////////////////
1458 void VymModel::setVersion (const QString &s)
1463 QString VymModel::getVersion()
1468 void VymModel::setAuthor (const QString &s)
1471 QString ("setMapAuthor (\"%1\")").arg(author),
1472 QString ("setMapAuthor (\"%1\")").arg(s),
1473 QString ("Set author of map to \"%1\"").arg(s)
1478 QString VymModel::getAuthor()
1483 void VymModel::setComment (const QString &s)
1486 QString ("setMapComment (\"%1\")").arg(comment),
1487 QString ("setMapComment (\"%1\")").arg(s),
1488 QString ("Set comment of map")
1493 QString VymModel::getComment ()
1498 QString VymModel::getDate ()
1500 return QDate::currentDate().toString ("yyyy-MM-dd");
1503 int VymModel::branchCount()
1506 BranchItem *cur=NULL;
1507 BranchItem *prev=NULL;
1508 nextBranch(cur,prev);
1512 nextBranch(cur,prev);
1517 void VymModel::setSortFilter (const QString &s)
1520 emit (sortFilterChanged (sortFilter));
1523 QString VymModel::getSortFilter ()
1528 void VymModel::setHeading(const QString &s)
1530 BranchItem *selbi=getSelectedBranch();
1535 "setHeading (\""+selbi->getHeading()+"\")",
1537 "setHeading (\""+s+"\")",
1538 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1539 selbi->setHeading(s );
1540 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1542 emitSelectionChanged();
1546 QString VymModel::getHeading()
1548 TreeItem *selti=getSelectedItem();
1550 return selti->getHeading();
1555 void VymModel::setNote(const QString &s)
1557 TreeItem *selti=getSelectedItem();
1562 "setNote (\""+selti->getNote()+"\")",
1564 "setNote (\""+s+"\")",
1565 QString("Set note of %1 ").arg(getObjectName(selti)) );
1568 emitNoteHasChanged(selti);
1569 emitDataHasChanged(selti);
1572 QString VymModel::getNote()
1574 TreeItem *selti=getSelectedItem();
1576 return selti->getNote();
1581 void VymModel::loadNote (const QString &fn)
1583 BranchItem *selbi=getSelectedBranch();
1587 if (!loadStringFromDisk (fn,n))
1588 qWarning ()<<"VymModel::loadNote Couldn't load "<<fn;
1592 qWarning ("VymModel::loadNote no branch selected");
1595 void VymModel::saveNote (const QString &fn)
1597 BranchItem *selbi=getSelectedBranch();
1600 QString n=selbi->getNote();
1602 qWarning ()<<"VymModel::saveNote note is empty, won't save to "<<fn;
1605 if (!saveStringToDisk (fn,n))
1606 qWarning ()<<"VymModel::saveNote Couldn't save "<<fn;
1611 qWarning ("VymModel::saveNote no branch selected");
1614 void VymModel::findDuplicateURLs() // FIXME-3 needs GUI
1616 // Generate map containing _all_ URLs and branches
1618 QMap <QString,BranchItem*> map;
1619 BranchItem *cur=NULL;
1620 BranchItem *prev=NULL;
1621 nextBranch(cur,prev);
1626 map.insertMulti (u,cur);
1627 nextBranch(cur,prev);
1630 // Extract duplicate URLs
1631 QMap <QString, BranchItem*>::const_iterator i=map.constBegin();
1632 QMap <QString, BranchItem*>::const_iterator firstdup=map.constEnd(); //invalid
1633 while (i != map.constEnd())
1635 if (i!=map.constBegin() && i.key()==firstdup.key())
1637 if ( i-1==firstdup )
1639 cout << firstdup.key().toStdString() << endl;
1640 cout << " - "<< firstdup.value() <<" - "<<firstdup.value()->getHeadingStd()<<endl;
1642 cout << " - "<< i.value() <<" - "<<i.value()->getHeadingStd()<<endl;
1650 void VymModel::findAll (FindResultModel *rmodel, QString s, Qt::CaseSensitivity cs)
1653 BranchItem *cur=NULL;
1654 BranchItem *prev=NULL;
1655 nextBranch(cur,prev);
1658 if (cur->getHeading().contains (s,cs))
1660 rmodel->addItem (cur);
1665 i=cur->getNote().indexOf (s,i,cs); //FIXME-2 add subitems to rmodel
1668 rmodel->addSubItem (cur,"Note",cur,i);
1672 nextBranch(cur,prev);
1676 BranchItem* VymModel::findText (QString s,Qt::CaseSensitivity cs,QTextCursor &cursor)
1678 if (!s.isEmpty() && s!=findString)
1684 QTextDocument::FindFlags flags=0;
1685 if (cs==Qt::CaseSensitive) flags=QTextDocument::FindCaseSensitively;
1688 { // Nothing found or new find process
1690 // nothing found, start again
1694 nextBranch (findCurrent,findPrevious);
1696 bool searching=true;
1697 bool foundNote=false;
1698 while (searching && !EOFind)
1702 // Searching in Note
1703 if (findCurrent->getNote().contains(findString,cs))
1705 select (findCurrent);
1706 if (textEditor->findText(findString,flags,cursor))
1712 // Searching in Heading
1713 if (searching && findCurrent->getHeading().contains (findString,cs) )
1715 select(findCurrent);
1721 if (!nextBranch(findCurrent,findPrevious) )
1726 return getSelectedBranch();
1731 void VymModel::findReset()
1732 { // Necessary if text to find changes during a find process
1739 void VymModel::setScene (QGraphicsScene *s)
1744 void VymModel::setURL(const QString &url)
1746 TreeItem *selti=getSelectedItem();
1749 QString oldurl=selti->getURL();
1750 selti->setURL (url);
1753 QString ("setURL (\"%1\")").arg(oldurl),
1755 QString ("setURL (\"%1\")").arg(url),
1756 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1759 emitDataHasChanged (selti);
1760 emitShowSelection();
1764 QString VymModel::getURL()
1766 TreeItem *selti=getSelectedItem();
1768 return selti->getURL();
1773 QStringList VymModel::getURLs(bool ignoreScrolled)
1776 BranchItem *selbi=getSelectedBranch();
1777 BranchItem *cur=selbi;
1778 BranchItem *prev=NULL;
1781 if (!cur->getURL().isEmpty() && !(ignoreScrolled && cur->hasScrolledParent(cur) ))
1782 urls.append( cur->getURL());
1783 cur=nextBranch (cur,prev,true,selbi);
1789 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1791 BranchItem *bi=getSelectedBranch();
1794 BranchObj *bo=(BranchObj*)(bi->getLMO());
1797 QString s=bo->getFrameTypeName();
1798 bo->setFrameType (t);
1799 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1800 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1802 bo->updateLinkGeometry();
1807 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1809 BranchItem *bi=getSelectedBranch();
1812 BranchObj *bo=(BranchObj*)(bi->getLMO());
1815 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1816 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1817 bo->setFrameType (s);
1819 bo->updateLinkGeometry();
1824 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1827 BranchItem *bi=getSelectedBranch();
1830 BranchObj *bo=(BranchObj*)(bi->getLMO());
1833 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1834 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1835 bo->setFramePenColor (c);
1840 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1842 BranchItem *bi=getSelectedBranch();
1845 BranchObj *bo=(BranchObj*)(bi->getLMO());
1848 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1849 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1850 bo->setFrameBrushColor (c);
1855 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1857 BranchItem *bi=getSelectedBranch();
1860 BranchObj *bo=(BranchObj*)(bi->getLMO());
1863 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1864 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1865 bo->setFramePadding (i);
1867 bo->updateLinkGeometry();
1872 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1874 BranchItem *bi=getSelectedBranch();
1877 BranchObj *bo=(BranchObj*)(bi->getLMO());
1880 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1881 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1882 bo->setFrameBorderWidth (i);
1884 bo->updateLinkGeometry();
1889 void VymModel::setIncludeImagesVer(bool b)
1891 BranchItem *bi=getSelectedBranch();
1894 QString u= b ? "false" : "true";
1895 QString r=!b ? "false" : "true";
1899 QString("setIncludeImagesVertically (%1)").arg(u),
1901 QString("setIncludeImagesVertically (%1)").arg(r),
1902 QString("Include images vertically in %1").arg(getObjectName(bi))
1904 bi->setIncludeImagesVer(b);
1905 emitDataHasChanged ( bi);
1910 void VymModel::setIncludeImagesHor(bool b)
1912 BranchItem *bi=getSelectedBranch();
1915 QString u= b ? "false" : "true";
1916 QString r=!b ? "false" : "true";
1920 QString("setIncludeImagesHorizontally (%1)").arg(u),
1922 QString("setIncludeImagesHorizontally (%1)").arg(r),
1923 QString("Include images horizontally in %1").arg(getObjectName(bi))
1925 bi->setIncludeImagesHor(b);
1926 emitDataHasChanged ( bi);
1931 void VymModel::setHideLinkUnselected (bool b)
1933 TreeItem *ti=getSelectedItem();
1934 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1936 QString u= b ? "false" : "true";
1937 QString r=!b ? "false" : "true";
1941 QString("setHideLinkUnselected (%1)").arg(u),
1943 QString("setHideLinkUnselected (%1)").arg(r),
1944 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1946 ((MapItem*)ti)->setHideLinkUnselected(b);
1950 void VymModel::setHideExport(bool b)
1952 TreeItem *ti=getSelectedItem();
1954 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1956 ti->setHideInExport (b);
1957 QString u= b ? "false" : "true";
1958 QString r=!b ? "false" : "true";
1962 QString ("setHideExport (%1)").arg(u),
1964 QString ("setHideExport (%1)").arg(r),
1965 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1967 emitDataHasChanged(ti);
1968 emitSelectionChanged();
1971 // emitSelectionChanged();
1972 // FIXME-3 VM needed? scene()->update();
1976 void VymModel::toggleHideExport()
1978 TreeItem *selti=getSelectedItem();
1980 setHideExport ( !selti->hideInExport() );
1983 void VymModel::addTimestamp() //FIXME-3 new function, localize
1985 BranchItem *selbi=addNewBranch();
1988 QDate today=QDate::currentDate();
1990 selbi->setHeading (QString ("%1-%2-%3")
1991 .arg(today.year(),4,10,c)
1992 .arg(today.month(),2,10,c)
1993 .arg(today.day(),2,10,c));
1994 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
2001 void VymModel::copy()
2003 TreeItem *selti=getSelectedItem();
2005 (selti->getType() == TreeItem::Branch ||
2006 selti->getType() == TreeItem::MapCenter ||
2007 selti->getType() == TreeItem::Image ))
2009 if (redosAvail == 0)
2012 QString s=getSelectString(selti);
2013 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
2014 curClipboard=curStep;
2017 // Copy also to global clipboard, because we are at last step in history
2018 QString bakMapName(QString("history-%1").arg(curStep));
2019 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2020 copyDir (bakMapDir,clipboardDir );
2022 clipboardEmpty=false;
2028 void VymModel::pasteNoSave(const int &n)
2030 bool old=blockSaveState;
2031 blockSaveState=true;
2032 bool zippedOrg=zipped;
2033 if (redosAvail > 0 || n!=0)
2035 // Use the "historical" buffer
2036 QString bakMapName(QString("history-%1").arg(n));
2037 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2038 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2040 // Use the global buffer
2041 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2046 void VymModel::paste()
2048 BranchItem *selbi=getSelectedBranch();
2051 saveStateChangingPart(
2054 QString ("paste (%1)").arg(curClipboard),
2055 QString("Paste to %1").arg( getObjectName(selbi))
2062 void VymModel::cut()
2064 TreeItem *selti=getSelectedItem();
2065 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
2073 bool VymModel::moveUp(BranchItem *bi)
2075 if (bi && bi->canMoveUp())
2076 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
2081 void VymModel::moveUp()
2083 BranchItem *selbi=getSelectedBranch();
2086 QString oldsel=getSelectString();
2089 getSelectString(),"moveDown ()",
2091 QString("Move up %1").arg(getObjectName(selbi)));
2095 bool VymModel::moveDown(BranchItem *bi)
2097 if (bi && bi->canMoveDown())
2098 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2103 void VymModel::moveDown()
2105 BranchItem *selbi=getSelectedBranch();
2108 QString oldsel=getSelectString();
2109 if ( moveDown(selbi))
2111 getSelectString(),"moveUp ()",
2112 oldsel,"moveDown ()",
2113 QString("Move down %1").arg(getObjectName(selbi)));
2117 void VymModel::detach()
2119 BranchItem *selbi=getSelectedBranch();
2120 if (selbi && selbi->depth()>0)
2122 // if no relPos have been set before, try to use current rel positions
2123 if (selbi->getLMO())
2124 for (int i=0; i<selbi->branchCount();++i)
2125 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2127 QString oldsel=getSelectString();
2130 BranchObj *bo=selbi->getBranchObj();
2131 if (bo) p=bo->getAbsPos();
2132 QString parsel=getSelectString(selbi->parent());
2133 if ( relinkBranch (selbi,rootItem,-1) )
2135 getSelectString (selbi),
2136 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2139 QString("Detach %1").arg(getObjectName(selbi))
2144 void VymModel::sortChildren(bool inverse)
2146 BranchItem* selbi=getSelectedBranch();
2149 if(selbi->branchCount()>1)
2153 saveStateChangingPart(
2154 selbi,selbi, "sortChildren ()",
2155 QString("Sort children of %1").arg(getObjectName(selbi)));
2157 selbi->sortChildren(inverse);
2159 emitShowSelection();
2164 BranchItem* VymModel::createMapCenter()
2166 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2170 BranchItem* VymModel::createBranch(BranchItem *dst)
2173 return addNewBranchInt (dst,-2);
2178 ImageItem* VymModel::createImage(BranchItem *dst)
2185 QList<QVariant> cData;
2186 cData << "new" << "undef";
2188 ImageItem *newii=new ImageItem(cData) ;
2189 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2191 emit (layoutAboutToBeChanged() );
2194 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2195 n=dst->getRowNumAppend(newii);
2196 beginInsertRows (parix,n,n);
2197 dst->appendChild (newii);
2200 emit (layoutChanged() );
2202 // save scroll state. If scrolled, automatically select
2203 // new branch in order to tmp unscroll parent...
2204 newii->createMapObj(mapScene);
2211 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2218 QList<QVariant> cData;
2219 cData << "new xLink"<<"undef";
2221 XLinkItem *newxli=new XLinkItem(cData) ;
2222 newxli->setBegin (bi);
2224 emit (layoutAboutToBeChanged() );
2227 n=bi->getRowNumAppend(newxli);
2228 beginInsertRows (parix,n,n);
2229 bi->appendChild (newxli);
2232 emit (layoutChanged() );
2234 // save scroll state. If scrolled, automatically select
2235 // new branch in order to tmp unscroll parent...
2238 newxli->createMapObj(mapScene);
2246 AttributeItem* VymModel::addAttribute()
2248 BranchItem *selbi=getSelectedBranch();
2251 QList<QVariant> cData;
2252 cData << "new attribute" << "undef";
2253 AttributeItem *a=new AttributeItem (cData);
2254 if (addAttribute (a)) return a;
2259 AttributeItem* VymModel::addAttribute(AttributeItem *ai) // FIXME-2 savestate missing
2261 BranchItem *selbi=getSelectedBranch();
2264 emit (layoutAboutToBeChanged() );
2266 QModelIndex parix=index(selbi);
2267 int n=selbi->getRowNumAppend (ai);
2268 beginInsertRows (parix,n,n);
2269 selbi->appendChild (ai);
2272 emit (layoutChanged() );
2274 ai->createMapObj(mapScene); //FIXME-2 check that...
2281 BranchItem* VymModel::addMapCenter ()
2283 BranchItem *bi=addMapCenter (contextPos);
2285 emitShowSelection();
2290 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2291 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2297 BranchItem* VymModel::addMapCenter(QPointF absPos)
2298 // createMapCenter could then probably be merged with createBranch
2302 QModelIndex parix=index(rootItem);
2304 QList<QVariant> cData;
2305 cData << "VM:addMapCenter" << "undef";
2306 BranchItem *newbi=new BranchItem (cData,rootItem);
2307 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2308 int n=rootItem->getRowNumAppend (newbi);
2310 emit (layoutAboutToBeChanged() );
2311 beginInsertRows (parix,n,n);
2313 rootItem->appendChild (newbi);
2316 emit (layoutChanged() );
2319 newbi->setPositionMode (MapItem::Absolute);
2320 BranchObj *bo=newbi->createMapObj(mapScene);
2321 if (bo) bo->move (absPos);
2326 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2328 // Depending on pos:
2329 // -3 insert in children of parent above selection
2330 // -2 add branch to selection
2331 // -1 insert in children of parent below selection
2332 // 0..n insert in children of parent at pos
2335 QList<QVariant> cData;
2336 cData << "" << "undef";
2341 BranchItem *newbi=new BranchItem (cData);
2342 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2344 emit (layoutAboutToBeChanged() );
2350 n=parbi->getRowNumAppend (newbi);
2351 beginInsertRows (parix,n,n);
2352 parbi->appendChild (newbi);
2354 }else if (num==-1 || num==-3)
2356 // insert below selection
2357 parbi=(BranchItem*)dst->parent();
2360 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2361 beginInsertRows (parix,n,n);
2362 parbi->insertBranch(n,newbi);
2365 emit (layoutChanged() );
2367 // Set color of heading to that of parent
2368 newbi->setHeadingColor (parbi->getHeadingColor());
2370 // save scroll state. If scrolled, automatically select
2371 // new branch in order to tmp unscroll parent...
2372 newbi->createMapObj(mapScene);
2377 BranchItem* VymModel::addNewBranch(int pos)
2379 // Different meaning than num in addNewBranchInt!
2383 BranchItem *newbi=NULL;
2384 BranchItem *selbi=getSelectedBranch();
2388 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2390 newbi=addNewBranchInt (selbi,pos-2);
2398 QString ("addBranch (%1)").arg(pos),
2399 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2402 // emitSelectionChanged(); FIXME-3
2403 latestAddedItem=newbi;
2404 // In Network mode, the client needs to know where the new branch is,
2405 // so we have to pass on this information via saveState.
2406 // TODO: Get rid of this positioning workaround
2407 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2408 sendData ("selectLatestAdded ()");
2409 sendData (QString("move %1").arg(ps));
2418 BranchItem* VymModel::addNewBranchBefore()
2420 BranchItem *newbi=NULL;
2421 BranchItem *selbi=getSelectedBranch();
2422 if (selbi && selbi->getType()==TreeItem::Branch)
2423 // We accept no MapCenter here, so we _have_ a parent
2425 //QPointF p=bo->getRelPos();
2428 // add below selection
2429 newbi=addNewBranchInt (selbi,-1);
2433 //newbi->move2RelPos (p);
2435 // Move selection to new branch
2436 relinkBranch (selbi,newbi,0);
2438 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2439 QString ("Add branch before %1").arg(getObjectName(selbi)));
2441 // FIXME-3 needed? reposition();
2442 // emitSelectionChanged(); FIXME-3
2448 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2454 // Do we need to update frame type?
2455 bool keepFrame=false;
2458 emit (layoutAboutToBeChanged() );
2459 BranchItem *branchpi=(BranchItem*)branch->parent();
2460 // Remove at current position
2461 int n=branch->childNum();
2463 /* FIXME-4 seg since 20091207, if ModelTest active. strange.
2464 // error occured if relinking branch to empty mainbranch
2465 cout<<"VM::relinkBranch:\n";
2466 cout<<" b="<<branch->getHeadingStd()<<endl;
2467 cout<<" dst="<<dst->getHeadingStd()<<endl;
2468 cout<<" pos="<<pos<<endl;
2469 cout<<" n1="<<n<<endl;
2471 beginRemoveRows (index(branchpi),n,n);
2472 branchpi->removeChild (n);
2475 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2477 // Append as last branch to dst
2478 if (dst->branchCount()==0)
2481 n=dst->getFirstBranch()->childNumber();
2482 beginInsertRows (index(dst),n+pos,n+pos);
2483 dst->insertBranch (pos,branch);
2486 // Correct type if necessesary
2487 if (branch->getType()==TreeItem::MapCenter)
2488 branch->setType(TreeItem::Branch);
2490 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2491 branch->updateStyles(keepFrame);
2493 emit (layoutChanged() );
2494 reposition(); // both for moveUp/Down and relinking
2495 if (dst->isScrolled() )
2498 branch->updateVisibility();
2507 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2511 emit (layoutAboutToBeChanged() );
2513 BranchItem *pi=(BranchItem*)(image->parent());
2514 QString oldParString=getSelectString (pi);
2515 // Remove at current position
2516 int n=image->childNum();
2517 beginRemoveRows (index(pi),n,n);
2518 pi->removeChild (n);
2522 QModelIndex dstix=index(dst);
2523 n=dst->getRowNumAppend (image);
2524 beginInsertRows (dstix,n,n+1);
2525 dst->appendChild (image);
2528 // Set new parent also for lmo
2529 if (image->getLMO() && dst->getLMO() )
2530 image->getLMO()->setParObj (dst->getLMO() );
2532 emit (layoutChanged() );
2535 QString("relinkTo (\"%1\")").arg(oldParString),
2537 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2538 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2544 void VymModel::deleteSelection() //FIXME-2 xLinks in a deleted subtree are not restored on undo
2545 //FIXME-1 delete MCO, UNDO, => crash (see 1.12.4 from 29.7.2009)
2547 BranchItem *selbi=getSelectedBranch();
2552 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2554 BranchItem *pi=(BranchItem*)(deleteItem (selbi));
2557 if (pi->isScrolled() && pi->branchCount()==0)
2560 emitDataHasChanged(pi);
2563 emitShowSelection();
2567 TreeItem *ti=getSelectedItem();
2569 { // Delete other item
2570 TreeItem *pi=ti->parent();
2572 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2574 saveStateChangingPart(
2578 QString("Delete %1").arg(getObjectName(ti))
2582 emitDataHasChanged (pi);
2585 emitShowSelection();
2586 } else if (ti->getType()==TreeItem::XLink)
2588 //FIXME-2 savestate for deleting xlink missing
2591 qWarning ("VymmModel::deleteSelection() unknown type?!");
2595 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2598 BranchItem *selbi=getSelectedBranch();
2602 // Don't use this on mapcenter
2603 if (selbi->depth()<2) return;
2605 pi=(BranchItem*)(selbi->parent());
2606 // Check if we have children at all to keep
2607 if (selbi->branchCount()==0)
2614 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2615 saveStateChangingPart(
2618 "deleteKeepChildren ()",
2619 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2622 QString sel=getSelectString(selbi);
2624 int pos=selbi->num();
2625 BranchItem *bi=selbi->getFirstBranch();
2628 relinkBranch (bi,pi,pos);
2629 bi=selbi->getFirstBranch();
2635 BranchObj *bo=getSelectedBranchObj();
2638 bo->move2RelPos (p);
2644 void VymModel::deleteChildren()
2647 BranchItem *selbi=getSelectedBranch();
2650 saveStateChangingPart(
2653 "deleteChildren ()",
2654 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2656 emit (layoutAboutToBeChanged() );
2658 QModelIndex ix=index (selbi);
2659 int n=selbi->branchCount()-1;
2660 beginRemoveRows (ix,0,n);
2661 removeRows (0,n+1,ix);
2663 if (selbi->isScrolled()) selbi->unScroll();
2664 emit (layoutChanged() );
2669 TreeItem* VymModel::deleteItem (TreeItem *ti)
2673 TreeItem *pi=ti->parent();
2674 QModelIndex parentIndex=index(pi);
2676 emit (layoutAboutToBeChanged() );
2678 int n=ti->childNum();
2679 beginRemoveRows (parentIndex,n,n);
2680 removeRows (n,1,parentIndex);
2684 emit (layoutChanged() );
2685 if (pi->depth()>=0) return pi;
2690 void VymModel::clearItem (TreeItem *ti)
2694 QModelIndex parentIndex=index(ti);
2695 if (!parentIndex.isValid()) return;
2697 int n=ti->childCount();
2700 emit (layoutAboutToBeChanged() );
2702 beginRemoveRows (parentIndex,0,n-1);
2703 removeRows (0,n,parentIndex);
2707 emit (layoutChanged() );
2713 bool VymModel::scrollBranch(BranchItem *bi)
2717 if (bi->isScrolled()) return false;
2718 if (bi->branchCount()==0) return false;
2719 if (bi->depth()==0) return false;
2720 if (bi->toggleScroll())
2728 QString ("%1 ()").arg(u),
2730 QString ("%1 ()").arg(r),
2731 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2733 emitDataHasChanged(bi);
2734 emitSelectionChanged();
2735 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2742 bool VymModel::unscrollBranch(BranchItem *bi)
2746 if (!bi->isScrolled()) return false;
2747 if (bi->branchCount()==0) return false;
2748 if (bi->depth()==0) return false;
2749 if (bi->toggleScroll())
2757 QString ("%1 ()").arg(u),
2759 QString ("%1 ()").arg(r),
2760 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2762 emitDataHasChanged(bi);
2763 emitSelectionChanged();
2764 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2771 void VymModel::toggleScroll()
2773 BranchItem *bi=(BranchItem*)getSelectedBranch();
2774 if (bi && bi->isBranchLikeType() )
2776 if (bi->isScrolled())
2777 unscrollBranch (bi);
2781 // saveState & reposition are called in above functions
2784 void VymModel::unscrollChildren()
2786 BranchItem *selbi=getSelectedBranch();
2787 BranchItem *prev=NULL;
2788 BranchItem *cur=selbi;
2791 saveStateChangingPart(
2794 QString ("unscrollChildren ()"),
2795 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2799 if (cur->isScrolled())
2801 cur->toggleScroll();
2802 emitDataHasChanged (cur);
2804 cur=nextBranch (cur,prev,true,selbi);
2811 void VymModel::emitExpandAll()
2813 emit (expandAll() );
2816 void VymModel::emitExpandOneLevel()
2818 emit (expandOneLevel () );
2821 void VymModel::emitCollapseOneLevel()
2823 emit (collapseOneLevel () );
2826 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2828 BranchItem *bi=getSelectedBranch();
2832 if (bi->isActiveStandardFlag(name))
2844 QString("%1 (\"%2\")").arg(u).arg(name),
2846 QString("%1 (\"%2\")").arg(r).arg(name),
2847 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2848 bi->toggleStandardFlag (name, master);
2850 emitSelectionChanged();
2854 void VymModel::addFloatImage (const QPixmap &img)
2856 BranchItem *selbi=getSelectedBranch();
2859 ImageItem *ii=createImage (selbi);
2861 ii->setOriginalFilename("No original filename (image added by dropevent)");
2862 QString s=getSelectString(selbi);
2863 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2864 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2866 // FIXME-3 VM needed? scene()->update();
2871 void VymModel::colorBranch (QColor c)
2873 BranchItem *selbi=getSelectedBranch();
2878 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2880 QString ("colorBranch (\"%1\")").arg(c.name()),
2881 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2883 selbi->setHeadingColor(c); // color branch
2888 void VymModel::colorSubtree (QColor c)
2890 BranchItem *selbi=getSelectedBranch();
2893 saveStateChangingPart(
2896 QString ("colorSubtree (\"%1\")").arg(c.name()),
2897 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2899 BranchItem *prev=NULL;
2900 BranchItem *cur=selbi;
2903 cur->setHeadingColor(c); // color links, color children
2904 cur=nextBranch (cur,prev,true,selbi);
2910 QColor VymModel::getCurrentHeadingColor()
2912 BranchItem *selbi=getSelectedBranch();
2913 if (selbi) return selbi->getHeadingColor();
2915 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2921 void VymModel::editURL()
2923 TreeItem *selti=getSelectedItem();
2927 QString text = QInputDialog::getText(
2928 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2929 selti->getURL(), &ok, NULL);
2931 // user entered something and pressed OK
2936 void VymModel::editLocalURL()
2938 TreeItem *selti=getSelectedItem();
2941 QStringList filters;
2942 filters <<"All files (*)";
2943 filters << tr("Text","Filedialog") + " (*.txt)";
2944 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2945 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2946 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2947 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2948 fd->setFilters (filters);
2949 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2950 fd->setDirectory (lastFileDir);
2951 if (! selti->getVymLink().isEmpty() )
2952 fd->selectFile( selti->getURL() );
2955 if ( fd->exec() == QDialog::Accepted )
2957 lastFileDir=QDir (fd->directory().path());
2958 setURL (fd->selectedFile() );
2964 void VymModel::editHeading2URL()
2966 TreeItem *selti=getSelectedItem();
2968 setURL (selti->getHeading());
2971 void VymModel::editBugzilla2URL()
2973 TreeItem *selti=getSelectedItem();
2976 QString h=selti->getHeading();
2977 QRegExp rx("^(\\d+)");
2978 if (rx.indexIn(h) !=-1)
2979 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2983 void VymModel::getBugzillaData()
2985 BranchItem *selbi=getSelectedBranch();
2988 QString url=selbi->getURL();
2991 QRegExp rx("(\\d+)");
2992 if (rx.indexIn(url) !=-1)
2994 QString bugID=rx.cap(1);
2995 qDebug()<< "VM::getBugzillaData bug="<<bugID;
2997 new BugAgent (selbi,bugID);
3003 void VymModel::editFATE2URL()
3005 TreeItem *selti=getSelectedItem();
3008 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
3011 "setURL (\""+selti->getURL()+"\")",
3013 "setURL (\""+url+"\")",
3014 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
3016 selti->setURL (url);
3017 // FIXME-4 updateActions();
3021 void VymModel::editVymLink()
3023 BranchItem *bi=getSelectedBranch();
3026 QStringList filters;
3027 filters <<"VYM map (*.vym)";
3028 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
3029 fd->setFilters (filters);
3030 fd->setCaption(vymName+" - " +tr("Link to another map"));
3031 fd->setDirectory (lastFileDir);
3032 if (! bi->getVymLink().isEmpty() )
3033 fd->selectFile( bi->getVymLink() );
3037 if ( fd->exec() == QDialog::Accepted )
3039 lastFileDir=QDir (fd->directory().path());
3042 "setVymLink (\""+bi->getVymLink()+"\")",
3044 "setVymLink (\""+fd->selectedFile()+"\")",
3045 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
3047 setVymLink (fd->selectedFile() );
3052 void VymModel::setVymLink (const QString &s)
3054 // Internal function, no saveState needed
3055 TreeItem *selti=getSelectedItem();
3058 selti->setVymLink(s);
3060 emitDataHasChanged (selti);
3061 emitShowSelection();
3065 void VymModel::deleteVymLink()
3067 BranchItem *bi=getSelectedBranch();
3072 "setVymLink (\""+bi->getVymLink()+"\")",
3074 "setVymLink (\"\")",
3075 QString("Unset vymlink of %1").arg(getObjectName(bi))
3077 bi->setVymLink ("" );
3083 QString VymModel::getVymLink()
3085 BranchItem *bi=getSelectedBranch();
3087 return bi->getVymLink();
3093 QStringList VymModel::getVymLinks()
3096 BranchItem *selbi=getSelectedBranch();
3097 BranchItem *cur=selbi;
3098 BranchItem *prev=NULL;
3101 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
3102 cur=nextBranch (cur,prev,true,selbi);
3108 void VymModel::followXLink(int i)
3111 BranchItem *selbi=getSelectedBranch();
3114 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
3115 if (selbi) select (selbi);
3119 void VymModel::editXLink(int i)
3122 BranchItem *selbi=getSelectedBranch();
3125 XLinkItem *xli=selbi->getXLinkNum(i);
3128 EditXLinkDialog dia;
3130 dia.setSelection(selbi);
3131 if (dia.exec() == QDialog::Accepted)
3133 if (dia.useSettingsGlobal() )
3135 setMapDefXLinkColor (xli->getColor() );
3136 setMapDefXLinkWidth (xli->getWidth() );
3138 if (dia.deleteXLink()) deleteItem (xli);
3148 //////////////////////////////////////////////
3150 //////////////////////////////////////////////
3152 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3154 TreeItem* selti=getSelectedItem();
3155 BranchItem *selbi=getSelectedBranch();
3160 QVariant returnValue="";
3162 // Split string s into command and parameters
3163 parser.parseAtom (atom);
3164 QString com=parser.getCommand();
3166 // External commands
3167 /////////////////////////////////////////////////////////////////////
3168 if (com=="addBranch")
3172 parser.setError (Aborted,"Nothing selected");
3173 } else if (! selbi )
3175 parser.setError (Aborted,"Type of selection is not a branch");
3180 if (parser.checkParCount(pl))
3182 if (parser.parCount()==0)
3186 n=parser.parInt (ok,0);
3187 if (ok ) addNewBranch (n);
3191 /////////////////////////////////////////////////////////////////////
3192 } else if (com=="addBranchBefore")
3196 parser.setError (Aborted,"Nothing selected");
3197 } else if (! selbi )
3199 parser.setError (Aborted,"Type of selection is not a branch");
3202 if (parser.parCount()==0)
3204 addNewBranchBefore ();
3207 /////////////////////////////////////////////////////////////////////
3208 } else if (com==QString("addMapCenter"))
3210 if (parser.checkParCount(2))
3212 x=parser.parDouble (ok,0);
3215 y=parser.parDouble (ok,1);
3216 if (ok) addMapCenter (QPointF(x,y));
3219 /////////////////////////////////////////////////////////////////////
3220 } else if (com==QString("addMapReplace"))
3224 parser.setError (Aborted,"Nothing selected");
3225 } else if (! selbi )
3227 parser.setError (Aborted,"Type of selection is not a branch");
3228 } else if (parser.checkParCount(1))
3230 //s=parser.parString (ok,0); // selection
3231 t=parser.parString (ok,0); // path to map
3232 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3233 addMapReplaceInt(getSelectString(selbi),t);
3235 /////////////////////////////////////////////////////////////////////
3236 } else if (com==QString("addMapInsert"))
3238 if (parser.parCount()==2)
3243 parser.setError (Aborted,"Nothing selected");
3244 } else if (! selbi )
3246 parser.setError (Aborted,"Type of selection is not a branch");
3249 t=parser.parString (ok,0); // path to map
3250 n=parser.parInt(ok,1); // position
3251 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3252 addMapInsertInt(t,n);
3254 } else if (parser.parCount()==1)
3256 t=parser.parString (ok,0); // path to map
3257 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3260 parser.setError (Aborted,"Wrong number of parameters");
3261 /////////////////////////////////////////////////////////////////////
3262 } else if (com==QString("addXLink"))
3264 if (parser.parCount()>1)
3266 s=parser.parString (ok,0); // begin
3267 t=parser.parString (ok,1); // end
3268 BranchItem *begin=(BranchItem*)findBySelectString(s);
3269 BranchItem *end=(BranchItem*)findBySelectString(t);
3272 if (begin->isBranchLikeType() && end->isBranchLikeType())
3274 XLinkItem *xl=createXLink (begin,true);
3280 parser.setError (Aborted,"Failed to create xLink");
3283 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3286 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3288 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3289 /////////////////////////////////////////////////////////////////////
3290 } else if (com=="clearFlags")
3294 parser.setError (Aborted,"Nothing selected");
3295 } else if (! selbi )
3297 parser.setError (Aborted,"Type of selection is not a branch");
3298 } else if (parser.checkParCount(0))
3300 selbi->deactivateAllStandardFlags(); //FIXME-2 this probably should emitDataChanged and also setChanged. Similar all other direct changes should be done...
3302 /////////////////////////////////////////////////////////////////////
3303 } else if (com=="colorBranch")
3307 parser.setError (Aborted,"Nothing selected");
3308 } else if (! selbi )
3310 parser.setError (Aborted,"Type of selection is not a branch");
3311 } else if (parser.checkParCount(1))
3313 QColor c=parser.parColor (ok,0);
3314 if (ok) colorBranch (c);
3316 /////////////////////////////////////////////////////////////////////
3317 } else if (com=="colorSubtree")
3321 parser.setError (Aborted,"Nothing selected");
3322 } else if (! selbi )
3324 parser.setError (Aborted,"Type of selection is not a branch");
3325 } else if (parser.checkParCount(1))
3327 QColor c=parser.parColor (ok,0);
3328 if (ok) colorSubtree (c);
3330 /////////////////////////////////////////////////////////////////////
3331 } else if (com=="copy")
3335 parser.setError (Aborted,"Nothing selected");
3336 } else if ( selectionType()!=TreeItem::Branch &&
3337 selectionType()!=TreeItem::MapCenter &&
3338 selectionType()!=TreeItem::Image )
3340 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3341 } else if (parser.checkParCount(0))
3345 /////////////////////////////////////////////////////////////////////
3346 } else if (com=="cut")
3350 parser.setError (Aborted,"Nothing selected");
3351 } else if ( selectionType()!=TreeItem::Branch &&
3352 selectionType()!=TreeItem::MapCenter &&
3353 selectionType()!=TreeItem::Image )
3355 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3356 } else if (parser.checkParCount(0))
3360 /////////////////////////////////////////////////////////////////////
3361 } else if (com=="delete")
3365 parser.setError (Aborted,"Nothing selected");
3367 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3369 parser.setError (Aborted,"Type of selection is wrong.");
3372 else if (parser.checkParCount(0))
3376 /////////////////////////////////////////////////////////////////////
3377 } else if (com=="deleteKeepChildren")
3381 parser.setError (Aborted,"Nothing selected");
3382 } else if (! selbi )
3384 parser.setError (Aborted,"Type of selection is not a branch");
3385 } else if (parser.checkParCount(0))
3387 deleteKeepChildren();
3389 /////////////////////////////////////////////////////////////////////
3390 } else if (com=="deleteChildren")
3394 parser.setError (Aborted,"Nothing selected");
3397 parser.setError (Aborted,"Type of selection is not a branch");
3398 } else if (parser.checkParCount(0))
3402 /////////////////////////////////////////////////////////////////////
3403 } else if (com=="exportAO")
3407 if (parser.parCount()>=1)
3408 // Hey, we even have a filename
3409 fname=parser.parString(ok,0);
3412 parser.setError (Aborted,"Could not read filename");
3415 exportAO (fname,false);
3417 /////////////////////////////////////////////////////////////////////
3418 } else if (com=="exportASCII")
3422 if (parser.parCount()>=1)
3423 // Hey, we even have a filename
3424 fname=parser.parString(ok,0);
3427 parser.setError (Aborted,"Could not read filename");
3430 exportASCII (fname,false);
3432 /////////////////////////////////////////////////////////////////////
3433 } else if (com=="exportImage")
3437 if (parser.parCount()>=2)
3438 // Hey, we even have a filename
3439 fname=parser.parString(ok,0);
3442 parser.setError (Aborted,"Could not read filename");
3445 QString format="PNG";
3446 if (parser.parCount()>=2)
3448 format=parser.parString(ok,1);
3450 exportImage (fname,false,format);
3452 /////////////////////////////////////////////////////////////////////
3453 } else if (com=="exportXHTML")
3457 if (parser.parCount()>=2)
3458 // Hey, we even have a filename
3459 fname=parser.parString(ok,1);
3462 parser.setError (Aborted,"Could not read filename");
3465 exportXHTML (fname,false);
3467 /////////////////////////////////////////////////////////////////////
3468 } else if (com=="exportXML")
3472 if (parser.parCount()>=2)
3473 // Hey, we even have a filename
3474 fname=parser.parString(ok,1);
3477 parser.setError (Aborted,"Could not read filename");
3480 exportXML (fname,false);
3482 /////////////////////////////////////////////////////////////////////
3483 } else if (com=="getHeading")
3487 parser.setError (Aborted,"Nothing selected");
3488 } else if (parser.checkParCount(0))
3489 returnValue=selti->getHeading();
3490 /////////////////////////////////////////////////////////////////////
3491 } else if (com=="importDir")
3495 parser.setError (Aborted,"Nothing selected");
3496 } else if (! selbi )
3498 parser.setError (Aborted,"Type of selection is not a branch");
3499 } else if (parser.checkParCount(1))
3501 s=parser.parString(ok,0);
3502 if (ok) importDirInt(s);
3504 /////////////////////////////////////////////////////////////////////
3505 } else if (com=="relinkTo")
3509 parser.setError (Aborted,"Nothing selected");
3512 if (parser.checkParCount(4))
3514 // 0 selectstring of parent
3515 // 1 num in parent (for branches)
3516 // 2,3 x,y of mainbranch or mapcenter
3517 s=parser.parString(ok,0);
3518 TreeItem *dst=findBySelectString (s);
3521 if (dst->getType()==TreeItem::Branch)
3523 // Get number in parent
3524 n=parser.parInt (ok,1);
3527 relinkBranch (selbi,(BranchItem*)dst,n);
3528 emitSelectionChanged();
3530 } else if (dst->getType()==TreeItem::MapCenter)
3532 relinkBranch (selbi,(BranchItem*)dst);
3533 // Get coordinates of mainbranch
3534 x=parser.parDouble(ok,2);
3537 y=parser.parDouble(ok,3);
3540 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3541 emitSelectionChanged();
3547 } else if ( selti->getType() == TreeItem::Image)
3549 if (parser.checkParCount(1))
3551 // 0 selectstring of parent
3552 s=parser.parString(ok,0);
3553 TreeItem *dst=findBySelectString (s);
3556 if (dst->isBranchLikeType())
3557 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3559 parser.setError (Aborted,"Destination is not a branch");
3562 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3563 /////////////////////////////////////////////////////////////////////
3564 } else if (com=="loadImage")
3568 parser.setError (Aborted,"Nothing selected");
3569 } else if (! selbi )
3571 parser.setError (Aborted,"Type of selection is not a branch");
3572 } else if (parser.checkParCount(1))
3574 s=parser.parString(ok,0);
3575 if (ok) loadFloatImageInt (selbi,s);
3577 /////////////////////////////////////////////////////////////////////
3578 } else if (com=="loadNote")
3582 parser.setError (Aborted,"Nothing selected");
3583 } else if (! selbi )
3585 parser.setError (Aborted,"Type of selection is not a branch");
3586 } else if (parser.checkParCount(1))
3588 s=parser.parString(ok,0);
3589 if (ok) loadNote (s);
3591 /////////////////////////////////////////////////////////////////////
3592 } else if (com=="moveUp")
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(0))
3604 /////////////////////////////////////////////////////////////////////
3605 } else if (com=="moveDown")
3609 parser.setError (Aborted,"Nothing selected");
3610 } else if (! selbi )
3612 parser.setError (Aborted,"Type of selection is not a branch");
3613 } else if (parser.checkParCount(0))
3617 /////////////////////////////////////////////////////////////////////
3618 } else if (com=="move")
3622 parser.setError (Aborted,"Nothing selected");
3623 } else if ( selectionType()!=TreeItem::Branch &&
3624 selectionType()!=TreeItem::MapCenter &&
3625 selectionType()!=TreeItem::Image )
3627 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3628 } else if (parser.checkParCount(2))
3630 x=parser.parDouble (ok,0);
3633 y=parser.parDouble (ok,1);
3637 /////////////////////////////////////////////////////////////////////
3638 } else if (com=="moveRel")
3642 parser.setError (Aborted,"Nothing selected");
3643 } else if ( selectionType()!=TreeItem::Branch &&
3644 selectionType()!=TreeItem::MapCenter &&
3645 selectionType()!=TreeItem::Image )
3647 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3648 } else if (parser.checkParCount(2))
3650 x=parser.parDouble (ok,0);
3653 y=parser.parDouble (ok,1);
3654 if (ok) moveRel (x,y);
3657 /////////////////////////////////////////////////////////////////////
3658 } else if (com=="nop")
3660 /////////////////////////////////////////////////////////////////////
3661 } else if (com=="paste")
3665 parser.setError (Aborted,"Nothing selected");
3666 } else if (! selbi )
3668 parser.setError (Aborted,"Type of selection is not a branch");
3669 } else if (parser.checkParCount(1))
3671 n=parser.parInt (ok,0);
3672 if (ok) pasteNoSave(n);
3674 /////////////////////////////////////////////////////////////////////
3675 } else if (com=="qa")
3679 parser.setError (Aborted,"Nothing selected");
3680 } else if (! selbi )
3682 parser.setError (Aborted,"Type of selection is not a branch");
3683 } else if (parser.checkParCount(4))
3686 c=parser.parString (ok,0);
3689 parser.setError (Aborted,"No comment given");
3692 s=parser.parString (ok,1);
3695 parser.setError (Aborted,"First parameter is not a string");
3698 t=parser.parString (ok,2);
3701 parser.setError (Aborted,"Condition is not a string");
3704 u=parser.parString (ok,3);
3707 parser.setError (Aborted,"Third parameter is not a string");
3712 parser.setError (Aborted,"Unknown type: "+s);
3717 parser.setError (Aborted,"Unknown operator: "+t);
3722 parser.setError (Aborted,"Type of selection is not a branch");
3725 if (selbi->getHeading() == u)
3727 cout << "PASSED: " << qPrintable (c) << endl;
3730 cout << "FAILED: " << qPrintable (c) << endl;
3740 /////////////////////////////////////////////////////////////////////
3741 } else if (com=="saveImage")
3743 ImageItem *ii=getSelectedImage();
3746 parser.setError (Aborted,"No image selected");
3747 } else if (parser.checkParCount(2))
3749 s=parser.parString(ok,0);
3752 t=parser.parString(ok,1);
3753 if (ok) saveFloatImageInt (ii,t,s);
3756 /////////////////////////////////////////////////////////////////////
3757 } else if (com=="saveNote")
3761 parser.setError (Aborted,"Nothing selected");
3762 } else if (! selbi )
3764 parser.setError (Aborted,"Type of selection is not a branch");
3765 } else if (parser.checkParCount(1))
3767 s=parser.parString(ok,0);
3768 if (ok) saveNote (s);
3770 /////////////////////////////////////////////////////////////////////
3771 } else if (com=="scroll")
3775 parser.setError (Aborted,"Nothing selected");
3776 } else if (! selbi )
3778 parser.setError (Aborted,"Type of selection is not a branch");
3779 } else if (parser.checkParCount(0))
3781 if (!scrollBranch (selbi))
3782 parser.setError (Aborted,"Could not scroll branch");
3784 /////////////////////////////////////////////////////////////////////
3785 } else if (com=="select")
3787 if (parser.checkParCount(1))
3789 s=parser.parString(ok,0);
3792 /////////////////////////////////////////////////////////////////////
3793 } else if (com=="selectLastBranch")
3797 parser.setError (Aborted,"Nothing selected");
3798 } else if (! selbi )
3800 parser.setError (Aborted,"Type of selection is not a branch");
3801 } else if (parser.checkParCount(0))
3803 BranchItem *bi=selbi->getLastBranch();
3805 parser.setError (Aborted,"Could not select last branch");
3806 select (bi); // FIXME-3 was selectInt
3809 /////////////////////////////////////////////////////////////////////
3810 } else /* FIXME-2 if (com=="selectLastImage")
3814 parser.setError (Aborted,"Nothing selected");
3815 } else if (! selbi )
3817 parser.setError (Aborted,"Type of selection is not a branch");
3818 } else if (parser.checkParCount(0))
3820 FloatImageObj *fio=selb->getLastFloatImage();
3822 parser.setError (Aborted,"Could not select last image");
3823 select (fio); // FIXME-3 was selectInt
3826 /////////////////////////////////////////////////////////////////////
3827 } else */ if (com=="selectLatestAdded")
3829 if (!latestAddedItem)
3831 parser.setError (Aborted,"No latest added object");
3834 if (!select (latestAddedItem))
3835 parser.setError (Aborted,"Could not select latest added object ");
3837 /////////////////////////////////////////////////////////////////////
3838 } else if (com=="setFlag")
3842 parser.setError (Aborted,"Nothing selected");
3843 } else if (! selbi )
3845 parser.setError (Aborted,"Type of selection is not a branch");
3846 } else if (parser.checkParCount(1))
3848 s=parser.parString(ok,0);
3850 selbi->activateStandardFlag(s);
3852 /////////////////////////////////////////////////////////////////////
3853 } else if (com=="setFrameType")
3855 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3857 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3859 else if (parser.checkParCount(1))
3861 s=parser.parString(ok,0);
3862 if (ok) setFrameType (s);
3864 /////////////////////////////////////////////////////////////////////
3865 } else if (com=="setFramePenColor")
3867 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3869 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3871 else if (parser.checkParCount(1))
3873 QColor c=parser.parColor(ok,0);
3874 if (ok) setFramePenColor (c);
3876 /////////////////////////////////////////////////////////////////////
3877 } else if (com=="setFrameBrushColor")
3879 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3881 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3883 else if (parser.checkParCount(1))
3885 QColor c=parser.parColor(ok,0);
3886 if (ok) setFrameBrushColor (c);
3888 /////////////////////////////////////////////////////////////////////
3889 } else if (com=="setFramePadding")
3891 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3893 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3895 else if (parser.checkParCount(1))
3897 n=parser.parInt(ok,0);
3898 if (ok) setFramePadding(n);
3900 /////////////////////////////////////////////////////////////////////
3901 } else if (com=="setFrameBorderWidth")
3903 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3905 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3907 else if (parser.checkParCount(1))
3909 n=parser.parInt(ok,0);
3910 if (ok) setFrameBorderWidth (n);
3912 /////////////////////////////////////////////////////////////////////
3913 /* FIXME-2 else if (com=="setFrameType")
3917 parser.setError (Aborted,"Nothing selected");
3920 parser.setError (Aborted,"Type of selection is not a branch");
3921 } else if (parser.checkParCount(1))
3923 s=parser.parString(ok,0);
3927 /////////////////////////////////////////////////////////////////////
3929 /////////////////////////////////////////////////////////////////////
3930 } else if (com=="setHeading")
3934 parser.setError (Aborted,"Nothing selected");
3935 } else if (! selbi )
3937 parser.setError (Aborted,"Type of selection is not a branch");
3938 } else if (parser.checkParCount(1))
3940 s=parser.parString (ok,0);
3944 /////////////////////////////////////////////////////////////////////
3945 } else if (com=="setHideExport")
3949 parser.setError (Aborted,"Nothing selected");
3950 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3952 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3953 } else if (parser.checkParCount(1))
3955 b=parser.parBool(ok,0);
3956 if (ok) setHideExport (b);
3958 /////////////////////////////////////////////////////////////////////
3959 } else if (com=="setIncludeImagesHorizontally")
3963 parser.setError (Aborted,"Nothing selected");
3966 parser.setError (Aborted,"Type of selection is not a branch");
3967 } else if (parser.checkParCount(1))
3969 b=parser.parBool(ok,0);
3970 if (ok) setIncludeImagesHor(b);
3972 /////////////////////////////////////////////////////////////////////
3973 } else if (com=="setIncludeImagesVertically")
3977 parser.setError (Aborted,"Nothing selected");
3980 parser.setError (Aborted,"Type of selection is not a branch");
3981 } else if (parser.checkParCount(1))
3983 b=parser.parBool(ok,0);
3984 if (ok) setIncludeImagesVer(b);
3986 /////////////////////////////////////////////////////////////////////
3987 } else if (com=="setHideLinkUnselected")
3991 parser.setError (Aborted,"Nothing selected");
3992 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3994 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3995 } else if (parser.checkParCount(1))
3997 b=parser.parBool(ok,0);
3998 if (ok) setHideLinkUnselected(b);
4000 /////////////////////////////////////////////////////////////////////
4001 } else if (com=="setMapAuthor")
4003 if (parser.checkParCount(1))
4005 s=parser.parString(ok,0);
4006 if (ok) setAuthor (s);
4008 /////////////////////////////////////////////////////////////////////
4009 } else if (com=="setMapComment")
4011 if (parser.checkParCount(1))
4013 s=parser.parString(ok,0);
4014 if (ok) setComment(s);
4016 /////////////////////////////////////////////////////////////////////
4017 } else if (com=="setMapBackgroundColor")
4021 parser.setError (Aborted,"Nothing selected");
4022 } else if (! selbi )
4024 parser.setError (Aborted,"Type of selection is not a branch");
4025 } else if (parser.checkParCount(1))
4027 QColor c=parser.parColor (ok,0);
4028 if (ok) setMapBackgroundColor (c);
4030 /////////////////////////////////////////////////////////////////////
4031 } else if (com=="setMapDefLinkColor")
4035 parser.setError (Aborted,"Nothing selected");
4036 } else if (! selbi )
4038 parser.setError (Aborted,"Type of selection is not a branch");
4039 } else if (parser.checkParCount(1))
4041 QColor c=parser.parColor (ok,0);
4042 if (ok) setMapDefLinkColor (c);
4044 /////////////////////////////////////////////////////////////////////
4045 } else if (com=="setMapLinkStyle")
4047 if (parser.checkParCount(1))
4049 s=parser.parString (ok,0);
4050 if (ok) setMapLinkStyle(s);
4052 /////////////////////////////////////////////////////////////////////
4053 } else if (com=="setNote")
4057 parser.setError (Aborted,"Nothing selected");
4058 } else if (! selbi )
4060 parser.setError (Aborted,"Type of selection is not a branch");
4061 } else if (parser.checkParCount(1))
4063 s=parser.parString (ok,0);
4067 /////////////////////////////////////////////////////////////////////
4068 } else if (com=="setSelectionColor")
4070 if (parser.checkParCount(1))
4072 QColor c=parser.parColor (ok,0);
4073 if (ok) setSelectionColorInt (c);
4075 /////////////////////////////////////////////////////////////////////
4076 } else if (com=="setURL")
4080 parser.setError (Aborted,"Nothing selected");
4081 } else if (! selbi )
4083 parser.setError (Aborted,"Type of selection is not a branch");
4084 } else if (parser.checkParCount(1))
4086 s=parser.parString (ok,0);
4089 /////////////////////////////////////////////////////////////////////
4090 } else if (com=="setVymLink")
4094 parser.setError (Aborted,"Nothing selected");
4095 } else if (! selbi )
4097 parser.setError (Aborted,"Type of selection is not a branch");
4098 } else if (parser.checkParCount(1))
4100 s=parser.parString (ok,0);
4101 if (ok) setVymLink(s);
4103 } else if (com=="sortChildren")
4107 parser.setError (Aborted,"Nothing selected");
4108 } else if (! selbi )
4110 parser.setError (Aborted,"Type of selection is not a branch");
4111 } else if (parser.checkParCount(0))
4114 } else if (parser.checkParCount(1))
4116 b=parser.parBool(ok,0);
4117 if (ok) sortChildren(b);
4119 /////////////////////////////////////////////////////////////////////
4120 } else if (com=="toggleFlag")
4124 parser.setError (Aborted,"Nothing selected");
4125 } else if (! selbi )
4127 parser.setError (Aborted,"Type of selection is not a branch");
4128 } else if (parser.checkParCount(1))
4130 s=parser.parString(ok,0);
4132 selbi->toggleStandardFlag(s);
4134 /////////////////////////////////////////////////////////////////////
4135 } else if (com=="unscroll")
4139 parser.setError (Aborted,"Nothing selected");
4140 } else if (! selbi )
4142 parser.setError (Aborted,"Type of selection is not a branch");
4143 } else if (parser.checkParCount(0))
4145 if (!unscrollBranch (selbi))
4146 parser.setError (Aborted,"Could not unscroll branch");
4148 /////////////////////////////////////////////////////////////////////
4149 } else if (com=="unscrollChildren")
4153 parser.setError (Aborted,"Nothing selected");
4154 } else if (! selbi )
4156 parser.setError (Aborted,"Type of selection is not a branch");
4157 } else if (parser.checkParCount(0))
4159 unscrollChildren ();
4161 /////////////////////////////////////////////////////////////////////
4162 } else if (com=="unsetFlag")
4166 parser.setError (Aborted,"Nothing selected");
4167 } else if (! selbi )
4169 parser.setError (Aborted,"Type of selection is not a branch");
4170 } else if (parser.checkParCount(1))
4172 s=parser.parString(ok,0);
4174 selbi->deactivateStandardFlag(s);
4177 parser.setError (Aborted,"Unknown command");
4180 if (parser.errorLevel()==NoError)
4188 // TODO Error handling
4189 qWarning("VymModel::parseAtom: Error!");
4191 qWarning(parser.errorMessage());
4193 errorMsg=parser.errorMessage();
4194 returnValue=errorMsg;
4199 QVariant VymModel::runScript (const QString &script)
4201 parser.setScript (script);
4206 while (parser.next() && noErr)
4208 r=parseAtom(parser.getAtom(),noErr,errMsg);
4209 if (!noErr) //FIXME-3 need dialog box here
4210 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4215 void VymModel::setExportMode (bool b)
4217 // should be called before and after exports
4218 // depending on the settings
4219 if (b && settings.value("/export/useHideExport","true")=="true")
4220 setHideTmpMode (TreeItem::HideExport);
4222 setHideTmpMode (TreeItem::HideNone);
4225 void VymModel::exportImage(QString fname, bool askName, QString format)
4229 fname=getMapName()+".png";
4236 QFileDialog *fd=new QFileDialog (NULL);
4237 fd->setCaption (tr("Export map as image"));
4238 fd->setDirectory (lastImageDir);
4239 fd->setFileMode(QFileDialog::AnyFile);
4240 fd->setFilters (imageIO.getFilters() );
4243 fl=fd->selectedFiles();
4245 format=imageIO.getType(fd->selectedFilter());
4249 setExportMode (true);
4250 mapEditor->getScene()->update(); // FIXME-3 check this...
4251 QImage img (mapEditor->getImage()); //FIXME-3 calls getTotalBBox, but also in ExportHTML::doExport()
4252 img.save(fname, format);
4253 setExportMode (false);
4257 void VymModel::exportXML(QString dir, bool askForName)
4261 dir=browseDirectory(NULL,tr("Export XML to directory"));
4262 if (dir =="" && !reallyWriteDirectory(dir) )
4266 // Hide stuff during export, if settings want this
4267 setExportMode (true);
4269 // Create subdirectories
4272 // write to directory //FIXME-4 check totalBBox here...
4273 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4276 file.setName ( dir + "/"+mapName+".xml");
4277 if ( !file.open( QIODevice::WriteOnly ) )
4279 // This should neverever happen
4280 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4284 // Write it finally, and write in UTF8, no matter what
4285 QTextStream ts( &file );
4286 ts.setEncoding (QTextStream::UnicodeUTF8);
4290 // Now write image, too
4291 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4293 setExportMode (false);
4296 void VymModel::exportAO (QString fname,bool askName)
4301 ex.setFile (mapName+".txt");
4307 //ex.addFilter ("TXT (*.txt)");
4308 ex.setDir(lastImageDir);
4309 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4314 setExportMode(true);
4316 setExportMode(false);
4320 void VymModel::exportASCII(QString fname,bool askName)
4325 ex.setFile (mapName+".txt");
4331 //ex.addFilter ("TXT (*.txt)");
4332 ex.setDir(lastImageDir);
4333 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4338 setExportMode(true);
4340 setExportMode(false);
4344 void VymModel::exportHTML (const QString &dir, bool useDialog)
4346 ExportHTML ex (this);
4348 ex.doExport(useDialog);
4351 void VymModel::exportXHTML (const QString &dir, bool askForName)
4353 ExportXHTMLDialog dia(NULL);
4354 dia.setFilePath (filePath );
4355 dia.setMapName (mapName );
4357 if (dir!="") dia.setDir (dir);
4363 if (dia.exec()!=QDialog::Accepted)
4367 QDir d (dia.getDir());
4368 // Check, if warnings should be used before overwriting
4369 // the output directory
4370 if (d.exists() && d.count()>0)
4373 warn.showCancelButton (true);
4374 warn.setText(QString(
4375 "The directory %1 is not empty.\n"
4376 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4377 warn.setCaption("Warning: Directory not empty");
4378 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4380 if (warn.exec()!=QDialog::Accepted) ok=false;
4387 exportXML (dia.getDir(),false );
4388 dia.doExport(mapName );
4389 //if (dia.hasChanged()) setChanged();
4393 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4398 if (ex.setConfigFile(cf))
4400 setExportMode (true);
4401 ex.exportPresentation();
4402 setExportMode (false);
4409 //////////////////////////////////////////////
4411 //////////////////////////////////////////////
4413 void VymModel::registerEditor(QWidget *me)
4415 mapEditor=(MapEditor*)me;
4418 void VymModel::unregisterEditor(QWidget *)
4423 void VymModel::setMapZoomFactor (const double &d)
4428 void VymModel::setContextPos(QPointF p)
4433 void VymModel::unsetContextPos()
4435 contextPos=QPointF();
4438 void VymModel::updateNoteFlag()
4440 TreeItem *selti=getSelectedItem();
4449 if (textEditor->isEmpty())
4452 selti->setNote (textEditor->getText());
4453 emitDataHasChanged(selti);
4457 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4459 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4460 if (blockReposition) return;
4462 for (int i=0;i<rootItem->branchCount(); i++)
4463 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4464 //emitSelectionChanged();
4468 void VymModel::setMapLinkStyle (const QString & s)
4473 case LinkableMapObj::Line :
4476 case LinkableMapObj::Parabel:
4477 snow="StyleParabel";
4479 case LinkableMapObj::PolyLine:
4480 snow="StylePolyLine";
4482 case LinkableMapObj::PolyParabel:
4483 snow="StylePolyParabel";
4486 snow="UndefinedStyle";
4491 QString("setMapLinkStyle (\"%1\")").arg(s),
4492 QString("setMapLinkStyle (\"%1\")").arg(snow),
4493 QString("Set map link style (\"%1\")").arg(s)
4497 linkstyle=LinkableMapObj::Line;
4498 else if (s=="StyleParabel")
4499 linkstyle=LinkableMapObj::Parabel;
4500 else if (s=="StylePolyLine")
4501 linkstyle=LinkableMapObj::PolyLine;
4502 else if (s=="StylePolyParabel")
4503 linkstyle=LinkableMapObj::PolyParabel;
4505 linkstyle=LinkableMapObj::UndefinedStyle;
4507 BranchItem *cur=NULL;
4508 BranchItem *prev=NULL;
4510 nextBranch (cur,prev);
4513 bo=(BranchObj*)(cur->getLMO() );
4514 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4515 cur=nextBranch(cur,prev);
4520 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4525 uint VymModel::getID()
4530 void VymModel::setMapDefLinkColor(QColor col)
4532 if ( !col.isValid() ) return;
4534 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4535 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4536 QString("Set map link color to %1").arg(col.name())
4540 BranchItem *cur=NULL;
4541 BranchItem *prev=NULL;
4543 cur=nextBranch(cur,prev);
4546 bo=(BranchObj*)(cur->getLMO() );
4548 nextBranch(cur,prev);
4553 void VymModel::setMapLinkColorHintInt()
4555 // called from setMapLinkColorHint(lch) or at end of parse
4556 BranchItem *cur=NULL;
4557 BranchItem *prev=NULL;
4559 cur=nextBranch(cur,prev);
4562 bo=(BranchObj*)(cur->getLMO() );
4564 cur=nextBranch(cur,prev);
4568 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4571 setMapLinkColorHintInt();
4574 void VymModel::toggleMapLinkColorHint()
4576 if (linkcolorhint==LinkableMapObj::HeadingColor)
4577 linkcolorhint=LinkableMapObj::DefaultColor;
4579 linkcolorhint=LinkableMapObj::HeadingColor;
4580 BranchItem *cur=NULL;
4581 BranchItem *prev=NULL;
4583 cur=nextBranch(cur,prev);
4586 bo=(BranchObj*)(cur->getLMO() );
4588 nextBranch(cur,prev);
4592 void VymModel::selectMapBackgroundImage () // FIXME-3 for using background image: view.setCacheMode(QGraphicsView::CacheBackground); Also this belongs into ME
4594 Q3FileDialog *fd=new Q3FileDialog( NULL);
4595 fd->setMode (Q3FileDialog::ExistingFile);
4596 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4597 ImagePreview *p =new ImagePreview (fd);
4598 fd->setContentsPreviewEnabled( TRUE );
4599 fd->setContentsPreview( p, p );
4600 fd->setPreviewMode( Q3FileDialog::Contents );
4601 fd->setCaption(vymName+" - " +tr("Load background image"));
4602 fd->setDir (lastImageDir);
4605 if ( fd->exec() == QDialog::Accepted )
4607 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4608 lastImageDir=QDir (fd->dirPath());
4609 setMapBackgroundImage (fd->selectedFile());
4613 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4615 QColor oldcol=mapScene->backgroundBrush().color();
4619 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4621 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4622 QString("Set background color of map to %1").arg(col.name()));
4625 brush.setTextureImage (QPixmap (fn));
4626 mapScene->setBackgroundBrush(brush);
4629 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4631 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4632 if ( !col.isValid() ) return;
4633 setMapBackgroundColor( col );
4637 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4639 QColor oldcol=mapScene->backgroundBrush().color();
4641 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4642 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4643 QString("Set background color of map to %1").arg(col.name()));
4644 mapScene->setBackgroundBrush(col);
4647 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4649 return mapScene->backgroundBrush().color();
4653 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4655 return linkcolorhint;
4658 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4660 return defLinkColor;
4663 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4668 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4670 return defXLinkColor;
4673 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4678 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4680 return defXLinkWidth;
4683 void VymModel::move(const double &x, const double &y)
4686 MapItem *seli = (MapItem*)getSelectedItem();
4687 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4689 LinkableMapObj *lmo=seli->getLMO();
4692 QPointF ap(lmo->getAbsPos());
4696 QString ps=qpointFToString(ap);
4697 QString s=getSelectString(seli);
4700 s, "move "+qpointFToString(to),
4701 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4704 emitSelectionChanged();
4710 void VymModel::moveRel (const double &x, const double &y)
4713 MapItem *seli = (MapItem*)getSelectedItem();
4714 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4716 LinkableMapObj *lmo=seli->getLMO();
4719 QPointF rp(lmo->getRelPos());
4723 QString ps=qpointFToString (lmo->getRelPos());
4724 QString s=getSelectString(seli);
4727 s, "moveRel "+qpointFToString(to),
4728 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4729 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4731 lmo->updateLinkGeometry();
4732 emitSelectionChanged();
4739 void VymModel::animate()
4741 animationTimer->stop();
4744 while (i<animObjList.size() )
4746 bo=(BranchObj*)animObjList.at(i);
4751 animObjList.removeAt(i);
4758 QItemSelection sel=selModel->selection();
4759 emit (selectionChanged(sel,sel));
4762 if (!animObjList.isEmpty()) animationTimer->start();
4766 void VymModel::startAnimation(BranchObj *bo, const QPointF &v)
4770 if (bo->getUseRelPos())
4771 startAnimation (bo,bo->getRelPos(),bo->getRelPos()+v);
4773 startAnimation (bo,bo->getAbsPos(),bo->getAbsPos()+v);
4776 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4778 if (start==dest) return;
4779 if (bo && bo->getTreeItem()->depth()>=0)
4782 ap.setStart (start);
4784 ap.setTicks (animationTicks);
4785 ap.setAnimated (true);
4786 bo->setAnimation (ap);
4787 if (!animObjList.contains(bo))
4788 animObjList.append( bo );
4789 animationTimer->setSingleShot (true);
4790 animationTimer->start(animationInterval);
4794 void VymModel::stopAnimation (MapObj *mo)
4796 int i=animObjList.indexOf(mo);
4798 animObjList.removeAt (i);
4801 void VymModel::sendSelection()
4803 if (netstate!=Server) return;
4804 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4807 void VymModel::newServer()
4811 tcpServer = new QTcpServer(this);
4812 if (!tcpServer->listen(QHostAddress::Any,port)) {
4813 QMessageBox::critical(NULL, "vym server",
4814 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4815 //FIXME-3 needed? we are no widget any longer... close();
4818 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4820 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4823 void VymModel::connectToServer()
4826 server="salam.suse.de";
4828 clientSocket = new QTcpSocket (this);
4829 clientSocket->abort();
4830 clientSocket->connectToHost(server ,port);
4831 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4832 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4833 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4835 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4840 void VymModel::newClient()
4842 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4843 connect(newClient, SIGNAL(disconnected()),
4844 newClient, SLOT(deleteLater()));
4846 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4848 clientList.append (newClient);
4852 void VymModel::sendData(const QString &s)
4854 if (clientList.size()==0) return;
4856 // Create bytearray to send
4858 QDataStream out(&block, QIODevice::WriteOnly);
4859 out.setVersion(QDataStream::Qt_4_0);
4861 // Reserve some space for blocksize
4864 // Write sendCounter
4865 out << sendCounter++;
4870 // Go back and write blocksize so far
4871 out.device()->seek(0);
4872 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4876 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4878 for (int i=0; i<clientList.size(); ++i)
4880 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4881 clientList.at(i)->write (block);
4885 void VymModel::readData ()
4887 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4890 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4894 QDataStream in(clientSocket);
4895 in.setVersion(QDataStream::Qt_4_0);
4903 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4906 parseAtom (t,noErr,errMsg);
4912 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4914 switch (socketError) {
4915 case QAbstractSocket::RemoteHostClosedError:
4917 case QAbstractSocket::HostNotFoundError:
4918 QMessageBox::information(NULL, vymName +" Network client",
4919 "The host was not found. Please check the "
4920 "host name and port settings.");
4922 case QAbstractSocket::ConnectionRefusedError:
4923 QMessageBox::information(NULL, vymName + " Network client",
4924 "The connection was refused by the peer. "
4925 "Make sure the fortune server is running, "
4926 "and check that the host name and port "
4927 "settings are correct.");
4930 QMessageBox::information(NULL, vymName + " Network client",
4931 QString("The following error occurred: %1.")
4932 .arg(clientSocket->errorString()));
4936 /* FIXME-3 Playing with DBUS...
4937 QDBusVariant VymModel::query (const QString &query)
4939 TreeItem *selti=getSelectedItem();
4941 return QDBusVariant (selti->getHeading());
4943 return QDBusVariant ("Nothing selected.");
4947 void VymModel::testslot() //FIXME-3 Playing with DBUS
4949 cout << "VM::testslot called\n";
4952 void VymModel::selectMapSelectionColor()
4954 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4955 setSelectionColor (col);
4958 void VymModel::setSelectionColorInt (QColor col)
4960 if ( !col.isValid() ) return;
4962 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4963 QString("setSelectionColor (%1)").arg(col.name()),
4964 QString("Set color of selection box to %1").arg(col.name())
4967 mapEditor->setSelectionColor (col);
4970 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4972 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4973 //FIXME-3 emitShowSelection();
4977 void VymModel::emitSelectionChanged()
4979 QItemSelection newsel=selModel->selection();
4980 emitSelectionChanged (newsel);
4983 void VymModel::setSelectionColor(QColor col)
4985 if ( !col.isValid() ) return;
4987 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4988 QString("setSelectionColor (%1)").arg(col.name()),
4989 QString("Set color of selection box to %1").arg(col.name())
4991 setSelectionColorInt (col);
4994 QColor VymModel::getSelectionColor()
4996 return mapEditor->getSelectionColor();
4999 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
5002 for (int i=0;i<rootItem->branchCount();i++)
5003 rootItem->getBranchNum(i)->setHideTmp (mode);
5005 if (mode==TreeItem::HideExport)
5011 //////////////////////////////////////////////
5012 // Selection related
5013 //////////////////////////////////////////////
5015 void VymModel::setSelectionModel (QItemSelectionModel *sm)
5020 QItemSelectionModel* VymModel::getSelectionModel()
5025 void VymModel::setSelectionBlocked (bool b)
5030 bool VymModel::isSelectionBlocked()
5032 return selectionBlocked;
5035 bool VymModel::select ()
5037 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
5040 bool VymModel::select (const QString &s)
5047 TreeItem *ti=findBySelectString(s);
5048 if (ti) return select (index(ti));
5052 bool VymModel::select (LinkableMapObj *lmo)
5054 QItemSelection oldsel=selModel->selection();
5057 return select (index (lmo->getTreeItem()) );
5062 bool VymModel::select (TreeItem *ti)
5064 if (ti) return select (index(ti));
5068 bool VymModel::select (const QModelIndex &index)
5070 if (index.isValid() )
5072 selModel->select (index,QItemSelectionModel::ClearAndSelect );
5073 BranchItem *bi=getSelectedBranch();
5074 if (bi) bi->setLastSelectedBranch();
5080 void VymModel::unselect()
5082 if (!selModel->selectedIndexes().isEmpty())
5084 lastSelectString=getSelectString();
5085 selModel->clearSelection();
5089 bool VymModel::reselect()
5091 return select (lastSelectString);
5094 void VymModel::emitShowSelection()
5096 if (!blockReposition)
5097 emit (showSelection() );
5100 void VymModel::emitNoteHasChanged (TreeItem *ti)
5102 QModelIndex ix=index(ti);
5103 emit (noteHasChanged (ix) );
5106 void VymModel::emitDataHasChanged (TreeItem *ti)
5108 QModelIndex ix=index(ti);
5109 emit (dataChanged (ix,ix) );
5112 void VymModel::emitUpdateLayout()
5114 if (settings.value("/mainwindow/autoLayout/use","true")=="true")
5115 emit (updateLayout());
5118 bool VymModel::selectFirstBranch()
5120 TreeItem *ti=getSelectedBranch();
5123 TreeItem *par=ti->parent();
5126 TreeItem *ti2=par->getFirstBranch();
5127 if (ti2) return select(ti2);
5133 bool VymModel::selectLastBranch()
5135 TreeItem *ti=getSelectedBranch();
5138 TreeItem *par=ti->parent();
5141 TreeItem *ti2=par->getLastBranch();
5142 if (ti2) return select(ti2);
5148 bool VymModel::selectLastSelectedBranch()
5150 BranchItem *bi=getSelectedBranch();
5153 bi=bi->getLastSelectedBranch();
5154 if (bi) return select (bi);
5159 bool VymModel::selectParent()
5161 TreeItem *ti=getSelectedItem();
5172 TreeItem::Type VymModel::selectionType()
5174 QModelIndexList list=selModel->selectedIndexes();
5175 if (list.isEmpty()) return TreeItem::Undefined;
5176 TreeItem *ti = getItem (list.first() );
5177 return ti->getType();
5181 LinkableMapObj* VymModel::getSelectedLMO()
5183 QModelIndexList list=selModel->selectedIndexes();
5184 if (!list.isEmpty() )
5186 TreeItem *ti = getItem (list.first() );
5187 TreeItem::Type type=ti->getType();
5188 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5189 return ((MapItem*)ti)->getLMO();
5194 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5196 TreeItem *ti = getSelectedBranch();
5198 return (BranchObj*)( ((MapItem*)ti)->getLMO());
5203 BranchItem* VymModel::getSelectedBranch()
5205 QModelIndexList list=selModel->selectedIndexes();
5206 if (!list.isEmpty() )
5208 TreeItem *ti = getItem (list.first() );
5209 TreeItem::Type type=ti->getType();
5210 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5211 return (BranchItem*)ti;
5216 ImageItem* VymModel::getSelectedImage()
5218 QModelIndexList list=selModel->selectedIndexes();
5219 if (!list.isEmpty())
5221 TreeItem *ti=getItem (list.first());
5222 if (ti && ti->getType()==TreeItem::Image)
5223 return (ImageItem*)ti;
5228 AttributeItem* VymModel::getSelectedAttribute()
5230 QModelIndexList list=selModel->selectedIndexes();
5231 if (!list.isEmpty() )
5233 TreeItem *ti = getItem (list.first() );
5234 TreeItem::Type type=ti->getType();
5235 if (type ==TreeItem::Attribute)
5236 return (AttributeItem*)ti;
5241 TreeItem* VymModel::getSelectedItem()
5243 QModelIndexList list=selModel->selectedIndexes();
5244 if (!list.isEmpty() )
5245 return getItem (list.first() );
5250 QModelIndex VymModel::getSelectedIndex()
5252 QModelIndexList list=selModel->selectedIndexes();
5253 if (list.isEmpty() )
5254 return QModelIndex();
5256 return list.first();
5259 QString VymModel::getSelectString ()
5261 return getSelectString (getSelectedItem());
5264 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5266 if (!lmo) return QString();
5267 return getSelectString (lmo->getTreeItem() );
5270 QString VymModel::getSelectString (TreeItem *ti)
5274 switch (ti->getType())
5276 case TreeItem::MapCenter: s="mc:"; break;
5277 case TreeItem::Branch: s="bo:";break;
5278 case TreeItem::Image: s="fi:";break;
5279 case TreeItem::Attribute: s="ai:";break;
5280 case TreeItem::XLink: s="xl:";break;
5282 s="unknown type in VymModel::getSelectString()";
5285 s= s + QString("%1").arg(ti->num());
5287 // call myself recursively
5288 s= getSelectString(ti->parent()) +","+s;