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
2546 BranchItem *selbi=getSelectedBranch();
2551 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2553 BranchItem *pi=(BranchItem*)(deleteItem (selbi));
2556 if (pi->isScrolled() && pi->branchCount()==0)
2559 emitDataHasChanged(pi);
2562 emitShowSelection();
2566 TreeItem *ti=getSelectedItem();
2568 { // Delete other item
2569 TreeItem *pi=ti->parent();
2571 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2573 saveStateChangingPart(
2577 QString("Delete %1").arg(getObjectName(ti))
2581 emitDataHasChanged (pi);
2584 emitShowSelection();
2585 } else if (ti->getType()==TreeItem::XLink)
2587 //FIXME-2 savestate for deleting xlink missing
2590 qWarning ("VymmModel::deleteSelection() unknown type?!");
2594 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2597 BranchItem *selbi=getSelectedBranch();
2601 // Don't use this on mapcenter
2602 if (selbi->depth()<2) return;
2604 pi=(BranchItem*)(selbi->parent());
2605 // Check if we have children at all to keep
2606 if (selbi->branchCount()==0)
2613 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2614 saveStateChangingPart(
2617 "deleteKeepChildren ()",
2618 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2621 QString sel=getSelectString(selbi);
2623 int pos=selbi->num();
2624 BranchItem *bi=selbi->getFirstBranch();
2627 relinkBranch (bi,pi,pos);
2628 bi=selbi->getFirstBranch();
2634 BranchObj *bo=getSelectedBranchObj();
2637 bo->move2RelPos (p);
2643 void VymModel::deleteChildren()
2646 BranchItem *selbi=getSelectedBranch();
2649 saveStateChangingPart(
2652 "deleteChildren ()",
2653 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2655 emit (layoutAboutToBeChanged() );
2657 QModelIndex ix=index (selbi);
2658 int n=selbi->branchCount()-1;
2659 beginRemoveRows (ix,0,n);
2660 removeRows (0,n+1,ix);
2662 if (selbi->isScrolled()) selbi->unScroll();
2663 emit (layoutChanged() );
2668 TreeItem* VymModel::deleteItem (TreeItem *ti)
2672 TreeItem *pi=ti->parent();
2673 QModelIndex parentIndex=index(pi);
2675 emit (layoutAboutToBeChanged() );
2677 int n=ti->childNum();
2678 beginRemoveRows (parentIndex,n,n);
2679 removeRows (n,1,parentIndex);
2683 emit (layoutChanged() );
2684 if (pi->depth()>=0) return pi;
2689 void VymModel::clearItem (TreeItem *ti)
2693 QModelIndex parentIndex=index(ti);
2694 if (!parentIndex.isValid()) return;
2696 int n=ti->childCount();
2699 emit (layoutAboutToBeChanged() );
2701 beginRemoveRows (parentIndex,0,n-1);
2702 removeRows (0,n,parentIndex);
2706 emit (layoutChanged() );
2712 bool VymModel::scrollBranch(BranchItem *bi)
2716 if (bi->isScrolled()) return false;
2717 if (bi->branchCount()==0) return false;
2718 if (bi->depth()==0) return false;
2719 if (bi->toggleScroll())
2727 QString ("%1 ()").arg(u),
2729 QString ("%1 ()").arg(r),
2730 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2732 emitDataHasChanged(bi);
2733 emitSelectionChanged();
2734 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2741 bool VymModel::unscrollBranch(BranchItem *bi)
2745 if (!bi->isScrolled()) return false;
2746 if (bi->branchCount()==0) return false;
2747 if (bi->depth()==0) return false;
2748 if (bi->toggleScroll())
2756 QString ("%1 ()").arg(u),
2758 QString ("%1 ()").arg(r),
2759 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2761 emitDataHasChanged(bi);
2762 emitSelectionChanged();
2763 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2770 void VymModel::toggleScroll()
2772 BranchItem *bi=(BranchItem*)getSelectedBranch();
2773 if (bi && bi->isBranchLikeType() )
2775 if (bi->isScrolled())
2776 unscrollBranch (bi);
2780 // saveState & reposition are called in above functions
2783 void VymModel::unscrollChildren()
2785 BranchItem *selbi=getSelectedBranch();
2786 BranchItem *prev=NULL;
2787 BranchItem *cur=selbi;
2790 saveStateChangingPart(
2793 QString ("unscrollChildren ()"),
2794 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2798 if (cur->isScrolled())
2800 cur->toggleScroll();
2801 emitDataHasChanged (cur);
2803 cur=nextBranch (cur,prev,true,selbi);
2810 void VymModel::emitExpandAll()
2812 emit (expandAll() );
2815 void VymModel::emitExpandOneLevel()
2817 emit (expandOneLevel () );
2820 void VymModel::emitCollapseOneLevel()
2822 emit (collapseOneLevel () );
2825 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2827 BranchItem *bi=getSelectedBranch();
2831 if (bi->isActiveStandardFlag(name))
2843 QString("%1 (\"%2\")").arg(u).arg(name),
2845 QString("%1 (\"%2\")").arg(r).arg(name),
2846 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2847 bi->toggleStandardFlag (name, master);
2849 emitSelectionChanged();
2853 void VymModel::addFloatImage (const QPixmap &img)
2855 BranchItem *selbi=getSelectedBranch();
2858 ImageItem *ii=createImage (selbi);
2860 ii->setOriginalFilename("No original filename (image added by dropevent)");
2861 QString s=getSelectString(selbi);
2862 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2863 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2865 // FIXME-3 VM needed? scene()->update();
2870 void VymModel::colorBranch (QColor c)
2872 BranchItem *selbi=getSelectedBranch();
2877 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2879 QString ("colorBranch (\"%1\")").arg(c.name()),
2880 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2882 selbi->setHeadingColor(c); // color branch
2887 void VymModel::colorSubtree (QColor c)
2889 BranchItem *selbi=getSelectedBranch();
2892 saveStateChangingPart(
2895 QString ("colorSubtree (\"%1\")").arg(c.name()),
2896 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2898 BranchItem *prev=NULL;
2899 BranchItem *cur=selbi;
2902 cur->setHeadingColor(c); // color links, color children
2903 cur=nextBranch (cur,prev,true,selbi);
2909 QColor VymModel::getCurrentHeadingColor()
2911 BranchItem *selbi=getSelectedBranch();
2912 if (selbi) return selbi->getHeadingColor();
2914 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2920 void VymModel::editURL()
2922 TreeItem *selti=getSelectedItem();
2926 QString text = QInputDialog::getText(
2927 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2928 selti->getURL(), &ok, NULL);
2930 // user entered something and pressed OK
2935 void VymModel::editLocalURL()
2937 TreeItem *selti=getSelectedItem();
2940 QStringList filters;
2941 filters <<"All files (*)";
2942 filters << tr("Text","Filedialog") + " (*.txt)";
2943 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2944 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2945 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2946 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2947 fd->setFilters (filters);
2948 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2949 fd->setDirectory (lastFileDir);
2950 if (! selti->getVymLink().isEmpty() )
2951 fd->selectFile( selti->getURL() );
2954 if ( fd->exec() == QDialog::Accepted )
2956 lastFileDir=QDir (fd->directory().path());
2957 setURL (fd->selectedFile() );
2963 void VymModel::editHeading2URL()
2965 TreeItem *selti=getSelectedItem();
2967 setURL (selti->getHeading());
2970 void VymModel::editBugzilla2URL()
2972 TreeItem *selti=getSelectedItem();
2975 QString h=selti->getHeading();
2976 QRegExp rx("^(\\d+)");
2977 if (rx.indexIn(h) !=-1)
2978 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2982 void VymModel::getBugzillaData()
2984 BranchItem *selbi=getSelectedBranch();
2987 QString url=selbi->getURL();
2990 QRegExp rx("(\\d+)");
2991 if (rx.indexIn(url) !=-1)
2993 QString bugID=rx.cap(1);
2994 qDebug()<< "VM::getBugzillaData bug="<<bugID;
2996 new BugAgent (selbi,bugID);
3002 void VymModel::editFATE2URL()
3004 TreeItem *selti=getSelectedItem();
3007 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
3010 "setURL (\""+selti->getURL()+"\")",
3012 "setURL (\""+url+"\")",
3013 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
3015 selti->setURL (url);
3016 // FIXME-4 updateActions();
3020 void VymModel::editVymLink()
3022 BranchItem *bi=getSelectedBranch();
3025 QStringList filters;
3026 filters <<"VYM map (*.vym)";
3027 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
3028 fd->setFilters (filters);
3029 fd->setCaption(vymName+" - " +tr("Link to another map"));
3030 fd->setDirectory (lastFileDir);
3031 if (! bi->getVymLink().isEmpty() )
3032 fd->selectFile( bi->getVymLink() );
3036 if ( fd->exec() == QDialog::Accepted )
3038 lastFileDir=QDir (fd->directory().path());
3041 "setVymLink (\""+bi->getVymLink()+"\")",
3043 "setVymLink (\""+fd->selectedFile()+"\")",
3044 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
3046 setVymLink (fd->selectedFile() );
3051 void VymModel::setVymLink (const QString &s)
3053 // Internal function, no saveState needed
3054 TreeItem *selti=getSelectedItem();
3057 selti->setVymLink(s);
3059 emitDataHasChanged (selti);
3060 emitShowSelection();
3064 void VymModel::deleteVymLink()
3066 BranchItem *bi=getSelectedBranch();
3071 "setVymLink (\""+bi->getVymLink()+"\")",
3073 "setVymLink (\"\")",
3074 QString("Unset vymlink of %1").arg(getObjectName(bi))
3076 bi->setVymLink ("" );
3082 QString VymModel::getVymLink()
3084 BranchItem *bi=getSelectedBranch();
3086 return bi->getVymLink();
3092 QStringList VymModel::getVymLinks()
3095 BranchItem *selbi=getSelectedBranch();
3096 BranchItem *cur=selbi;
3097 BranchItem *prev=NULL;
3100 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
3101 cur=nextBranch (cur,prev,true,selbi);
3107 void VymModel::followXLink(int i)
3110 BranchItem *selbi=getSelectedBranch();
3113 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
3114 if (selbi) select (selbi);
3118 void VymModel::editXLink(int i)
3121 BranchItem *selbi=getSelectedBranch();
3124 XLinkItem *xli=selbi->getXLinkNum(i);
3127 EditXLinkDialog dia;
3129 dia.setSelection(selbi);
3130 if (dia.exec() == QDialog::Accepted)
3132 if (dia.useSettingsGlobal() )
3134 setMapDefXLinkColor (xli->getColor() );
3135 setMapDefXLinkWidth (xli->getWidth() );
3137 if (dia.deleteXLink()) deleteItem (xli);
3147 //////////////////////////////////////////////
3149 //////////////////////////////////////////////
3151 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3153 TreeItem* selti=getSelectedItem();
3154 BranchItem *selbi=getSelectedBranch();
3159 QVariant returnValue="";
3161 // Split string s into command and parameters
3162 parser.parseAtom (atom);
3163 QString com=parser.getCommand();
3165 // External commands
3166 /////////////////////////////////////////////////////////////////////
3167 if (com=="addBranch")
3171 parser.setError (Aborted,"Nothing selected");
3172 } else if (! selbi )
3174 parser.setError (Aborted,"Type of selection is not a branch");
3179 if (parser.checkParCount(pl))
3181 if (parser.parCount()==0)
3185 n=parser.parInt (ok,0);
3186 if (ok ) addNewBranch (n);
3190 /////////////////////////////////////////////////////////////////////
3191 } else if (com=="addBranchBefore")
3195 parser.setError (Aborted,"Nothing selected");
3196 } else if (! selbi )
3198 parser.setError (Aborted,"Type of selection is not a branch");
3201 if (parser.parCount()==0)
3203 addNewBranchBefore ();
3206 /////////////////////////////////////////////////////////////////////
3207 } else if (com==QString("addMapCenter"))
3209 if (parser.checkParCount(2))
3211 x=parser.parDouble (ok,0);
3214 y=parser.parDouble (ok,1);
3215 if (ok) addMapCenter (QPointF(x,y));
3218 /////////////////////////////////////////////////////////////////////
3219 } else if (com==QString("addMapReplace"))
3223 parser.setError (Aborted,"Nothing selected");
3224 } else if (! selbi )
3226 parser.setError (Aborted,"Type of selection is not a branch");
3227 } else if (parser.checkParCount(1))
3229 //s=parser.parString (ok,0); // selection
3230 t=parser.parString (ok,0); // path to map
3231 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3232 addMapReplaceInt(getSelectString(selbi),t);
3234 /////////////////////////////////////////////////////////////////////
3235 } else if (com==QString("addMapInsert"))
3237 if (parser.parCount()==2)
3242 parser.setError (Aborted,"Nothing selected");
3243 } else if (! selbi )
3245 parser.setError (Aborted,"Type of selection is not a branch");
3248 t=parser.parString (ok,0); // path to map
3249 n=parser.parInt(ok,1); // position
3250 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3251 addMapInsertInt(t,n);
3253 } else if (parser.parCount()==1)
3255 t=parser.parString (ok,0); // path to map
3256 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3259 parser.setError (Aborted,"Wrong number of parameters");
3260 /////////////////////////////////////////////////////////////////////
3261 } else if (com==QString("addXLink"))
3263 if (parser.parCount()>1)
3265 s=parser.parString (ok,0); // begin
3266 t=parser.parString (ok,1); // end
3267 BranchItem *begin=(BranchItem*)findBySelectString(s);
3268 BranchItem *end=(BranchItem*)findBySelectString(t);
3271 if (begin->isBranchLikeType() && end->isBranchLikeType())
3273 XLinkItem *xl=createXLink (begin,true);
3279 parser.setError (Aborted,"Failed to create xLink");
3282 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3285 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3287 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3288 /////////////////////////////////////////////////////////////////////
3289 } else if (com=="clearFlags")
3293 parser.setError (Aborted,"Nothing selected");
3294 } else if (! selbi )
3296 parser.setError (Aborted,"Type of selection is not a branch");
3297 } else if (parser.checkParCount(0))
3299 selbi->deactivateAllStandardFlags(); //FIXME-2 this probably should emitDataChanged and also setChanged. Similar all other direct changes should be done...
3301 /////////////////////////////////////////////////////////////////////
3302 } else if (com=="colorBranch")
3306 parser.setError (Aborted,"Nothing selected");
3307 } else if (! selbi )
3309 parser.setError (Aborted,"Type of selection is not a branch");
3310 } else if (parser.checkParCount(1))
3312 QColor c=parser.parColor (ok,0);
3313 if (ok) colorBranch (c);
3315 /////////////////////////////////////////////////////////////////////
3316 } else if (com=="colorSubtree")
3320 parser.setError (Aborted,"Nothing selected");
3321 } else if (! selbi )
3323 parser.setError (Aborted,"Type of selection is not a branch");
3324 } else if (parser.checkParCount(1))
3326 QColor c=parser.parColor (ok,0);
3327 if (ok) colorSubtree (c);
3329 /////////////////////////////////////////////////////////////////////
3330 } else if (com=="copy")
3334 parser.setError (Aborted,"Nothing selected");
3335 } else if ( selectionType()!=TreeItem::Branch &&
3336 selectionType()!=TreeItem::MapCenter &&
3337 selectionType()!=TreeItem::Image )
3339 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3340 } else if (parser.checkParCount(0))
3344 /////////////////////////////////////////////////////////////////////
3345 } else if (com=="cut")
3349 parser.setError (Aborted,"Nothing selected");
3350 } else if ( selectionType()!=TreeItem::Branch &&
3351 selectionType()!=TreeItem::MapCenter &&
3352 selectionType()!=TreeItem::Image )
3354 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3355 } else if (parser.checkParCount(0))
3359 /////////////////////////////////////////////////////////////////////
3360 } else if (com=="delete")
3364 parser.setError (Aborted,"Nothing selected");
3366 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3368 parser.setError (Aborted,"Type of selection is wrong.");
3371 else if (parser.checkParCount(0))
3375 /////////////////////////////////////////////////////////////////////
3376 } else if (com=="deleteKeepChildren")
3380 parser.setError (Aborted,"Nothing selected");
3381 } else if (! selbi )
3383 parser.setError (Aborted,"Type of selection is not a branch");
3384 } else if (parser.checkParCount(0))
3386 deleteKeepChildren();
3388 /////////////////////////////////////////////////////////////////////
3389 } else if (com=="deleteChildren")
3393 parser.setError (Aborted,"Nothing selected");
3396 parser.setError (Aborted,"Type of selection is not a branch");
3397 } else if (parser.checkParCount(0))
3401 /////////////////////////////////////////////////////////////////////
3402 } else if (com=="exportAO")
3406 if (parser.parCount()>=1)
3407 // Hey, we even have a filename
3408 fname=parser.parString(ok,0);
3411 parser.setError (Aborted,"Could not read filename");
3414 exportAO (fname,false);
3416 /////////////////////////////////////////////////////////////////////
3417 } else if (com=="exportASCII")
3421 if (parser.parCount()>=1)
3422 // Hey, we even have a filename
3423 fname=parser.parString(ok,0);
3426 parser.setError (Aborted,"Could not read filename");
3429 exportASCII (fname,false);
3431 /////////////////////////////////////////////////////////////////////
3432 } else if (com=="exportImage")
3436 if (parser.parCount()>=2)
3437 // Hey, we even have a filename
3438 fname=parser.parString(ok,0);
3441 parser.setError (Aborted,"Could not read filename");
3444 QString format="PNG";
3445 if (parser.parCount()>=2)
3447 format=parser.parString(ok,1);
3449 exportImage (fname,false,format);
3451 /////////////////////////////////////////////////////////////////////
3452 } else if (com=="exportXHTML")
3456 if (parser.parCount()>=2)
3457 // Hey, we even have a filename
3458 fname=parser.parString(ok,1);
3461 parser.setError (Aborted,"Could not read filename");
3464 exportXHTML (fname,false);
3466 /////////////////////////////////////////////////////////////////////
3467 } else if (com=="exportXML")
3471 if (parser.parCount()>=2)
3472 // Hey, we even have a filename
3473 fname=parser.parString(ok,1);
3476 parser.setError (Aborted,"Could not read filename");
3479 exportXML (fname,false);
3481 /////////////////////////////////////////////////////////////////////
3482 } else if (com=="getHeading")
3486 parser.setError (Aborted,"Nothing selected");
3487 } else if (parser.checkParCount(0))
3488 returnValue=selti->getHeading();
3489 /////////////////////////////////////////////////////////////////////
3490 } else if (com=="importDir")
3494 parser.setError (Aborted,"Nothing selected");
3495 } else if (! selbi )
3497 parser.setError (Aborted,"Type of selection is not a branch");
3498 } else if (parser.checkParCount(1))
3500 s=parser.parString(ok,0);
3501 if (ok) importDirInt(s);
3503 /////////////////////////////////////////////////////////////////////
3504 } else if (com=="relinkTo")
3508 parser.setError (Aborted,"Nothing selected");
3511 if (parser.checkParCount(4))
3513 // 0 selectstring of parent
3514 // 1 num in parent (for branches)
3515 // 2,3 x,y of mainbranch or mapcenter
3516 s=parser.parString(ok,0);
3517 TreeItem *dst=findBySelectString (s);
3520 if (dst->getType()==TreeItem::Branch)
3522 // Get number in parent
3523 n=parser.parInt (ok,1);
3526 relinkBranch (selbi,(BranchItem*)dst,n);
3527 emitSelectionChanged();
3529 } else if (dst->getType()==TreeItem::MapCenter)
3531 relinkBranch (selbi,(BranchItem*)dst);
3532 // Get coordinates of mainbranch
3533 x=parser.parDouble(ok,2);
3536 y=parser.parDouble(ok,3);
3539 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3540 emitSelectionChanged();
3546 } else if ( selti->getType() == TreeItem::Image)
3548 if (parser.checkParCount(1))
3550 // 0 selectstring of parent
3551 s=parser.parString(ok,0);
3552 TreeItem *dst=findBySelectString (s);
3555 if (dst->isBranchLikeType())
3556 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3558 parser.setError (Aborted,"Destination is not a branch");
3561 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3562 /////////////////////////////////////////////////////////////////////
3563 } else if (com=="loadImage")
3567 parser.setError (Aborted,"Nothing selected");
3568 } else if (! selbi )
3570 parser.setError (Aborted,"Type of selection is not a branch");
3571 } else if (parser.checkParCount(1))
3573 s=parser.parString(ok,0);
3574 if (ok) loadFloatImageInt (selbi,s);
3576 /////////////////////////////////////////////////////////////////////
3577 } else if (com=="loadNote")
3581 parser.setError (Aborted,"Nothing selected");
3582 } else if (! selbi )
3584 parser.setError (Aborted,"Type of selection is not a branch");
3585 } else if (parser.checkParCount(1))
3587 s=parser.parString(ok,0);
3588 if (ok) loadNote (s);
3590 /////////////////////////////////////////////////////////////////////
3591 } else if (com=="moveUp")
3595 parser.setError (Aborted,"Nothing selected");
3596 } else if (! selbi )
3598 parser.setError (Aborted,"Type of selection is not a branch");
3599 } else if (parser.checkParCount(0))
3603 /////////////////////////////////////////////////////////////////////
3604 } else if (com=="moveDown")
3608 parser.setError (Aborted,"Nothing selected");
3609 } else if (! selbi )
3611 parser.setError (Aborted,"Type of selection is not a branch");
3612 } else if (parser.checkParCount(0))
3616 /////////////////////////////////////////////////////////////////////
3617 } else if (com=="move")
3621 parser.setError (Aborted,"Nothing selected");
3622 } else if ( selectionType()!=TreeItem::Branch &&
3623 selectionType()!=TreeItem::MapCenter &&
3624 selectionType()!=TreeItem::Image )
3626 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3627 } else if (parser.checkParCount(2))
3629 x=parser.parDouble (ok,0);
3632 y=parser.parDouble (ok,1);
3636 /////////////////////////////////////////////////////////////////////
3637 } else if (com=="moveRel")
3641 parser.setError (Aborted,"Nothing selected");
3642 } else if ( selectionType()!=TreeItem::Branch &&
3643 selectionType()!=TreeItem::MapCenter &&
3644 selectionType()!=TreeItem::Image )
3646 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3647 } else if (parser.checkParCount(2))
3649 x=parser.parDouble (ok,0);
3652 y=parser.parDouble (ok,1);
3653 if (ok) moveRel (x,y);
3656 /////////////////////////////////////////////////////////////////////
3657 } else if (com=="nop")
3659 /////////////////////////////////////////////////////////////////////
3660 } else if (com=="paste")
3664 parser.setError (Aborted,"Nothing selected");
3665 } else if (! selbi )
3667 parser.setError (Aborted,"Type of selection is not a branch");
3668 } else if (parser.checkParCount(1))
3670 n=parser.parInt (ok,0);
3671 if (ok) pasteNoSave(n);
3673 /////////////////////////////////////////////////////////////////////
3674 } else if (com=="qa")
3678 parser.setError (Aborted,"Nothing selected");
3679 } else if (! selbi )
3681 parser.setError (Aborted,"Type of selection is not a branch");
3682 } else if (parser.checkParCount(4))
3685 c=parser.parString (ok,0);
3688 parser.setError (Aborted,"No comment given");
3691 s=parser.parString (ok,1);
3694 parser.setError (Aborted,"First parameter is not a string");
3697 t=parser.parString (ok,2);
3700 parser.setError (Aborted,"Condition is not a string");
3703 u=parser.parString (ok,3);
3706 parser.setError (Aborted,"Third parameter is not a string");
3711 parser.setError (Aborted,"Unknown type: "+s);
3716 parser.setError (Aborted,"Unknown operator: "+t);
3721 parser.setError (Aborted,"Type of selection is not a branch");
3724 if (selbi->getHeading() == u)
3726 cout << "PASSED: " << qPrintable (c) << endl;
3729 cout << "FAILED: " << qPrintable (c) << endl;
3739 /////////////////////////////////////////////////////////////////////
3740 } else if (com=="saveImage")
3742 ImageItem *ii=getSelectedImage();
3745 parser.setError (Aborted,"No image selected");
3746 } else if (parser.checkParCount(2))
3748 s=parser.parString(ok,0);
3751 t=parser.parString(ok,1);
3752 if (ok) saveFloatImageInt (ii,t,s);
3755 /////////////////////////////////////////////////////////////////////
3756 } else if (com=="saveNote")
3760 parser.setError (Aborted,"Nothing selected");
3761 } else if (! selbi )
3763 parser.setError (Aborted,"Type of selection is not a branch");
3764 } else if (parser.checkParCount(1))
3766 s=parser.parString(ok,0);
3767 if (ok) saveNote (s);
3769 /////////////////////////////////////////////////////////////////////
3770 } else if (com=="scroll")
3774 parser.setError (Aborted,"Nothing selected");
3775 } else if (! selbi )
3777 parser.setError (Aborted,"Type of selection is not a branch");
3778 } else if (parser.checkParCount(0))
3780 if (!scrollBranch (selbi))
3781 parser.setError (Aborted,"Could not scroll branch");
3783 /////////////////////////////////////////////////////////////////////
3784 } else if (com=="select")
3786 if (parser.checkParCount(1))
3788 s=parser.parString(ok,0);
3791 /////////////////////////////////////////////////////////////////////
3792 } else if (com=="selectLastBranch")
3796 parser.setError (Aborted,"Nothing selected");
3797 } else if (! selbi )
3799 parser.setError (Aborted,"Type of selection is not a branch");
3800 } else if (parser.checkParCount(0))
3802 BranchItem *bi=selbi->getLastBranch();
3804 parser.setError (Aborted,"Could not select last branch");
3805 select (bi); // FIXME-3 was selectInt
3808 /////////////////////////////////////////////////////////////////////
3809 } else /* FIXME-2 if (com=="selectLastImage")
3813 parser.setError (Aborted,"Nothing selected");
3814 } else if (! selbi )
3816 parser.setError (Aborted,"Type of selection is not a branch");
3817 } else if (parser.checkParCount(0))
3819 FloatImageObj *fio=selb->getLastFloatImage();
3821 parser.setError (Aborted,"Could not select last image");
3822 select (fio); // FIXME-3 was selectInt
3825 /////////////////////////////////////////////////////////////////////
3826 } else */ if (com=="selectLatestAdded")
3828 if (!latestAddedItem)
3830 parser.setError (Aborted,"No latest added object");
3833 if (!select (latestAddedItem))
3834 parser.setError (Aborted,"Could not select latest added object ");
3836 /////////////////////////////////////////////////////////////////////
3837 } else if (com=="setFlag")
3841 parser.setError (Aborted,"Nothing selected");
3842 } else if (! selbi )
3844 parser.setError (Aborted,"Type of selection is not a branch");
3845 } else if (parser.checkParCount(1))
3847 s=parser.parString(ok,0);
3849 selbi->activateStandardFlag(s);
3851 /////////////////////////////////////////////////////////////////////
3852 } else if (com=="setFrameType")
3854 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3856 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3858 else if (parser.checkParCount(1))
3860 s=parser.parString(ok,0);
3861 if (ok) setFrameType (s);
3863 /////////////////////////////////////////////////////////////////////
3864 } else if (com=="setFramePenColor")
3866 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3868 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3870 else if (parser.checkParCount(1))
3872 QColor c=parser.parColor(ok,0);
3873 if (ok) setFramePenColor (c);
3875 /////////////////////////////////////////////////////////////////////
3876 } else if (com=="setFrameBrushColor")
3878 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3880 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3882 else if (parser.checkParCount(1))
3884 QColor c=parser.parColor(ok,0);
3885 if (ok) setFrameBrushColor (c);
3887 /////////////////////////////////////////////////////////////////////
3888 } else if (com=="setFramePadding")
3890 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3892 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3894 else if (parser.checkParCount(1))
3896 n=parser.parInt(ok,0);
3897 if (ok) setFramePadding(n);
3899 /////////////////////////////////////////////////////////////////////
3900 } else if (com=="setFrameBorderWidth")
3902 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3904 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3906 else if (parser.checkParCount(1))
3908 n=parser.parInt(ok,0);
3909 if (ok) setFrameBorderWidth (n);
3911 /////////////////////////////////////////////////////////////////////
3912 /* FIXME-2 else if (com=="setFrameType")
3916 parser.setError (Aborted,"Nothing selected");
3919 parser.setError (Aborted,"Type of selection is not a branch");
3920 } else if (parser.checkParCount(1))
3922 s=parser.parString(ok,0);
3926 /////////////////////////////////////////////////////////////////////
3928 /////////////////////////////////////////////////////////////////////
3929 } else if (com=="setHeading")
3933 parser.setError (Aborted,"Nothing selected");
3934 } else if (! selbi )
3936 parser.setError (Aborted,"Type of selection is not a branch");
3937 } else if (parser.checkParCount(1))
3939 s=parser.parString (ok,0);
3943 /////////////////////////////////////////////////////////////////////
3944 } else if (com=="setHideExport")
3948 parser.setError (Aborted,"Nothing selected");
3949 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3951 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3952 } else if (parser.checkParCount(1))
3954 b=parser.parBool(ok,0);
3955 if (ok) setHideExport (b);
3957 /////////////////////////////////////////////////////////////////////
3958 } else if (com=="setIncludeImagesHorizontally")
3962 parser.setError (Aborted,"Nothing selected");
3965 parser.setError (Aborted,"Type of selection is not a branch");
3966 } else if (parser.checkParCount(1))
3968 b=parser.parBool(ok,0);
3969 if (ok) setIncludeImagesHor(b);
3971 /////////////////////////////////////////////////////////////////////
3972 } else if (com=="setIncludeImagesVertically")
3976 parser.setError (Aborted,"Nothing selected");
3979 parser.setError (Aborted,"Type of selection is not a branch");
3980 } else if (parser.checkParCount(1))
3982 b=parser.parBool(ok,0);
3983 if (ok) setIncludeImagesVer(b);
3985 /////////////////////////////////////////////////////////////////////
3986 } else if (com=="setHideLinkUnselected")
3990 parser.setError (Aborted,"Nothing selected");
3991 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3993 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3994 } else if (parser.checkParCount(1))
3996 b=parser.parBool(ok,0);
3997 if (ok) setHideLinkUnselected(b);
3999 /////////////////////////////////////////////////////////////////////
4000 } else if (com=="setMapAuthor")
4002 if (parser.checkParCount(1))
4004 s=parser.parString(ok,0);
4005 if (ok) setAuthor (s);
4007 /////////////////////////////////////////////////////////////////////
4008 } else if (com=="setMapComment")
4010 if (parser.checkParCount(1))
4012 s=parser.parString(ok,0);
4013 if (ok) setComment(s);
4015 /////////////////////////////////////////////////////////////////////
4016 } else if (com=="setMapBackgroundColor")
4020 parser.setError (Aborted,"Nothing selected");
4021 } else if (! selbi )
4023 parser.setError (Aborted,"Type of selection is not a branch");
4024 } else if (parser.checkParCount(1))
4026 QColor c=parser.parColor (ok,0);
4027 if (ok) setMapBackgroundColor (c);
4029 /////////////////////////////////////////////////////////////////////
4030 } else if (com=="setMapDefLinkColor")
4034 parser.setError (Aborted,"Nothing selected");
4035 } else if (! selbi )
4037 parser.setError (Aborted,"Type of selection is not a branch");
4038 } else if (parser.checkParCount(1))
4040 QColor c=parser.parColor (ok,0);
4041 if (ok) setMapDefLinkColor (c);
4043 /////////////////////////////////////////////////////////////////////
4044 } else if (com=="setMapLinkStyle")
4046 if (parser.checkParCount(1))
4048 s=parser.parString (ok,0);
4049 if (ok) setMapLinkStyle(s);
4051 /////////////////////////////////////////////////////////////////////
4052 } else if (com=="setNote")
4056 parser.setError (Aborted,"Nothing selected");
4057 } else if (! selbi )
4059 parser.setError (Aborted,"Type of selection is not a branch");
4060 } else if (parser.checkParCount(1))
4062 s=parser.parString (ok,0);
4066 /////////////////////////////////////////////////////////////////////
4067 } else if (com=="setSelectionColor")
4069 if (parser.checkParCount(1))
4071 QColor c=parser.parColor (ok,0);
4072 if (ok) setSelectionColorInt (c);
4074 /////////////////////////////////////////////////////////////////////
4075 } else if (com=="setURL")
4079 parser.setError (Aborted,"Nothing selected");
4080 } else if (! selbi )
4082 parser.setError (Aborted,"Type of selection is not a branch");
4083 } else if (parser.checkParCount(1))
4085 s=parser.parString (ok,0);
4088 /////////////////////////////////////////////////////////////////////
4089 } else if (com=="setVymLink")
4093 parser.setError (Aborted,"Nothing selected");
4094 } else if (! selbi )
4096 parser.setError (Aborted,"Type of selection is not a branch");
4097 } else if (parser.checkParCount(1))
4099 s=parser.parString (ok,0);
4100 if (ok) setVymLink(s);
4102 } else if (com=="sortChildren")
4106 parser.setError (Aborted,"Nothing selected");
4107 } else if (! selbi )
4109 parser.setError (Aborted,"Type of selection is not a branch");
4110 } else if (parser.checkParCount(0))
4113 } else if (parser.checkParCount(1))
4115 b=parser.parBool(ok,0);
4116 if (ok) sortChildren(b);
4118 /////////////////////////////////////////////////////////////////////
4119 } else if (com=="toggleFlag")
4123 parser.setError (Aborted,"Nothing selected");
4124 } else if (! selbi )
4126 parser.setError (Aborted,"Type of selection is not a branch");
4127 } else if (parser.checkParCount(1))
4129 s=parser.parString(ok,0);
4131 selbi->toggleStandardFlag(s);
4133 /////////////////////////////////////////////////////////////////////
4134 } else if (com=="unscroll")
4138 parser.setError (Aborted,"Nothing selected");
4139 } else if (! selbi )
4141 parser.setError (Aborted,"Type of selection is not a branch");
4142 } else if (parser.checkParCount(0))
4144 if (!unscrollBranch (selbi))
4145 parser.setError (Aborted,"Could not unscroll branch");
4147 /////////////////////////////////////////////////////////////////////
4148 } else if (com=="unscrollChildren")
4152 parser.setError (Aborted,"Nothing selected");
4153 } else if (! selbi )
4155 parser.setError (Aborted,"Type of selection is not a branch");
4156 } else if (parser.checkParCount(0))
4158 unscrollChildren ();
4160 /////////////////////////////////////////////////////////////////////
4161 } else if (com=="unsetFlag")
4165 parser.setError (Aborted,"Nothing selected");
4166 } else if (! selbi )
4168 parser.setError (Aborted,"Type of selection is not a branch");
4169 } else if (parser.checkParCount(1))
4171 s=parser.parString(ok,0);
4173 selbi->deactivateStandardFlag(s);
4176 parser.setError (Aborted,"Unknown command");
4179 if (parser.errorLevel()==NoError)
4187 // TODO Error handling
4188 qWarning("VymModel::parseAtom: Error!");
4190 qWarning(parser.errorMessage());
4192 errorMsg=parser.errorMessage();
4193 returnValue=errorMsg;
4198 QVariant VymModel::runScript (const QString &script)
4200 parser.setScript (script);
4205 while (parser.next() && noErr)
4207 r=parseAtom(parser.getAtom(),noErr,errMsg);
4208 if (!noErr) //FIXME-3 need dialog box here
4209 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4214 void VymModel::setExportMode (bool b)
4216 // should be called before and after exports
4217 // depending on the settings
4218 if (b && settings.value("/export/useHideExport","true")=="true")
4219 setHideTmpMode (TreeItem::HideExport);
4221 setHideTmpMode (TreeItem::HideNone);
4224 void VymModel::exportImage(QString fname, bool askName, QString format)
4228 fname=getMapName()+".png";
4235 QFileDialog *fd=new QFileDialog (NULL);
4236 fd->setCaption (tr("Export map as image"));
4237 fd->setDirectory (lastImageDir);
4238 fd->setFileMode(QFileDialog::AnyFile);
4239 fd->setFilters (imageIO.getFilters() );
4242 fl=fd->selectedFiles();
4244 format=imageIO.getType(fd->selectedFilter());
4248 setExportMode (true);
4249 mapEditor->getScene()->update(); // FIXME-3 check this...
4250 QImage img (mapEditor->getImage()); //FIXME-3 calls getTotalBBox, but also in ExportHTML::doExport()
4251 img.save(fname, format);
4252 setExportMode (false);
4256 void VymModel::exportXML(QString dir, bool askForName)
4260 dir=browseDirectory(NULL,tr("Export XML to directory"));
4261 if (dir =="" && !reallyWriteDirectory(dir) )
4265 // Hide stuff during export, if settings want this
4266 setExportMode (true);
4268 // Create subdirectories
4271 // write to directory //FIXME-4 check totalBBox here...
4272 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4275 file.setName ( dir + "/"+mapName+".xml");
4276 if ( !file.open( QIODevice::WriteOnly ) )
4278 // This should neverever happen
4279 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4283 // Write it finally, and write in UTF8, no matter what
4284 QTextStream ts( &file );
4285 ts.setEncoding (QTextStream::UnicodeUTF8);
4289 // Now write image, too
4290 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4292 setExportMode (false);
4295 void VymModel::exportAO (QString fname,bool askName)
4300 ex.setFile (mapName+".txt");
4306 //ex.addFilter ("TXT (*.txt)");
4307 ex.setDir(lastImageDir);
4308 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4313 setExportMode(true);
4315 setExportMode(false);
4319 void VymModel::exportASCII(QString fname,bool askName)
4324 ex.setFile (mapName+".txt");
4330 //ex.addFilter ("TXT (*.txt)");
4331 ex.setDir(lastImageDir);
4332 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4337 setExportMode(true);
4339 setExportMode(false);
4343 void VymModel::exportHTML (const QString &dir, bool useDialog)
4345 ExportHTML ex (this);
4347 ex.doExport(useDialog);
4350 void VymModel::exportXHTML (const QString &dir, bool askForName)
4352 ExportXHTMLDialog dia(NULL);
4353 dia.setFilePath (filePath );
4354 dia.setMapName (mapName );
4356 if (dir!="") dia.setDir (dir);
4362 if (dia.exec()!=QDialog::Accepted)
4366 QDir d (dia.getDir());
4367 // Check, if warnings should be used before overwriting
4368 // the output directory
4369 if (d.exists() && d.count()>0)
4372 warn.showCancelButton (true);
4373 warn.setText(QString(
4374 "The directory %1 is not empty.\n"
4375 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4376 warn.setCaption("Warning: Directory not empty");
4377 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4379 if (warn.exec()!=QDialog::Accepted) ok=false;
4386 exportXML (dia.getDir(),false );
4387 dia.doExport(mapName );
4388 //if (dia.hasChanged()) setChanged();
4392 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4397 if (ex.setConfigFile(cf))
4399 setExportMode (true);
4400 ex.exportPresentation();
4401 setExportMode (false);
4408 //////////////////////////////////////////////
4410 //////////////////////////////////////////////
4412 void VymModel::registerEditor(QWidget *me)
4414 mapEditor=(MapEditor*)me;
4417 void VymModel::unregisterEditor(QWidget *)
4422 void VymModel::setMapZoomFactor (const double &d)
4427 void VymModel::setContextPos(QPointF p)
4432 void VymModel::unsetContextPos()
4434 contextPos=QPointF();
4437 void VymModel::updateNoteFlag()
4439 TreeItem *selti=getSelectedItem();
4448 if (textEditor->isEmpty())
4451 selti->setNote (textEditor->getText());
4452 emitDataHasChanged(selti);
4456 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4458 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4459 if (blockReposition) return;
4461 for (int i=0;i<rootItem->branchCount(); i++)
4462 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4463 //emitSelectionChanged();
4467 void VymModel::setMapLinkStyle (const QString & s)
4472 case LinkableMapObj::Line :
4475 case LinkableMapObj::Parabel:
4476 snow="StyleParabel";
4478 case LinkableMapObj::PolyLine:
4479 snow="StylePolyLine";
4481 case LinkableMapObj::PolyParabel:
4482 snow="StylePolyParabel";
4485 snow="UndefinedStyle";
4490 QString("setMapLinkStyle (\"%1\")").arg(s),
4491 QString("setMapLinkStyle (\"%1\")").arg(snow),
4492 QString("Set map link style (\"%1\")").arg(s)
4496 linkstyle=LinkableMapObj::Line;
4497 else if (s=="StyleParabel")
4498 linkstyle=LinkableMapObj::Parabel;
4499 else if (s=="StylePolyLine")
4500 linkstyle=LinkableMapObj::PolyLine;
4501 else if (s=="StylePolyParabel")
4502 linkstyle=LinkableMapObj::PolyParabel;
4504 linkstyle=LinkableMapObj::UndefinedStyle;
4506 BranchItem *cur=NULL;
4507 BranchItem *prev=NULL;
4509 nextBranch (cur,prev);
4512 bo=(BranchObj*)(cur->getLMO() );
4513 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4514 cur=nextBranch(cur,prev);
4519 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4524 uint VymModel::getID()
4529 void VymModel::setMapDefLinkColor(QColor col)
4531 if ( !col.isValid() ) return;
4533 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4534 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4535 QString("Set map link color to %1").arg(col.name())
4539 BranchItem *cur=NULL;
4540 BranchItem *prev=NULL;
4542 cur=nextBranch(cur,prev);
4545 bo=(BranchObj*)(cur->getLMO() );
4547 nextBranch(cur,prev);
4552 void VymModel::setMapLinkColorHintInt()
4554 // called from setMapLinkColorHint(lch) or at end of parse
4555 BranchItem *cur=NULL;
4556 BranchItem *prev=NULL;
4558 cur=nextBranch(cur,prev);
4561 bo=(BranchObj*)(cur->getLMO() );
4563 cur=nextBranch(cur,prev);
4567 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4570 setMapLinkColorHintInt();
4573 void VymModel::toggleMapLinkColorHint()
4575 if (linkcolorhint==LinkableMapObj::HeadingColor)
4576 linkcolorhint=LinkableMapObj::DefaultColor;
4578 linkcolorhint=LinkableMapObj::HeadingColor;
4579 BranchItem *cur=NULL;
4580 BranchItem *prev=NULL;
4582 cur=nextBranch(cur,prev);
4585 bo=(BranchObj*)(cur->getLMO() );
4587 nextBranch(cur,prev);
4591 void VymModel::selectMapBackgroundImage () // FIXME-3 for using background image: view.setCacheMode(QGraphicsView::CacheBackground); Also this belongs into ME
4593 Q3FileDialog *fd=new Q3FileDialog( NULL);
4594 fd->setMode (Q3FileDialog::ExistingFile);
4595 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4596 ImagePreview *p =new ImagePreview (fd);
4597 fd->setContentsPreviewEnabled( TRUE );
4598 fd->setContentsPreview( p, p );
4599 fd->setPreviewMode( Q3FileDialog::Contents );
4600 fd->setCaption(vymName+" - " +tr("Load background image"));
4601 fd->setDir (lastImageDir);
4604 if ( fd->exec() == QDialog::Accepted )
4606 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4607 lastImageDir=QDir (fd->dirPath());
4608 setMapBackgroundImage (fd->selectedFile());
4612 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4614 QColor oldcol=mapScene->backgroundBrush().color();
4618 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4620 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4621 QString("Set background color of map to %1").arg(col.name()));
4624 brush.setTextureImage (QPixmap (fn));
4625 mapScene->setBackgroundBrush(brush);
4628 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4630 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4631 if ( !col.isValid() ) return;
4632 setMapBackgroundColor( col );
4636 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4638 QColor oldcol=mapScene->backgroundBrush().color();
4640 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4641 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4642 QString("Set background color of map to %1").arg(col.name()));
4643 mapScene->setBackgroundBrush(col);
4646 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4648 return mapScene->backgroundBrush().color();
4652 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4654 return linkcolorhint;
4657 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4659 return defLinkColor;
4662 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4667 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4669 return defXLinkColor;
4672 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4677 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4679 return defXLinkWidth;
4682 void VymModel::move(const double &x, const double &y)
4685 MapItem *seli = (MapItem*)getSelectedItem();
4686 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4688 LinkableMapObj *lmo=seli->getLMO();
4691 QPointF ap(lmo->getAbsPos());
4695 QString ps=qpointFToString(ap);
4696 QString s=getSelectString(seli);
4699 s, "move "+qpointFToString(to),
4700 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4703 emitSelectionChanged();
4709 void VymModel::moveRel (const double &x, const double &y)
4712 MapItem *seli = (MapItem*)getSelectedItem();
4713 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4715 LinkableMapObj *lmo=seli->getLMO();
4718 QPointF rp(lmo->getRelPos());
4722 QString ps=qpointFToString (lmo->getRelPos());
4723 QString s=getSelectString(seli);
4726 s, "moveRel "+qpointFToString(to),
4727 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4728 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4730 lmo->updateLinkGeometry();
4731 emitSelectionChanged();
4738 void VymModel::animate()
4740 animationTimer->stop();
4743 while (i<animObjList.size() )
4745 bo=(BranchObj*)animObjList.at(i);
4750 animObjList.removeAt(i);
4757 QItemSelection sel=selModel->selection();
4758 emit (selectionChanged(sel,sel));
4761 if (!animObjList.isEmpty()) animationTimer->start();
4765 void VymModel::startAnimation(BranchObj *bo, const QPointF &v)
4769 if (bo->getUseRelPos())
4770 startAnimation (bo,bo->getRelPos(),bo->getRelPos()+v);
4772 startAnimation (bo,bo->getAbsPos(),bo->getAbsPos()+v);
4775 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4777 if (start==dest) return;
4778 if (bo && bo->getTreeItem()->depth()>=0)
4781 ap.setStart (start);
4783 ap.setTicks (animationTicks);
4784 ap.setAnimated (true);
4785 bo->setAnimation (ap);
4786 if (!animObjList.contains(bo))
4787 animObjList.append( bo );
4788 animationTimer->setSingleShot (true);
4789 animationTimer->start(animationInterval);
4793 void VymModel::stopAnimation (MapObj *mo)
4795 int i=animObjList.indexOf(mo);
4797 animObjList.removeAt (i);
4800 void VymModel::sendSelection()
4802 if (netstate!=Server) return;
4803 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4806 void VymModel::newServer()
4810 tcpServer = new QTcpServer(this);
4811 if (!tcpServer->listen(QHostAddress::Any,port)) {
4812 QMessageBox::critical(NULL, "vym server",
4813 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4814 //FIXME-3 needed? we are no widget any longer... close();
4817 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4819 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4822 void VymModel::connectToServer()
4825 server="salam.suse.de";
4827 clientSocket = new QTcpSocket (this);
4828 clientSocket->abort();
4829 clientSocket->connectToHost(server ,port);
4830 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4831 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4832 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4834 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4839 void VymModel::newClient()
4841 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4842 connect(newClient, SIGNAL(disconnected()),
4843 newClient, SLOT(deleteLater()));
4845 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4847 clientList.append (newClient);
4851 void VymModel::sendData(const QString &s)
4853 if (clientList.size()==0) return;
4855 // Create bytearray to send
4857 QDataStream out(&block, QIODevice::WriteOnly);
4858 out.setVersion(QDataStream::Qt_4_0);
4860 // Reserve some space for blocksize
4863 // Write sendCounter
4864 out << sendCounter++;
4869 // Go back and write blocksize so far
4870 out.device()->seek(0);
4871 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4875 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4877 for (int i=0; i<clientList.size(); ++i)
4879 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4880 clientList.at(i)->write (block);
4884 void VymModel::readData ()
4886 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4889 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4893 QDataStream in(clientSocket);
4894 in.setVersion(QDataStream::Qt_4_0);
4902 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4905 parseAtom (t,noErr,errMsg);
4911 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4913 switch (socketError) {
4914 case QAbstractSocket::RemoteHostClosedError:
4916 case QAbstractSocket::HostNotFoundError:
4917 QMessageBox::information(NULL, vymName +" Network client",
4918 "The host was not found. Please check the "
4919 "host name and port settings.");
4921 case QAbstractSocket::ConnectionRefusedError:
4922 QMessageBox::information(NULL, vymName + " Network client",
4923 "The connection was refused by the peer. "
4924 "Make sure the fortune server is running, "
4925 "and check that the host name and port "
4926 "settings are correct.");
4929 QMessageBox::information(NULL, vymName + " Network client",
4930 QString("The following error occurred: %1.")
4931 .arg(clientSocket->errorString()));
4935 /* FIXME-3 Playing with DBUS...
4936 QDBusVariant VymModel::query (const QString &query)
4938 TreeItem *selti=getSelectedItem();
4940 return QDBusVariant (selti->getHeading());
4942 return QDBusVariant ("Nothing selected.");
4946 void VymModel::testslot() //FIXME-3 Playing with DBUS
4948 cout << "VM::testslot called\n";
4951 void VymModel::selectMapSelectionColor()
4953 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4954 setSelectionColor (col);
4957 void VymModel::setSelectionColorInt (QColor col)
4959 if ( !col.isValid() ) return;
4961 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4962 QString("setSelectionColor (%1)").arg(col.name()),
4963 QString("Set color of selection box to %1").arg(col.name())
4966 mapEditor->setSelectionColor (col);
4969 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4971 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4972 //FIXME-3 emitShowSelection();
4976 void VymModel::emitSelectionChanged()
4978 QItemSelection newsel=selModel->selection();
4979 emitSelectionChanged (newsel);
4982 void VymModel::setSelectionColor(QColor col)
4984 if ( !col.isValid() ) return;
4986 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4987 QString("setSelectionColor (%1)").arg(col.name()),
4988 QString("Set color of selection box to %1").arg(col.name())
4990 setSelectionColorInt (col);
4993 QColor VymModel::getSelectionColor()
4995 return mapEditor->getSelectionColor();
4998 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
5001 for (int i=0;i<rootItem->branchCount();i++)
5002 rootItem->getBranchNum(i)->setHideTmp (mode);
5004 if (mode==TreeItem::HideExport)
5010 //////////////////////////////////////////////
5011 // Selection related
5012 //////////////////////////////////////////////
5014 void VymModel::setSelectionModel (QItemSelectionModel *sm)
5019 QItemSelectionModel* VymModel::getSelectionModel()
5024 void VymModel::setSelectionBlocked (bool b)
5029 bool VymModel::isSelectionBlocked()
5031 return selectionBlocked;
5034 bool VymModel::select ()
5036 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
5039 bool VymModel::select (const QString &s)
5046 TreeItem *ti=findBySelectString(s);
5047 if (ti) return select (index(ti));
5051 bool VymModel::select (LinkableMapObj *lmo)
5053 QItemSelection oldsel=selModel->selection();
5056 return select (index (lmo->getTreeItem()) );
5061 bool VymModel::select (TreeItem *ti)
5063 if (ti) return select (index(ti));
5067 bool VymModel::select (const QModelIndex &index)
5069 if (index.isValid() )
5071 selModel->select (index,QItemSelectionModel::ClearAndSelect );
5072 BranchItem *bi=getSelectedBranch();
5073 if (bi) bi->setLastSelectedBranch();
5079 void VymModel::unselect()
5081 if (!selModel->selectedIndexes().isEmpty())
5083 lastSelectString=getSelectString();
5084 selModel->clearSelection();
5088 bool VymModel::reselect()
5090 return select (lastSelectString);
5093 void VymModel::emitShowSelection()
5095 if (!blockReposition)
5096 emit (showSelection() );
5099 void VymModel::emitNoteHasChanged (TreeItem *ti)
5101 QModelIndex ix=index(ti);
5102 emit (noteHasChanged (ix) );
5105 void VymModel::emitDataHasChanged (TreeItem *ti)
5107 QModelIndex ix=index(ti);
5108 emit (dataChanged (ix,ix) );
5111 void VymModel::emitUpdateLayout()
5113 if (settings.value("/mainwindow/autoLayout/use","true")=="true")
5114 emit (updateLayout());
5117 bool VymModel::selectFirstBranch()
5119 TreeItem *ti=getSelectedBranch();
5122 TreeItem *par=ti->parent();
5125 TreeItem *ti2=par->getFirstBranch();
5126 if (ti2) return select(ti2);
5132 bool VymModel::selectLastBranch()
5134 TreeItem *ti=getSelectedBranch();
5137 TreeItem *par=ti->parent();
5140 TreeItem *ti2=par->getLastBranch();
5141 if (ti2) return select(ti2);
5147 bool VymModel::selectLastSelectedBranch()
5149 BranchItem *bi=getSelectedBranch();
5152 bi=bi->getLastSelectedBranch();
5153 if (bi) return select (bi);
5158 bool VymModel::selectParent()
5160 TreeItem *ti=getSelectedItem();
5171 TreeItem::Type VymModel::selectionType()
5173 QModelIndexList list=selModel->selectedIndexes();
5174 if (list.isEmpty()) return TreeItem::Undefined;
5175 TreeItem *ti = getItem (list.first() );
5176 return ti->getType();
5180 LinkableMapObj* VymModel::getSelectedLMO()
5182 QModelIndexList list=selModel->selectedIndexes();
5183 if (!list.isEmpty() )
5185 TreeItem *ti = getItem (list.first() );
5186 TreeItem::Type type=ti->getType();
5187 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5188 return ((MapItem*)ti)->getLMO();
5193 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5195 TreeItem *ti = getSelectedBranch();
5197 return (BranchObj*)( ((MapItem*)ti)->getLMO());
5202 BranchItem* VymModel::getSelectedBranch()
5204 QModelIndexList list=selModel->selectedIndexes();
5205 if (!list.isEmpty() )
5207 TreeItem *ti = getItem (list.first() );
5208 TreeItem::Type type=ti->getType();
5209 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5210 return (BranchItem*)ti;
5215 ImageItem* VymModel::getSelectedImage()
5217 QModelIndexList list=selModel->selectedIndexes();
5218 if (!list.isEmpty())
5220 TreeItem *ti=getItem (list.first());
5221 if (ti && ti->getType()==TreeItem::Image)
5222 return (ImageItem*)ti;
5227 AttributeItem* VymModel::getSelectedAttribute()
5229 QModelIndexList list=selModel->selectedIndexes();
5230 if (!list.isEmpty() )
5232 TreeItem *ti = getItem (list.first() );
5233 TreeItem::Type type=ti->getType();
5234 if (type ==TreeItem::Attribute)
5235 return (AttributeItem*)ti;
5240 TreeItem* VymModel::getSelectedItem()
5242 QModelIndexList list=selModel->selectedIndexes();
5243 if (!list.isEmpty() )
5244 return getItem (list.first() );
5249 QModelIndex VymModel::getSelectedIndex()
5251 QModelIndexList list=selModel->selectedIndexes();
5252 if (list.isEmpty() )
5253 return QModelIndex();
5255 return list.first();
5258 QString VymModel::getSelectString ()
5260 return getSelectString (getSelectedItem());
5263 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5265 if (!lmo) return QString();
5266 return getSelectString (lmo->getTreeItem() );
5269 QString VymModel::getSelectString (TreeItem *ti)
5273 switch (ti->getType())
5275 case TreeItem::MapCenter: s="mc:"; break;
5276 case TreeItem::Branch: s="bo:";break;
5277 case TreeItem::Image: s="fi:";break;
5278 case TreeItem::Attribute: s="ai:";break;
5279 case TreeItem::XLink: s="xl:";break;
5281 s="unknown type in VymModel::getSelectString()";
5284 s= s + QString("%1").arg(ti->num());
5286 // call myself recursively
5287 s= getSelectString(ti->parent()) +","+s;