1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
10 #include "editxlinkdialog.h"
12 #include "exporthtmldialog.h"
14 #include "findresultmodel.h"
15 #include "mainwindow.h"
20 #include "xlinkitem.h"
22 #include "xml-freemind.h"
28 extern Main *mainWindow;
29 extern QDBusConnection dbusConnection;
31 extern Settings settings;
32 extern QString tmpVymDir;
34 extern TextEditor *textEditor;
35 extern FlagRow *standardFlagsMaster;
37 extern QString clipboardDir;
38 extern QString clipboardFile;
39 extern bool clipboardEmpty;
41 extern ImageIO imageIO;
43 extern QString vymName;
44 extern QString vymVersion;
45 extern QDir vymBaseDir;
47 extern QDir lastImageDir;
48 extern QDir lastFileDir;
50 extern Settings settings;
52 uint VymModel::idLast=0; // make instance
56 //qDebug()<< "Const VymModel";
58 rootItem->setModel (this);
64 //qDebug() << "Destr VymModel begin this="<<this;
65 autosaveTimer->stop();
66 fileChangedTimer->stop();
67 //qApp->processEvents(); // Update view (scene()->update() is not enough)
68 //qDebug() << "Destr VymModel end this="<<this;
71 void VymModel::clear()
73 while (rootItem->childCount() >0)
75 //qDebug()<<"VM::clear ri="<<rootItem<<" ri->count()="<<rootItem->childCount();
76 deleteItem (rootItem->getChildNum(0) );
80 void VymModel::init ()
85 // Also no scene yet (should not be needed anyway) FIXME-3 VM
99 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
100 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
101 mainWindow->updateHistory (undoSet);
104 makeTmpDirectories();
109 fileName=tr("unnamed");
111 blockReposition=false;
112 blockSaveState=false;
114 autosaveTimer=new QTimer (this);
115 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
117 fileChangedTimer=new QTimer (this);
118 fileChangedTimer->start(3000);
119 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
124 selectionBlocked=false;
129 // animations // FIXME-4 switch to new animation system
130 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-4 add options to control _what_ is animated
131 animationTicks=settings.readNumEntry("/animation/ticks",10);
132 animationInterval=settings.readNumEntry("/animation/interval",50);
134 animationTimer=new QTimer (this);
135 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
138 defLinkColor=QColor (0,0,255);
139 defXLinkColor=QColor (180,180,180);
140 linkcolorhint=LinkableMapObj::DefaultColor;
141 linkstyle=LinkableMapObj::PolyParabel;
143 defXLinkColor=QColor (230,230,230);
146 hidemode=TreeItem::HideNone;
148 // Avoid recursions later
149 cleaningUpLinks=false;
154 //Initialize DBUS object
155 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
156 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapID),this))
157 qWarning ("VymModel: Couldn't register DBUS object!");
160 void VymModel::makeTmpDirectories()
162 // Create unique temporary directories
163 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapID);
164 histPath = tmpMapDir+"/history";
170 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
175 bool VymModel::isRepositionBlocked()
177 return blockReposition;
180 void VymModel::updateActions() // FIXME-4 maybe don't update if blockReposition is set
182 //cout << "VM::updateActions \n";
183 // Tell mainwindow to update states of actions
184 mainWindow->updateActions();
189 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
191 // tmpdir temporary directory to which data will be written
192 // prefix mapname, which will be appended to images etc.
193 // writeflags Only write flags for "real" save of map, not undo
194 // offset offset of bbox of whole map in scene.
195 // Needed for XML export
204 case LinkableMapObj::Line:
207 case LinkableMapObj::Parabel:
210 case LinkableMapObj::PolyLine:
214 ls="StylePolyParabel";
218 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
220 if (linkcolorhint==LinkableMapObj::HeadingColor)
221 colhint=xml.attribut("linkColorHint","HeadingColor");
223 QString mapAttr=xml.attribut("version",vymVersion);
225 mapAttr+= xml.attribut("author",author) +
226 xml.attribut("comment",comment) +
227 xml.attribut("date",getDate()) +
228 xml.attribut("branchCount", QString().number(branchCount())) +
229 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
230 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
231 xml.attribut("linkStyle", ls ) +
232 xml.attribut("linkColor", defLinkColor.name() ) +
233 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
234 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
235 xml.attribut("mapZoomFactor", QString().setNum(mapEditor->getZoomFactorTarget()) ) +
237 s+=xml.beginElement("vymmap",mapAttr);
240 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
241 standardFlagsMaster->resetUsedCounter();
244 // Temporary list of links
245 QList <Link*> tmpLinks;
247 // Build xml recursivly
250 // Save all mapcenters as complete map, if saveSel not set
251 s+=saveTreeToDir(tmpdir,prefix,offset,tmpLinks);
253 // Save local settings
254 s+=settings.getDataXML (destPath);
257 if (getSelectedItem() && !saveSel )
258 s+=xml.valueElement("select",getSelectString());
262 switch (saveSel->getType())
264 case TreeItem::Branch:
266 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset,tmpLinks);
268 case TreeItem::MapCenter:
270 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset,tmpLinks);
272 case TreeItem::Image:
274 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
277 // other types shouldn't be safed directly...
283 for (int i=0; i<tmpLinks.count();++i)
285 s+=tmpLinks.at(i)->saveToDir();
289 s+=xml.endElement("vymmap");
291 //cout << s.toStdString() << endl;
293 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
297 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset, QList <Link*> &tmpLinks)
300 for (int i=0; i<rootItem->branchCount(); i++)
301 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset,tmpLinks);
305 void VymModel::setFilePath(QString fpath, QString destname)
307 if (fpath.isEmpty() || fpath=="")
314 filePath=fpath; // becomes absolute path
315 fileName=fpath; // gets stripped of path
316 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
318 // If fpath is not an absolute path, complete it
319 filePath=QDir(fpath).absPath();
320 fileDir=filePath.left (1+filePath.findRev ("/"));
322 // Set short name, too. Search from behind:
323 int i=fileName.findRev("/");
324 if (i>=0) fileName=fileName.remove (0,i+1);
326 // Forget the .vym (or .xml) for name of map
327 mapName=fileName.left(fileName.findRev(".",-1,true) );
331 void VymModel::setFilePath(QString fpath)
333 setFilePath (fpath,fpath);
336 QString VymModel::getFilePath()
341 QString VymModel::getFileName()
346 QString VymModel::getMapName()
351 QString VymModel::getDestPath()
356 ErrorCode VymModel::loadMap (
358 const LoadMode &lmode,
360 const FileType &ftype,
363 ErrorCode err=success;
365 // Get updated zoomFactor, before applying one read from file in the end
366 if (mapEditor) zoomFactor=mapEditor->getZoomFactorTarget();
368 // For ImportReplace let's insert a new branch and replace that
369 BranchItem *selbi=getSelectedBranch();
370 BranchItem *newbi=NULL;
372 parseBaseHandler *handler;
376 case VymMap: handler=new parseVYMHandler; break;
377 case FreemindMap : handler=new parseFreemindHandler; break;
379 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
380 "Unknown FileType in VymModel::load()");
384 bool zipped_org=zipped;
388 selModel->clearSelection();
391 if (!selbi) return aborted;
392 if (lmode==ImportAdd)
393 if (saveStateFlag) saveStateChangingPart(
396 QString("addMapInsert (%1)").arg(fname),
397 QString("Add map %1 to %2").arg(fname).arg(getObjectName(selbi)));
398 if (lmode==ImportReplace)
400 if (saveStateFlag) saveStateChangingPart(
403 QString("addMapReplace(%1)").arg(fname),
404 QString("Add map %1 to %2").arg(fname).arg(getObjectName(selbi)));
405 newbi=addNewBranchInt (selbi,-1); // Add below selection
411 // Create temporary directory for packing
413 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
416 QMessageBox::critical( 0, tr( "Critical Load Error" ),
417 tr("Couldn't create temporary directory before load\n"));
422 err=unzipDir (tmpZipDir,fname);
432 // Look for mapname.xml
433 xmlfile= fname.left(fname.findRev(".",-1,true));
434 xmlfile=xmlfile.section( '/', -1 );
435 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
436 if (!mfile.exists() )
438 // mapname.xml does not exist, well,
439 // maybe someone renamed the mapname.vym file...
440 // Try to find any .xml in the toplevel
441 // directory of the .vym file
442 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
443 if (flist.count()==1)
445 // Only one entry, take this one
446 xmlfile=tmpZipDir + "/"+flist.first();
449 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
450 *it=tmpZipDir + "/" + *it;
451 // TODO Multiple entries, load all (but only the first one into this ME)
452 //mainWindow->fileLoadFromTmp (flist);
453 //returnCode=1; // Silently forget this attempt to load
454 qWarning ("MainWindow::load (fn) multimap found...");
457 if (flist.isEmpty() )
459 QMessageBox::critical( 0, tr( "Critical Load Error" ),
460 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
463 } //file doesn't exist
465 xmlfile=mfile.name();
468 QFile file( xmlfile);
470 // I am paranoid: file should exist anyway
471 // according to check in mainwindow.
474 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
475 tr(QString("Couldn't open map %1").arg(file.name())));
479 bool blockSaveStateOrg=blockSaveState;
480 blockReposition=true;
482 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
483 QXmlInputSource source( file);
484 QXmlSimpleReader reader;
485 reader.setContentHandler( handler );
486 reader.setErrorHandler( handler );
487 handler->setModel ( this);
490 // We need to set the tmpDir in order to load files with rel. path
495 tmpdir=fname.left(fname.findRev("/",-1));
496 handler->setTmpDir (tmpdir);
497 handler->setInputFile (file.name());
498 if (lmode==ImportReplace)
499 handler->setLoadMode (ImportAdd,pos);
501 handler->setLoadMode (lmode,pos);
503 bool ok = reader.parse( source );
504 blockReposition=false;
505 blockSaveState=blockSaveStateOrg;
506 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
515 autosaveTimer->stop();
517 // Reset timestamp to check for later updates of file
518 fileChangedTime=QFileInfo (destPath).lastModified();
523 if (lmode==ImportReplace)
527 deleteKeepChildren (false);
530 emitSelectionChanged();
533 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
534 tr( handler->errorProtocol() ) );
536 // Still return "success": the map maybe at least
537 // partially read by the parser
542 removeDir (QDir(tmpZipDir));
544 // Restore original zip state
549 if (mapEditor) mapEditor->setZoomFactorTarget (zoomFactor);
551 //Update view (scene()->update() is not enough)
552 qApp->processEvents(); // Update view (scene()->update() is not enough)
556 ErrorCode VymModel::save (const SaveMode &savemode)
560 QString safeFilePath;
562 ErrorCode err=success;
566 mapFileName=mapName+".xml";
568 // use name given by user, even if he chooses .doc
569 mapFileName=fileName;
571 // Look, if we should zip the data:
574 QMessageBox mb( vymName,
575 tr("The map %1\ndid not use the compressed "
576 "vym file format.\nWriting it uncompressed will also write images \n"
577 "and flags and thus may overwrite files in the "
578 "given directory\n\nDo you want to write the map").arg(filePath),
579 QMessageBox::Warning,
580 QMessageBox::Yes | QMessageBox::Default,
582 QMessageBox::Cancel | QMessageBox::Escape);
583 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
584 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
585 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
588 case QMessageBox::Yes:
589 // save compressed (default file format)
592 case QMessageBox::No:
596 case QMessageBox::Cancel:
603 // First backup existing file, we
604 // don't want to add to old zip archives
608 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
610 QString backupFileName(destPath + "~");
611 QFile backupFile(backupFileName);
612 if (backupFile.exists() && !backupFile.remove())
614 QMessageBox::warning(0, tr("Save Error"),
615 tr("%1\ncould not be removed before saving").arg(backupFileName));
617 else if (!f.rename(backupFileName))
619 QMessageBox::warning(0, tr("Save Error"),
620 tr("%1\ncould not be renamed before saving").arg(destPath));
627 // Create temporary directory for packing
629 tmpZipDir=makeTmpDir (ok,"vym-zip");
632 QMessageBox::critical( 0, tr( "Critical Load Error" ),
633 tr("Couldn't create temporary directory before save\n"));
637 safeFilePath=filePath;
638 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
641 // Create mapName and fileDir
642 makeSubDirs (fileDir);
645 if (savemode==CompleteMap || selModel->selection().isEmpty())
648 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
651 autosaveTimer->stop();
656 if (selectionType()==TreeItem::Image)
659 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
660 // TODO take care of multiselections
663 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
666 qWarning ("ME::saveStringToDisk failed!");
672 if (err==success) err=zipDir (tmpZipDir,destPath);
675 removeDir (QDir(tmpZipDir));
677 // Restore original filepath outside of tmp zip dir
678 setFilePath (safeFilePath);
682 fileChangedTime=QFileInfo (destPath).lastModified();
686 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
688 ImageItem *ii=createImage(dst);
698 void VymModel::loadFloatImage ()
700 BranchItem *selbi=getSelectedBranch();
704 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
705 fd->setMode (Q3FileDialog::ExistingFiles);
706 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
707 ImagePreview *p =new ImagePreview (fd);
708 fd->setContentsPreviewEnabled( TRUE );
709 fd->setContentsPreview( p, p );
710 fd->setPreviewMode( Q3FileDialog::Contents );
711 fd->setCaption(vymName+" - " +tr("Load image"));
712 fd->setDir (lastImageDir);
715 if ( fd->exec() == QDialog::Accepted )
717 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
718 lastImageDir=QDir (fd->dirPath());
721 for (int j=0; j<fd->selectedFiles().count(); j++)
723 s=fd->selectedFiles().at(j);
724 ii=loadFloatImageInt (selbi,s);
725 //FIXME-3 check savestate for loadImage
731 QString ("loadImage (%1)").arg(s ),
732 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
735 // TODO loadFIO error handling
736 qWarning ("Failed to load "+s);
744 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
749 void VymModel::saveFloatImage ()
751 ImageItem *ii=getSelectedImage();
754 QFileDialog *fd=new QFileDialog( NULL);
755 fd->setFilters (imageIO.getFilters());
756 fd->setCaption(vymName+" - " +tr("Save image"));
757 fd->setFileMode( QFileDialog::AnyFile );
758 fd->setDirectory (lastImageDir);
759 // fd->setSelection (fio->getOriginalFilename());
763 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
765 fn=fd->selectedFiles().at(0);
766 if (QFile (fn).exists() )
768 QMessageBox mb( vymName,
769 tr("The file %1 exists already.\n"
770 "Do you want to overwrite it?").arg(fn),
771 QMessageBox::Warning,
772 QMessageBox::Yes | QMessageBox::Default,
773 QMessageBox::Cancel | QMessageBox::Escape,
774 QMessageBox::NoButton );
776 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
777 mb.setButtonText( QMessageBox::No, tr("Cancel"));
780 case QMessageBox::Yes:
783 case QMessageBox::Cancel:
790 saveFloatImageInt (ii,fd->selectedFilter(),fn );
797 void VymModel::importDirInt(BranchItem *dst, QDir d)
799 BranchItem *selbi=getSelectedBranch();
803 // Traverse directories
804 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
805 QFileInfoList list = d.entryInfoList();
808 for (int i = 0; i < list.size(); ++i)
811 if (fi.fileName() != "." && fi.fileName() != ".." )
813 bi=addNewBranchInt(dst,-2);
814 bi->setHeading (fi.fileName() ); // FIXME-3 check this
815 bi->setHeadingColor (QColor("blue"));
817 if ( !d.cd(fi.fileName()) )
818 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
821 // Recursively add subdirs
828 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
829 list = d.entryInfoList();
831 for (int i = 0; i < list.size(); ++i)
834 bi=addNewBranchInt (dst,-2);
835 bi->setHeading (fi.fileName() );
836 bi->setHeadingColor (QColor("black"));
837 if (fi.fileName().right(4) == ".vym" )
838 bi->setVymLink (fi.filePath());
843 void VymModel::importDirInt (const QString &s)
845 BranchItem *selbi=getSelectedBranch();
848 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
851 importDirInt (selbi,d);
855 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
857 BranchItem *selbi=getSelectedBranch();
861 filters <<"VYM map (*.vym)";
862 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
863 fd->setMode (QFileDialog::DirectoryOnly);
864 fd->setFilters (filters);
865 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
869 if ( fd->exec() == QDialog::Accepted )
871 importDirInt (fd->selectedFile() );
873 //FIXME-3 VM needed? scene()->update();
879 void VymModel::autosave()
884 cout << "VymModel::autosave rejected due to missing filePath\n";
887 QDateTime now=QDateTime().currentDateTime();
889 // Disable autosave, while we have gone back in history
890 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
891 if (redosAvail>0) return;
893 // Also disable autosave for new map without filename
894 if (filePath.isEmpty()) return;
897 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
899 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
900 mainWindow->fileSave (this);
903 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
908 void VymModel::fileChanged()
910 // Check if file on disk has changed meanwhile
911 if (!filePath.isEmpty())
913 QDateTime tmod=QFileInfo (filePath).lastModified();
914 if (tmod>fileChangedTime)
916 // FIXME-3 VM switch to current mapeditor and finish lineedits...
917 QMessageBox mb( vymName,
918 tr("The file of the map on disk has changed:\n\n"
919 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
920 QMessageBox::Question,
922 QMessageBox::Cancel | QMessageBox::Default,
923 QMessageBox::NoButton );
925 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
926 mb.setButtonText( QMessageBox::No, tr("Ignore"));
929 case QMessageBox::Yes:
932 case QMessageBox::Cancel:
933 fileChangedTime=tmod; // allow autosave to overwrite newer file!
939 bool VymModel::isDefault()
944 void VymModel::makeDefault()
950 bool VymModel::hasChanged()
955 void VymModel::setChanged()
958 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
962 latestAddedItem=NULL;
966 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
968 if (!lmo || !lmo->getTreeItem() ) return QString();
969 return getObjectName (lmo->getTreeItem() );
973 QString VymModel::getObjectName (TreeItem *ti)
976 if (!ti) return QString("Error: NULL has no name!");
978 if (s=="") s="unnamed";
980 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
983 void VymModel::redo()
985 // Can we undo at all?
986 if (redosAvail<1) return;
988 bool blockSaveStateOrg=blockSaveState;
993 if (undosAvail<stepsTotal) undosAvail++;
995 if (curStep>stepsTotal) curStep=1;
996 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
997 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
998 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
999 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1000 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1001 QString version=undoSet.readEntry ("/history/version");
1003 /* TODO Maybe check for version, if we save the history
1004 if (!checkVersion(version))
1005 QMessageBox::warning(0,tr("Warning"),
1006 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1009 // Find out current undo directory
1010 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1014 cout << "VymModel::redo() begin\n";
1015 cout << " undosAvail="<<undosAvail<<endl;
1016 cout << " redosAvail="<<redosAvail<<endl;
1017 cout << " curStep="<<curStep<<endl;
1018 cout << " ---------------------------"<<endl;
1019 cout << " comment="<<comment.toStdString()<<endl;
1020 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1021 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1022 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1023 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1024 cout << " ---------------------------"<<endl<<endl;
1027 // select object before redo
1028 if (!redoSelection.isEmpty())
1029 select (redoSelection);
1034 parseAtom (redoCommand,noErr,errMsg);
1036 blockSaveState=blockSaveStateOrg;
1038 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1039 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1040 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1041 undoSet.writeSettings(histPath);
1043 mainWindow->updateHistory (undoSet);
1046 /* TODO remove testing
1047 cout << "ME::redo() end\n";
1048 cout << " undosAvail="<<undosAvail<<endl;
1049 cout << " redosAvail="<<redosAvail<<endl;
1050 cout << " curStep="<<curStep<<endl;
1051 cout << " ---------------------------"<<endl<<endl;
1057 bool VymModel::isRedoAvailable()
1059 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1065 void VymModel::undo() //FIXME-1 segfault when trying to undo in a brandnew map
1067 // Can we undo at all?
1068 if (undosAvail<1) return;
1070 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1072 bool blockSaveStateOrg=blockSaveState;
1073 blockSaveState=true;
1075 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1076 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1077 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1078 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1079 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1080 QString version=undoSet.readEntry ("/history/version");
1082 /* TODO Maybe check for version, if we save the history
1083 if (!checkVersion(version))
1084 QMessageBox::warning(0,tr("Warning"),
1085 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1088 // Find out current undo directory
1089 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1091 // select object before undo
1092 if (!select (undoSelection))
1094 qWarning ("VymModel::undo() Could not select object for undo");
1101 cout << "VymModel::undo() begin\n";
1102 cout << " undosAvail="<<undosAvail<<endl;
1103 cout << " redosAvail="<<redosAvail<<endl;
1104 cout << " curStep="<<curStep<<endl;
1105 cout << " ---------------------------"<<endl;
1106 cout << " comment="<<comment.toStdString()<<endl;
1107 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1108 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1109 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1110 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1111 cout << " ---------------------------"<<endl<<endl;
1116 parseAtom (undoCommand,noErr,errMsg);
1120 if (curStep<1) curStep=stepsTotal;
1124 blockSaveState=blockSaveStateOrg;
1126 cout << "VymModel::undo() end\n";
1127 cout << " undosAvail="<<undosAvail<<endl;
1128 cout << " redosAvail="<<redosAvail<<endl;
1129 cout << " curStep="<<curStep<<endl;
1130 cout << " ---------------------------"<<endl<<endl;
1133 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1134 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1135 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1136 undoSet.writeSettings(histPath);
1138 mainWindow->updateHistory (undoSet);
1140 //emitSelectionChanged();
1143 bool VymModel::isUndoAvailable()
1145 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1151 void VymModel::gotoHistoryStep (int i)
1153 // Restore variables
1154 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1155 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1157 if (i<0) i=undosAvail+redosAvail;
1159 // Clicking above current step makes us undo things
1162 for (int j=0; j<undosAvail-i; j++) undo();
1165 // Clicking below current step makes us redo things
1167 for (int j=undosAvail; j<i; j++)
1169 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1173 // And ignore clicking the current row ;-)
1177 QString VymModel::getHistoryPath()
1179 QString histName(QString("history-%1").arg(curStep));
1180 return (tmpMapDir+"/"+histName);
1183 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1185 sendData(redoCom); //FIXME-3 testing
1190 if (blockSaveState) return;
1192 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1194 // Find out current undo directory
1195 if (undosAvail<stepsTotal) undosAvail++;
1197 if (curStep>stepsTotal) curStep=1;
1199 QString backupXML="";
1200 QString histDir=getHistoryPath();
1201 QString bakMapPath=histDir+"/map.xml";
1203 // Create histDir if not available
1206 makeSubDirs (histDir);
1208 // Save depending on how much needs to be saved
1209 QList <Link*> tmpLinks;
1211 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1213 QString undoCommand="";
1214 if (savemode==UndoCommand)
1216 undoCommand=undoCom;
1218 else if (savemode==PartOfMap )
1220 undoCommand=undoCom;
1221 undoCommand.replace ("PATH",bakMapPath);
1225 if (!backupXML.isEmpty())
1226 // Write XML Data to disk
1227 saveStringToDisk (bakMapPath,backupXML);
1229 // We would have to save all actions in a tree, to keep track of
1230 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1233 // Write the current state to disk
1234 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1235 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1236 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1237 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1238 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1239 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1240 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1241 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1242 undoSet.setEntry (QString("/history/version"),vymVersion);
1243 undoSet.writeSettings(histPath);
1247 // TODO remove after testing
1248 //cout << " into="<< histPath.toStdString()<<endl;
1249 cout << " stepsTotal="<<stepsTotal<<
1250 ", undosAvail="<<undosAvail<<
1251 ", redosAvail="<<redosAvail<<
1252 ", curStep="<<curStep<<endl;
1253 cout << " ---------------------------"<<endl;
1254 cout << " comment="<<comment.toStdString()<<endl;
1255 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1256 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1257 cout << " redoCom="<<redoCom.toStdString()<<endl;
1258 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1259 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1260 cout << " ---------------------------"<<endl;
1263 mainWindow->updateHistory (undoSet);
1269 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1271 // save the selected part of the map, Undo will replace part of map
1272 QString undoSelection="";
1274 undoSelection=getSelectString(undoSel);
1276 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1277 QString redoSelection="";
1279 redoSelection=getSelectString(undoSel);
1281 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1284 saveState (PartOfMap,
1285 undoSelection, "addMapReplace (\"PATH\")",
1291 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1295 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1298 QString undoSelection;
1299 QString redoSelection=getSelectString(redoSel);
1300 if (redoSel->getType()==TreeItem::Branch)
1302 undoSelection=getSelectString (redoSel->parent());
1303 // save the selected branch of the map, Undo will insert part of map
1304 saveState (PartOfMap,
1305 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1306 redoSelection, "delete ()",
1310 if (redoSel->getType()==TreeItem::MapCenter)
1312 // save the selected branch of the map, Undo will insert part of map
1313 saveState (PartOfMap,
1314 undoSelection, QString("addMapInsert (\"PATH\")"),
1315 redoSelection, "delete ()",
1322 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1324 // "Normal" savestate: save commands, selections and comment
1325 // so just save commands for undo and redo
1326 // and use current selection
1328 QString redoSelection="";
1329 if (redoSel) redoSelection=getSelectString(redoSel);
1330 QString undoSelection="";
1331 if (undoSel) undoSelection=getSelectString(undoSel);
1333 saveState (UndoCommand,
1340 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1342 // "Normal" savestate: save commands, selections and comment
1343 // so just save commands for undo and redo
1344 // and use current selection
1345 saveState (UndoCommand,
1352 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1354 // "Normal" savestate applied to model (no selection needed):
1355 // save commands and comment
1356 saveState (UndoCommand,
1364 QGraphicsScene* VymModel::getScene ()
1369 TreeItem* VymModel::findBySelectString(QString s)
1371 if (s.isEmpty() ) return NULL;
1373 // Old maps don't have multiple mapcenters and don't save full path
1374 if (s.left(2) !="mc")
1377 QStringList parts=s.split (",");
1380 TreeItem *ti=rootItem;
1382 while (!parts.isEmpty() )
1384 typ=parts.first().left(2);
1385 n=parts.first().right(parts.first().length() - 3).toInt();
1386 parts.removeFirst();
1387 if (typ=="mc" || typ=="bo")
1388 ti=ti->getBranchNum (n);
1390 ti=ti->getImageNum (n);
1392 ti=ti->getAttributeNum (n);
1394 ti=ti->getXLinkNum (n);
1395 if(!ti) return NULL;
1400 TreeItem* VymModel::findID (const uint &i) //FIXME-3 Search also other types...
1402 BranchItem *cur=NULL;
1403 BranchItem *prev=NULL;
1404 nextBranch(cur,prev);
1407 if (i==cur->getID() ) return cur;
1408 nextBranch(cur,prev);
1413 //////////////////////////////////////////////
1415 //////////////////////////////////////////////
1416 void VymModel::setVersion (const QString &s)
1421 QString VymModel::getVersion()
1426 void VymModel::setAuthor (const QString &s)
1429 QString ("setMapAuthor (\"%1\")").arg(author),
1430 QString ("setMapAuthor (\"%1\")").arg(s),
1431 QString ("Set author of map to \"%1\"").arg(s)
1436 QString VymModel::getAuthor()
1441 void VymModel::setComment (const QString &s)
1444 QString ("setMapComment (\"%1\")").arg(comment),
1445 QString ("setMapComment (\"%1\")").arg(s),
1446 QString ("Set comment of map")
1451 QString VymModel::getComment ()
1456 QString VymModel::getDate ()
1458 return QDate::currentDate().toString ("yyyy-MM-dd");
1461 int VymModel::branchCount()
1464 BranchItem *cur=NULL;
1465 BranchItem *prev=NULL;
1466 nextBranch(cur,prev);
1470 nextBranch(cur,prev);
1475 void VymModel::setSortFilter (const QString &s)
1478 emit (sortFilterChanged (sortFilter));
1481 QString VymModel::getSortFilter ()
1486 void VymModel::setHeading(const QString &s)
1488 BranchItem *selbi=getSelectedBranch();
1493 "setHeading (\""+selbi->getHeading()+"\")",
1495 "setHeading (\""+s+"\")",
1496 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1497 selbi->setHeading(s );
1498 emitDataHasChanged ( selbi); //FIXME-4 maybe emit signal from TreeItem?
1500 emitSelectionChanged();
1504 QString VymModel::getHeading()
1506 TreeItem *selti=getSelectedItem();
1508 return selti->getHeading();
1513 void VymModel::setNote(const QString &s)
1515 TreeItem *selti=getSelectedItem();
1520 "setNote (\""+selti->getNote()+"\")",
1522 "setNote (\""+s+"\")",
1523 QString("Set note of %1 ").arg(getObjectName(selti)) );
1526 emitNoteHasChanged(selti);
1527 emitDataHasChanged(selti);
1530 QString VymModel::getNote()
1532 TreeItem *selti=getSelectedItem();
1534 return selti->getNote();
1539 void VymModel::loadNote (const QString &fn)
1541 BranchItem *selbi=getSelectedBranch();
1545 if (!loadStringFromDisk (fn,n))
1546 qWarning ()<<"VymModel::loadNote Couldn't load "<<fn;
1550 qWarning ("VymModel::loadNote no branch selected");
1553 void VymModel::saveNote (const QString &fn)
1555 BranchItem *selbi=getSelectedBranch();
1558 QString n=selbi->getNote();
1560 qWarning ()<<"VymModel::saveNote note is empty, won't save to "<<fn;
1563 if (!saveStringToDisk (fn,n))
1564 qWarning ()<<"VymModel::saveNote Couldn't save "<<fn;
1569 qWarning ("VymModel::saveNote no branch selected");
1572 void VymModel::findDuplicateURLs() // FIXME-3 needs GUI
1574 // Generate map containing _all_ URLs and branches
1576 QMap <QString,BranchItem*> map;
1577 BranchItem *cur=NULL;
1578 BranchItem *prev=NULL;
1579 nextBranch(cur,prev);
1584 map.insertMulti (u,cur);
1585 nextBranch(cur,prev);
1588 // Extract duplicate URLs
1589 QMap <QString, BranchItem*>::const_iterator i=map.constBegin();
1590 QMap <QString, BranchItem*>::const_iterator firstdup=map.constEnd(); //invalid
1591 while (i != map.constEnd())
1593 if (i!=map.constBegin() && i.key()==firstdup.key())
1595 if ( i-1==firstdup )
1597 cout << firstdup.key().toStdString() << endl;
1598 cout << " - "<< firstdup.value() <<" - "<<firstdup.value()->getHeadingStd()<<endl;
1600 cout << " - "<< i.value() <<" - "<<i.value()->getHeadingStd()<<endl;
1608 void VymModel::findAll (FindResultModel *rmodel, QString s, Qt::CaseSensitivity cs)
1611 rmodel->setSearchString (s);
1612 rmodel->setSearchFlags (0); //FIXME-3 translate cs to QTextDocument::FindFlag
1613 BranchItem *cur=NULL;
1614 BranchItem *prev=NULL;
1615 nextBranch(cur,prev);
1617 FindResultItem *lastParent=NULL;
1621 if (cur->getHeading().contains (s,cs))
1622 lastParent=rmodel->addItem (cur);
1623 QString n=cur->getNoteASCII();
1628 i=n.indexOf (s,i,cs);
1631 // If not there yet, add "parent" item
1634 lastParent=rmodel->addItem (cur);
1636 qWarning()<<"VymModel::findAll still no lastParent?!";
1639 lastParent->setSelectable (false);
1643 // save index of occurence
1644 rmodel->addSubItem (lastParent,QString(tr("Note","FindAll in VymModel")+" "+s),cur,j);
1649 nextBranch(cur,prev);
1653 BranchItem* VymModel::findText (QString s,Qt::CaseSensitivity cs)
1655 if (!s.isEmpty() && s!=findString)
1661 QTextDocument::FindFlags flags=0;
1662 if (cs==Qt::CaseSensitive) flags=QTextDocument::FindCaseSensitively;
1665 { // Nothing found or new find process
1667 // nothing found, start again
1671 nextBranch (findCurrent,findPrevious);
1673 bool searching=true;
1674 bool foundNote=false;
1675 while (searching && !EOFind)
1679 // Searching in Note
1680 if (findCurrent->getNote().contains(findString,cs))
1682 select (findCurrent);
1683 if (textEditor->findText(findString,flags))
1689 // Searching in Heading
1690 if (searching && findCurrent->getHeading().contains (findString,cs) )
1692 select(findCurrent);
1698 if (!nextBranch(findCurrent,findPrevious) )
1703 return getSelectedBranch();
1708 void VymModel::findReset()
1709 { // Necessary if text to find changes during a find process
1716 void VymModel::setScene (QGraphicsScene *s)
1721 void VymModel::setURL(const QString &url)
1723 TreeItem *selti=getSelectedItem();
1726 QString oldurl=selti->getURL();
1727 selti->setURL (url);
1730 QString ("setURL (\"%1\")").arg(oldurl),
1732 QString ("setURL (\"%1\")").arg(url),
1733 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1736 emitDataHasChanged (selti);
1737 emitShowSelection();
1741 QString VymModel::getURL()
1743 TreeItem *selti=getSelectedItem();
1745 return selti->getURL();
1750 QStringList VymModel::getURLs(bool ignoreScrolled)
1753 BranchItem *selbi=getSelectedBranch();
1754 BranchItem *cur=selbi;
1755 BranchItem *prev=NULL;
1758 if (!cur->getURL().isEmpty() && !(ignoreScrolled && cur->hasScrolledParent(cur) ))
1759 urls.append( cur->getURL());
1760 cur=nextBranch (cur,prev,true,selbi);
1766 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1768 BranchItem *bi=getSelectedBranch();
1771 BranchObj *bo=(BranchObj*)(bi->getLMO());
1774 QString s=bo->getFrameTypeName();
1775 bo->setFrameType (t);
1776 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1777 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1779 bo->updateLinkGeometry();
1784 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1786 BranchItem *bi=getSelectedBranch();
1789 BranchObj *bo=(BranchObj*)(bi->getLMO());
1792 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1793 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1794 bo->setFrameType (s);
1796 bo->updateLinkGeometry();
1801 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1804 BranchItem *bi=getSelectedBranch();
1807 BranchObj *bo=(BranchObj*)(bi->getLMO());
1810 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1811 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1812 bo->setFramePenColor (c);
1817 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1819 BranchItem *bi=getSelectedBranch();
1822 BranchObj *bo=(BranchObj*)(bi->getLMO());
1825 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1826 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1827 bo->setFrameBrushColor (c);
1832 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1834 BranchItem *bi=getSelectedBranch();
1837 BranchObj *bo=(BranchObj*)(bi->getLMO());
1840 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1841 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1842 bo->setFramePadding (i);
1844 bo->updateLinkGeometry();
1849 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1851 BranchItem *bi=getSelectedBranch();
1854 BranchObj *bo=(BranchObj*)(bi->getLMO());
1857 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1858 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1859 bo->setFrameBorderWidth (i);
1861 bo->updateLinkGeometry();
1866 void VymModel::setIncludeImagesVer(bool b)
1868 BranchItem *bi=getSelectedBranch();
1871 QString u= b ? "false" : "true";
1872 QString r=!b ? "false" : "true";
1876 QString("setIncludeImagesVertically (%1)").arg(u),
1878 QString("setIncludeImagesVertically (%1)").arg(r),
1879 QString("Include images vertically in %1").arg(getObjectName(bi))
1881 bi->setIncludeImagesVer(b);
1882 emitDataHasChanged ( bi);
1887 void VymModel::setIncludeImagesHor(bool b)
1889 BranchItem *bi=getSelectedBranch();
1892 QString u= b ? "false" : "true";
1893 QString r=!b ? "false" : "true";
1897 QString("setIncludeImagesHorizontally (%1)").arg(u),
1899 QString("setIncludeImagesHorizontally (%1)").arg(r),
1900 QString("Include images horizontally in %1").arg(getObjectName(bi))
1902 bi->setIncludeImagesHor(b);
1903 emitDataHasChanged ( bi);
1908 void VymModel::setHideLinkUnselected (bool b)
1910 TreeItem *ti=getSelectedItem();
1911 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1913 QString u= b ? "false" : "true";
1914 QString r=!b ? "false" : "true";
1918 QString("setHideLinkUnselected (%1)").arg(u),
1920 QString("setHideLinkUnselected (%1)").arg(r),
1921 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1923 ((MapItem*)ti)->setHideLinkUnselected(b);
1927 void VymModel::setHideExport(bool b)
1929 TreeItem *ti=getSelectedItem();
1931 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1933 ti->setHideInExport (b);
1934 QString u= b ? "false" : "true";
1935 QString r=!b ? "false" : "true";
1939 QString ("setHideExport (%1)").arg(u),
1941 QString ("setHideExport (%1)").arg(r),
1942 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1944 emitDataHasChanged(ti);
1945 emitSelectionChanged();
1948 // emitSelectionChanged();
1949 // FIXME-3 VM needed? scene()->update();
1953 void VymModel::toggleHideExport()
1955 TreeItem *selti=getSelectedItem();
1957 setHideExport ( !selti->hideInExport() );
1960 void VymModel::addTimestamp() //FIXME-3 new function, localize
1962 BranchItem *selbi=addNewBranch();
1965 QDate today=QDate::currentDate();
1967 selbi->setHeading (QString ("%1-%2-%3")
1968 .arg(today.year(),4,10,c)
1969 .arg(today.month(),2,10,c)
1970 .arg(today.day(),2,10,c));
1971 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1978 void VymModel::copy()
1980 TreeItem *selti=getSelectedItem();
1982 (selti->getType() == TreeItem::Branch ||
1983 selti->getType() == TreeItem::MapCenter ||
1984 selti->getType() == TreeItem::Image ))
1986 if (redosAvail == 0)
1989 QString s=getSelectString(selti);
1990 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1991 curClipboard=curStep;
1994 // Copy also to global clipboard, because we are at last step in history
1995 QString bakMapName(QString("history-%1").arg(curStep));
1996 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1997 copyDir (bakMapDir,clipboardDir );
1999 clipboardEmpty=false;
2005 void VymModel::pasteNoSave(const int &n)
2007 bool zippedOrg=zipped;
2008 if (redosAvail > 0 || n!=0)
2010 // Use the "historical" buffer
2011 QString bakMapName(QString("history-%1").arg(n));
2012 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2013 loadMap (bakMapDir+"/"+clipboardFile,ImportAdd, false);
2015 // Use the global buffer
2016 loadMap (clipboardDir+"/"+clipboardFile,ImportAdd, false);
2020 void VymModel::paste()
2022 BranchItem *selbi=getSelectedBranch();
2025 saveStateChangingPart(
2028 QString ("paste (%1)").arg(curClipboard),
2029 QString("Paste to %1").arg( getObjectName(selbi))
2036 void VymModel::cut()
2038 TreeItem *selti=getSelectedItem();
2039 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
2047 bool VymModel::moveUp(BranchItem *bi)
2049 if (bi && bi->canMoveUp())
2050 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
2055 void VymModel::moveUp()
2057 BranchItem *selbi=getSelectedBranch();
2060 QString oldsel=getSelectString();
2063 getSelectString(),"moveDown ()",
2065 QString("Move up %1").arg(getObjectName(selbi)));
2069 bool VymModel::moveDown(BranchItem *bi)
2071 if (bi && bi->canMoveDown())
2072 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2077 void VymModel::moveDown()
2079 BranchItem *selbi=getSelectedBranch();
2082 QString oldsel=getSelectString();
2083 if ( moveDown(selbi))
2085 getSelectString(),"moveUp ()",
2086 oldsel,"moveDown ()",
2087 QString("Move down %1").arg(getObjectName(selbi)));
2091 void VymModel::detach()
2093 BranchItem *selbi=getSelectedBranch();
2094 if (selbi && selbi->depth()>0)
2096 // if no relPos have been set before, try to use current rel positions
2097 if (selbi->getLMO())
2098 for (int i=0; i<selbi->branchCount();++i)
2099 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2101 QString oldsel=getSelectString();
2104 BranchObj *bo=selbi->getBranchObj();
2105 if (bo) p=bo->getAbsPos();
2106 QString parsel=getSelectString(selbi->parent());
2107 if ( relinkBranch (selbi,rootItem,-1) )
2109 getSelectString (selbi),
2110 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2113 QString("Detach %1").arg(getObjectName(selbi))
2118 void VymModel::sortChildren(bool inverse)
2120 BranchItem* selbi=getSelectedBranch();
2123 if(selbi->branchCount()>1)
2127 saveStateChangingPart(
2128 selbi,selbi, "sortChildren ()",
2129 QString("Sort children of %1").arg(getObjectName(selbi)));
2131 selbi->sortChildren(inverse);
2133 emitShowSelection();
2138 BranchItem* VymModel::createMapCenter()
2140 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2144 BranchItem* VymModel::createBranch(BranchItem *dst)
2147 return addNewBranchInt (dst,-2);
2152 ImageItem* VymModel::createImage(BranchItem *dst)
2159 QList<QVariant> cData;
2160 cData << "new" << "undef";
2162 ImageItem *newii=new ImageItem(cData) ;
2163 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2165 emit (layoutAboutToBeChanged() );
2168 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2169 n=dst->getRowNumAppend(newii);
2170 beginInsertRows (parix,n,n);
2171 dst->appendChild (newii);
2174 emit (layoutChanged() );
2176 // save scroll state. If scrolled, automatically select
2177 // new branch in order to tmp unscroll parent...
2178 newii->createMapObj(mapScene);
2185 bool VymModel::createLink(Link *link, bool createMO)
2187 BranchItem *begin=link->getBeginBranch();
2188 BranchItem *end =link->getEndBranch();
2192 qWarning ()<<"VM::createXLinkNew part of XLink is NULL";
2200 QList<QVariant> cData;
2202 cData << "new Link begin"<<"undef";
2203 XLinkItem *newli=new XLinkItem(cData) ;
2204 newli->setLink (link);
2205 link->setBeginLinkItem (newli);
2207 emit (layoutAboutToBeChanged() );
2210 n=begin->getRowNumAppend(newli);
2211 beginInsertRows (parix,n,n);
2212 begin->appendChild (newli);
2216 cData << "new Link end"<<"undef";
2217 newli=new XLinkItem(cData) ;
2218 newli->setLink (link);
2219 link->setEndLinkItem (newli);
2222 n=end->getRowNumAppend(newli);
2223 beginInsertRows (parix,n,n);
2224 end->appendChild (newli);
2227 emit (layoutChanged() );
2229 xlinks.append (link);
2234 link->createMapObj(mapScene);
2242 AttributeItem* VymModel::addAttribute()
2244 BranchItem *selbi=getSelectedBranch();
2247 QList<QVariant> cData;
2248 cData << "new attribute" << "undef";
2249 AttributeItem *a=new AttributeItem (cData);
2250 if (addAttribute (a)) return a;
2255 AttributeItem* VymModel::addAttribute(AttributeItem *ai) // FIXME-3 savestate missing
2257 BranchItem *selbi=getSelectedBranch();
2260 emit (layoutAboutToBeChanged() );
2262 QModelIndex parix=index(selbi);
2263 int n=selbi->getRowNumAppend (ai);
2264 beginInsertRows (parix,n,n);
2265 selbi->appendChild (ai);
2268 emit (layoutChanged() );
2270 ai->createMapObj(mapScene); //FIXME-3 check that...
2277 BranchItem* VymModel::addMapCenter ()
2279 BranchItem *bi=addMapCenter (contextPos);
2281 emitShowSelection();
2286 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2287 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2293 BranchItem* VymModel::addMapCenter(QPointF absPos)
2294 // createMapCenter could then probably be merged with createBranch
2298 QModelIndex parix=index(rootItem);
2300 QList<QVariant> cData;
2301 cData << "VM:addMapCenter" << "undef";
2302 BranchItem *newbi=new BranchItem (cData,rootItem);
2303 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2304 int n=rootItem->getRowNumAppend (newbi);
2306 emit (layoutAboutToBeChanged() );
2307 beginInsertRows (parix,n,n);
2309 rootItem->appendChild (newbi);
2312 emit (layoutChanged() );
2315 newbi->setPositionMode (MapItem::Absolute);
2316 BranchObj *bo=newbi->createMapObj(mapScene);
2317 if (bo) bo->move (absPos);
2322 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2324 // Depending on pos:
2325 // -3 insert in children of parent above selection
2326 // -2 add branch to selection
2327 // -1 insert in children of parent below selection
2328 // 0..n insert in children of parent at pos
2331 QList<QVariant> cData;
2332 cData << "" << "undef";
2337 BranchItem *newbi=new BranchItem (cData);
2338 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2340 emit (layoutAboutToBeChanged() );
2346 n=parbi->getRowNumAppend (newbi);
2347 beginInsertRows (parix,n,n);
2348 parbi->appendChild (newbi);
2350 }else if (num==-1 || num==-3)
2352 // insert below selection
2353 parbi=(BranchItem*)dst->parent();
2356 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2357 beginInsertRows (parix,n,n);
2358 parbi->insertBranch(n,newbi);
2361 emit (layoutChanged() );
2363 // Set color of heading to that of parent
2364 newbi->setHeadingColor (parbi->getHeadingColor());
2366 // save scroll state. If scrolled, automatically select
2367 // new branch in order to tmp unscroll parent...
2368 newbi->createMapObj(mapScene);
2373 BranchItem* VymModel::addNewBranch(int pos)
2375 // Different meaning than num in addNewBranchInt!
2379 BranchItem *newbi=NULL;
2380 BranchItem *selbi=getSelectedBranch();
2384 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2386 newbi=addNewBranchInt (selbi,pos-2);
2394 QString ("addBranch (%1)").arg(pos),
2395 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2398 // emitSelectionChanged(); FIXME-3
2399 latestAddedItem=newbi;
2400 // In Network mode, the client needs to know where the new branch is,
2401 // so we have to pass on this information via saveState.
2402 // TODO: Get rid of this positioning workaround
2403 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2404 sendData ("selectLatestAdded ()");
2405 sendData (QString("move %1").arg(ps));
2414 BranchItem* VymModel::addNewBranchBefore()
2416 BranchItem *newbi=NULL;
2417 BranchItem *selbi=getSelectedBranch();
2418 if (selbi && selbi->getType()==TreeItem::Branch)
2419 // We accept no MapCenter here, so we _have_ a parent
2421 //QPointF p=bo->getRelPos();
2424 // add below selection
2425 newbi=addNewBranchInt (selbi,-1);
2429 //newbi->move2RelPos (p);
2431 // Move selection to new branch
2432 relinkBranch (selbi,newbi,0);
2434 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2435 QString ("Add branch before %1").arg(getObjectName(selbi)));
2437 // FIXME-3 needed? reposition();
2438 // emitSelectionChanged(); FIXME-3
2444 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2450 // Do we need to update frame type?
2451 bool keepFrame=false;
2454 emit (layoutAboutToBeChanged() );
2455 BranchItem *branchpi=(BranchItem*)branch->parent();
2456 // Remove at current position
2457 int n=branch->childNum();
2459 /* FIXME-4 seg since 20091207, if ModelTest active. strange.
2460 // error occured if relinking branch to empty mainbranch
2461 cout<<"VM::relinkBranch:\n";
2462 cout<<" b="<<branch->getHeadingStd()<<endl;
2463 cout<<" dst="<<dst->getHeadingStd()<<endl;
2464 cout<<" pos="<<pos<<endl;
2465 cout<<" n1="<<n<<endl;
2467 beginRemoveRows (index(branchpi),n,n);
2468 branchpi->removeChild (n);
2471 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2473 // Append as last branch to dst
2474 if (dst->branchCount()==0)
2477 n=dst->getFirstBranch()->childNumber();
2478 beginInsertRows (index(dst),n+pos,n+pos);
2479 dst->insertBranch (pos,branch);
2482 // Correct type if necessesary
2483 if (branch->getType()==TreeItem::MapCenter)
2484 branch->setType(TreeItem::Branch);
2486 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2487 branch->updateStyles(keepFrame);
2489 emit (layoutChanged() );
2490 reposition(); // both for moveUp/Down and relinking
2491 if (dst->isScrolled() )
2494 branch->updateVisibility();
2503 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2507 emit (layoutAboutToBeChanged() );
2509 BranchItem *pi=(BranchItem*)(image->parent());
2510 QString oldParString=getSelectString (pi);
2511 // Remove at current position
2512 int n=image->childNum();
2513 beginRemoveRows (index(pi),n,n);
2514 pi->removeChild (n);
2518 QModelIndex dstix=index(dst);
2519 n=dst->getRowNumAppend (image);
2520 beginInsertRows (dstix,n,n+1);
2521 dst->appendChild (image);
2524 // Set new parent also for lmo
2525 if (image->getLMO() && dst->getLMO() )
2526 image->getLMO()->setParObj (dst->getLMO() );
2528 emit (layoutChanged() );
2531 QString("relinkTo (\"%1\")").arg(oldParString),
2533 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2534 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2540 void VymModel::cleanupLinks()
2542 // This probably could be done more elegant from destructor of a Link,
2543 // but somehow this resulted in strange segfaults deep in Qt and glibc...
2544 //qDebug ()<<"VM::cleanupLinks begin"<< "CUL="<<cleaningUpLinks;
2545 cleaningUpLinks=true;
2548 while (!xlinks_obsolete.isEmpty())
2550 l=xlinks_obsolete.takeFirst();
2551 xli=l->getBeginLinkItem();
2552 //qDebug()<<"VM::cleanupLinks a) l="<<l<<" xli="<<xli;
2553 if (xli) deleteItem (xli);
2554 xli=l->getEndLinkItem();
2555 //qDebug()<<"VM::cleanupLinks b) l="<<l<<" xli="<<xli;
2556 if (xli) deleteItem (xli);
2559 cleaningUpLinks=false;
2560 //qDebug ()<<"VM::cleanupLinks end";
2563 void VymModel::deleteSelection()
2565 BranchItem *selbi=getSelectedBranch();
2570 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2572 BranchItem *pi=(BranchItem*)(deleteItem (selbi));
2575 if (pi->isScrolled() && pi->branchCount()==0)
2578 emitDataHasChanged(pi);
2581 emitShowSelection();
2586 TreeItem *ti=getSelectedItem();
2589 { // Delete other item
2590 TreeItem *pi=ti->parent();
2592 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute||ti->getType()==TreeItem::XLink)
2594 saveStateChangingPart(
2598 QString("Delete %1").arg(getObjectName(ti))
2602 emitDataHasChanged (pi);
2605 emitShowSelection();
2607 qWarning ("VymmModel::deleteSelection() unknown type?!");
2611 void VymModel::deleteKeepChildren(bool saveStateFlag) //FIXME-3 does not work yet for mapcenters
2614 BranchItem *selbi=getSelectedBranch();
2618 // Don't use this on mapcenter
2619 if (selbi->depth()<2) return;
2621 pi=(BranchItem*)(selbi->parent());
2622 // Check if we have children at all to keep
2623 if (selbi->branchCount()==0)
2630 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2631 if (saveStateFlag) saveStateChangingPart(
2634 "deleteKeepChildren ()",
2635 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2638 QString sel=getSelectString(selbi);
2640 int pos=selbi->num();
2641 BranchItem *bi=selbi->getFirstBranch();
2644 relinkBranch (bi,pi,pos);
2645 bi=selbi->getFirstBranch();
2651 BranchObj *bo=getSelectedBranchObj();
2654 bo->move2RelPos (p);
2660 void VymModel::deleteChildren()
2663 BranchItem *selbi=getSelectedBranch();
2666 saveStateChangingPart(
2669 "deleteChildren ()",
2670 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2672 emit (layoutAboutToBeChanged() );
2674 QModelIndex ix=index (selbi);
2675 int n=selbi->branchCount()-1;
2676 beginRemoveRows (ix,0,n);
2677 removeRows (0,n+1,ix);
2679 if (selbi->isScrolled()) selbi->unScroll();
2680 emit (layoutChanged() );
2685 TreeItem* VymModel::deleteItem (TreeItem *ti)
2689 TreeItem *pi=ti->parent();
2690 //qDebug()<<"VM::deleteItem start ti="<<ti<<" "<<ti->getHeading()<<" pi="<<pi<<"="<<pi->getHeading();
2691 QModelIndex parentIndex=index(pi);
2693 emit (layoutAboutToBeChanged() );
2695 int n=ti->childNum();
2696 beginRemoveRows (parentIndex,n,n);
2697 removeRows (n,1,parentIndex);
2701 emit (layoutChanged() );
2702 //qDebug()<<"VM::deleteItem end ti="<<ti;
2703 if (!cleaningUpLinks) cleanupLinks();
2704 if (pi->depth()>=0) return pi;
2709 void VymModel::deleteLink(Link* l)
2711 int i=xlinks.indexOf(l);
2712 if (i>-1) xlinks_obsolete.append (xlinks.takeAt (i));
2715 void VymModel::clearItem (TreeItem *ti)
2719 QModelIndex parentIndex=index(ti);
2720 if (!parentIndex.isValid()) return;
2722 int n=ti->childCount();
2725 emit (layoutAboutToBeChanged() );
2727 beginRemoveRows (parentIndex,0,n-1);
2728 removeRows (0,n,parentIndex);
2732 emit (layoutChanged() );
2738 bool VymModel::scrollBranch(BranchItem *bi)
2742 if (bi->isScrolled()) return false;
2743 if (bi->branchCount()==0) return false;
2744 if (bi->depth()==0) return false;
2745 if (bi->toggleScroll())
2753 QString ("%1 ()").arg(u),
2755 QString ("%1 ()").arg(r),
2756 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2758 emitDataHasChanged(bi);
2759 emitSelectionChanged();
2760 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2767 bool VymModel::unscrollBranch(BranchItem *bi)
2771 if (!bi->isScrolled()) return false;
2772 if (bi->branchCount()==0) return false;
2773 if (bi->depth()==0) return false;
2774 if (bi->toggleScroll())
2782 QString ("%1 ()").arg(u),
2784 QString ("%1 ()").arg(r),
2785 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2787 emitDataHasChanged(bi);
2788 emitSelectionChanged();
2789 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2796 void VymModel::toggleScroll()
2798 BranchItem *bi=(BranchItem*)getSelectedBranch();
2799 if (bi && bi->isBranchLikeType() )
2801 if (bi->isScrolled())
2802 unscrollBranch (bi);
2806 // saveState & reposition are called in above functions
2809 void VymModel::unscrollChildren()
2811 BranchItem *selbi=getSelectedBranch();
2812 BranchItem *prev=NULL;
2813 BranchItem *cur=selbi;
2816 saveStateChangingPart(
2819 QString ("unscrollChildren ()"),
2820 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2824 if (cur->isScrolled())
2826 cur->toggleScroll();
2827 emitDataHasChanged (cur);
2829 cur=nextBranch (cur,prev,true,selbi);
2836 void VymModel::emitExpandAll()
2838 emit (expandAll() );
2841 void VymModel::emitExpandOneLevel()
2843 emit (expandOneLevel () );
2846 void VymModel::emitCollapseOneLevel()
2848 emit (collapseOneLevel () );
2851 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2853 BranchItem *bi=getSelectedBranch();
2857 if (bi->isActiveStandardFlag(name))
2869 QString("%1 (\"%2\")").arg(u).arg(name),
2871 QString("%1 (\"%2\")").arg(r).arg(name),
2872 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2873 bi->toggleStandardFlag (name, master);
2875 emitSelectionChanged();
2879 void VymModel::addFloatImage (const QPixmap &img)
2881 BranchItem *selbi=getSelectedBranch();
2884 ImageItem *ii=createImage (selbi);
2886 ii->setOriginalFilename("No original filename (image added by dropevent)");
2887 QString s=getSelectString(selbi);
2888 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2889 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2891 // FIXME-3 VM needed? scene()->update();
2896 void VymModel::colorBranch (QColor c)
2898 BranchItem *selbi=getSelectedBranch();
2903 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2905 QString ("colorBranch (\"%1\")").arg(c.name()),
2906 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2908 selbi->setHeadingColor(c); // color branch
2913 void VymModel::colorSubtree (QColor c)
2915 BranchItem *selbi=getSelectedBranch();
2918 saveStateChangingPart(
2921 QString ("colorSubtree (\"%1\")").arg(c.name()),
2922 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2924 BranchItem *prev=NULL;
2925 BranchItem *cur=selbi;
2928 cur->setHeadingColor(c); // color links, color children
2929 cur=nextBranch (cur,prev,true,selbi);
2935 QColor VymModel::getCurrentHeadingColor()
2937 BranchItem *selbi=getSelectedBranch();
2938 if (selbi) return selbi->getHeadingColor();
2940 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2946 void VymModel::editURL()
2948 TreeItem *selti=getSelectedItem();
2952 QString text = QInputDialog::getText(
2953 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2954 selti->getURL(), &ok, NULL);
2956 // user entered something and pressed OK
2961 void VymModel::editLocalURL()
2963 TreeItem *selti=getSelectedItem();
2966 QStringList filters;
2967 filters <<"All files (*)";
2968 filters << tr("Text","Filedialog") + " (*.txt)";
2969 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2970 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2971 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2972 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2973 fd->setFilters (filters);
2974 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2975 fd->setDirectory (lastFileDir);
2976 if (! selti->getVymLink().isEmpty() )
2977 fd->selectFile( selti->getURL() );
2980 if ( fd->exec() == QDialog::Accepted )
2982 lastFileDir=QDir (fd->directory().path());
2983 setURL (fd->selectedFile() );
2989 void VymModel::editHeading2URL()
2991 TreeItem *selti=getSelectedItem();
2993 setURL (selti->getHeading());
2996 void VymModel::editBugzilla2URL()
2998 TreeItem *selti=getSelectedItem();
3001 QString h=selti->getHeading();
3002 QRegExp rx("^(\\d+)");
3003 if (rx.indexIn(h) !=-1)
3004 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
3008 void VymModel::getBugzillaData()
3010 BranchItem *selbi=getSelectedBranch();
3013 QString url=selbi->getURL();
3016 QRegExp rx("(\\d+)");
3017 if (rx.indexIn(url) !=-1)
3019 QString bugID=rx.cap(1);
3020 qDebug()<< "VM::getBugzillaData bug="<<bugID;
3022 new BugAgent (selbi,bugID);
3028 void VymModel::editFATE2URL()
3030 TreeItem *selti=getSelectedItem();
3033 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
3036 "setURL (\""+selti->getURL()+"\")",
3038 "setURL (\""+url+"\")",
3039 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
3041 selti->setURL (url);
3042 // FIXME-4 updateActions();
3046 void VymModel::editVymLink()
3048 BranchItem *bi=getSelectedBranch();
3051 QStringList filters;
3052 filters <<"VYM map (*.vym)";
3053 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
3054 fd->setFilters (filters);
3055 fd->setCaption(vymName+" - " +tr("Link to another map"));
3056 fd->setDirectory (lastFileDir);
3057 if (! bi->getVymLink().isEmpty() )
3058 fd->selectFile( bi->getVymLink() );
3062 if ( fd->exec() == QDialog::Accepted )
3064 lastFileDir=QDir (fd->directory().path());
3067 "setVymLink (\""+bi->getVymLink()+"\")",
3069 "setVymLink (\""+fd->selectedFile()+"\")",
3070 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
3072 setVymLink (fd->selectedFile() );
3077 void VymModel::setVymLink (const QString &s)
3079 // Internal function, no saveState needed
3080 TreeItem *selti=getSelectedItem();
3083 selti->setVymLink(s);
3085 emitDataHasChanged (selti);
3086 emitShowSelection();
3090 void VymModel::deleteVymLink()
3092 BranchItem *bi=getSelectedBranch();
3097 "setVymLink (\""+bi->getVymLink()+"\")",
3099 "setVymLink (\"\")",
3100 QString("Unset vymlink of %1").arg(getObjectName(bi))
3102 bi->setVymLink ("" );
3108 QString VymModel::getVymLink()
3110 BranchItem *bi=getSelectedBranch();
3112 return bi->getVymLink();
3118 QStringList VymModel::getVymLinks()
3121 BranchItem *selbi=getSelectedBranch();
3122 BranchItem *cur=selbi;
3123 BranchItem *prev=NULL;
3126 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
3127 cur=nextBranch (cur,prev,true,selbi);
3133 void VymModel::followXLink(int i)
3136 BranchItem *selbi=getSelectedBranch();
3139 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
3140 if (selbi) select (selbi);
3144 void VymModel::editXLink(int i)
3146 BranchItem *selbi=getSelectedBranch();
3149 Link *l=selbi->getXLinkNum(i)->getLink();
3152 EditXLinkDialog dia;
3154 dia.setSelection(selbi);
3155 if (dia.exec() == QDialog::Accepted)
3157 if (dia.useSettingsGlobal() )
3159 setMapDefXLinkColor (l->getColor() );
3160 setMapDefXLinkWidth (l->getWidth() );
3162 if (dia.deleteXLink()) delete (l);
3168 //////////////////////////////////////////////
3170 //////////////////////////////////////////////
3172 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3174 TreeItem* selti=getSelectedItem();
3175 BranchItem *selbi=getSelectedBranch();
3180 QVariant returnValue="";
3182 // Split string s into command and parameters
3183 parser.parseAtom (atom);
3184 QString com=parser.getCommand();
3186 // External commands
3187 /////////////////////////////////////////////////////////////////////
3188 if (com=="addBranch")
3192 parser.setError (Aborted,"Nothing selected");
3193 } else if (! selbi )
3195 parser.setError (Aborted,"Type of selection is not a branch");
3200 if (parser.checkParCount(pl))
3202 if (parser.parCount()==0)
3206 n=parser.parInt (ok,0);
3207 if (ok ) addNewBranch (n);
3211 /////////////////////////////////////////////////////////////////////
3212 } else if (com=="addBranchBefore")
3216 parser.setError (Aborted,"Nothing selected");
3217 } else if (! selbi )
3219 parser.setError (Aborted,"Type of selection is not a branch");
3222 if (parser.parCount()==0)
3224 addNewBranchBefore ();
3227 /////////////////////////////////////////////////////////////////////
3228 } else if (com==QString("addMapCenter"))
3230 if (parser.checkParCount(2))
3232 x=parser.parDouble (ok,0);
3235 y=parser.parDouble (ok,1);
3236 if (ok) addMapCenter (QPointF(x,y));
3239 /////////////////////////////////////////////////////////////////////
3240 } else if (com==QString("addMapReplace"))
3244 parser.setError (Aborted,"Nothing selected");
3245 } else if (! selbi )
3247 parser.setError (Aborted,"Type of selection is not a branch");
3248 } else if (parser.checkParCount(1))
3250 //s=parser.parString (ok,0); // selection
3251 t=parser.parString (ok,0); // path to map
3252 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3253 loadMap (t,ImportReplace,false,VymMap,n);
3255 /////////////////////////////////////////////////////////////////////
3256 } else if (com==QString("addMapInsert"))
3258 if (parser.parCount()==2)
3263 parser.setError (Aborted,"Nothing selected");
3264 } else if (! selbi )
3266 parser.setError (Aborted,"Type of selection is not a branch");
3269 t=parser.parString (ok,0); // path to map
3270 n=parser.parInt(ok,1); // position
3271 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3272 loadMap (t,ImportAdd,false,VymMap,n);
3274 } else if (parser.parCount()==1)
3276 t=parser.parString (ok,0); // path to map
3277 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3278 loadMap (t,ImportAdd,false);
3280 parser.setError (Aborted,"Wrong number of parameters");
3281 /////////////////////////////////////////////////////////////////////
3282 } else if (com==QString("addXLink")) //FIXME-2 not ported yet to Link
3285 if (parser.parCount()>1)
3287 s=parser.parString (ok,0); // begin
3288 t=parser.parString (ok,1); // end
3289 BranchItem *begin=(BranchItem*)findBySelectString(s);
3290 BranchItem *end=(BranchItem*)findBySelectString(t);
3293 if (begin->isBranchLikeType() && end->isBranchLikeType())
3295 XLinkItem *xl=createXLink (begin,true);
3301 parser.setError (Aborted,"Failed to create xLink");
3304 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3307 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3309 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3311 /////////////////////////////////////////////////////////////////////
3312 } else if (com=="clearFlags")
3316 parser.setError (Aborted,"Nothing selected");
3317 } else if (! selbi )
3319 parser.setError (Aborted,"Type of selection is not a branch");
3320 } else if (parser.checkParCount(0))
3322 selbi->deactivateAllStandardFlags(); //FIXME-2 this probably should emitDataChanged and also setChanged. Similar all other direct changes should be done...
3324 /////////////////////////////////////////////////////////////////////
3325 } else if (com=="colorBranch")
3329 parser.setError (Aborted,"Nothing selected");
3330 } else if (! selbi )
3332 parser.setError (Aborted,"Type of selection is not a branch");
3333 } else if (parser.checkParCount(1))
3335 QColor c=parser.parColor (ok,0);
3336 if (ok) colorBranch (c);
3338 /////////////////////////////////////////////////////////////////////
3339 } else if (com=="colorSubtree")
3343 parser.setError (Aborted,"Nothing selected");
3344 } else if (! selbi )
3346 parser.setError (Aborted,"Type of selection is not a branch");
3347 } else if (parser.checkParCount(1))
3349 QColor c=parser.parColor (ok,0);
3350 if (ok) colorSubtree (c);
3352 /////////////////////////////////////////////////////////////////////
3353 } else if (com=="copy")
3357 parser.setError (Aborted,"Nothing selected");
3358 } else if ( selectionType()!=TreeItem::Branch &&
3359 selectionType()!=TreeItem::MapCenter &&
3360 selectionType()!=TreeItem::Image )
3362 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3363 } else if (parser.checkParCount(0))
3367 /////////////////////////////////////////////////////////////////////
3368 } else if (com=="cut")
3372 parser.setError (Aborted,"Nothing selected");
3373 } else if ( selectionType()!=TreeItem::Branch &&
3374 selectionType()!=TreeItem::MapCenter &&
3375 selectionType()!=TreeItem::Image )
3377 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3378 } else if (parser.checkParCount(0))
3382 /////////////////////////////////////////////////////////////////////
3383 } else if (com=="delete")
3387 parser.setError (Aborted,"Nothing selected");
3389 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3391 parser.setError (Aborted,"Type of selection is wrong.");
3394 else if (parser.checkParCount(0))
3398 /////////////////////////////////////////////////////////////////////
3399 } else if (com=="deleteKeepChildren")
3403 parser.setError (Aborted,"Nothing selected");
3404 } else if (! selbi )
3406 parser.setError (Aborted,"Type of selection is not a branch");
3407 } else if (parser.checkParCount(0))
3409 deleteKeepChildren();
3411 /////////////////////////////////////////////////////////////////////
3412 } else if (com=="deleteChildren")
3416 parser.setError (Aborted,"Nothing selected");
3419 parser.setError (Aborted,"Type of selection is not a branch");
3420 } else if (parser.checkParCount(0))
3424 /////////////////////////////////////////////////////////////////////
3425 } else if (com=="exportAO")
3429 if (parser.parCount()>=1)
3430 // Hey, we even have a filename
3431 fname=parser.parString(ok,0);
3434 parser.setError (Aborted,"Could not read filename");
3437 exportAO (fname,false);
3439 /////////////////////////////////////////////////////////////////////
3440 } else if (com=="exportASCII")
3444 if (parser.parCount()>=1)
3445 // Hey, we even have a filename
3446 fname=parser.parString(ok,0);
3449 parser.setError (Aborted,"Could not read filename");
3452 exportASCII (fname,false);
3454 /////////////////////////////////////////////////////////////////////
3455 } else if (com=="exportImage")
3459 if (parser.parCount()>=2)
3460 // Hey, we even have a filename
3461 fname=parser.parString(ok,0);
3464 parser.setError (Aborted,"Could not read filename");
3467 QString format="PNG";
3468 if (parser.parCount()>=2)
3470 format=parser.parString(ok,1);
3472 exportImage (fname,false,format);
3474 /////////////////////////////////////////////////////////////////////
3475 } else if (com=="exportXML")
3479 if (parser.parCount()>=2)
3480 // Hey, we even have a filename
3481 fname=parser.parString(ok,1);
3484 parser.setError (Aborted,"Could not read filename");
3487 exportXML (fname,false);
3489 /////////////////////////////////////////////////////////////////////
3490 } else if (com=="getHeading")
3494 parser.setError (Aborted,"Nothing selected");
3495 } else if (parser.checkParCount(0))
3496 returnValue=selti->getHeading();
3497 /////////////////////////////////////////////////////////////////////
3498 } else if (com=="importDir")
3502 parser.setError (Aborted,"Nothing selected");
3503 } else if (! selbi )
3505 parser.setError (Aborted,"Type of selection is not a branch");
3506 } else if (parser.checkParCount(1))
3508 s=parser.parString(ok,0);
3509 if (ok) importDirInt(s);
3511 /////////////////////////////////////////////////////////////////////
3512 } else if (com=="relinkTo")
3516 parser.setError (Aborted,"Nothing selected");
3519 if (parser.checkParCount(4))
3521 // 0 selectstring of parent
3522 // 1 num in parent (for branches)
3523 // 2,3 x,y of mainbranch or mapcenter
3524 s=parser.parString(ok,0);
3525 TreeItem *dst=findBySelectString (s);
3528 if (dst->getType()==TreeItem::Branch)
3530 // Get number in parent
3531 n=parser.parInt (ok,1);
3534 relinkBranch (selbi,(BranchItem*)dst,n);
3535 emitSelectionChanged();
3537 } else if (dst->getType()==TreeItem::MapCenter)
3539 relinkBranch (selbi,(BranchItem*)dst);
3540 // Get coordinates of mainbranch
3541 x=parser.parDouble(ok,2);
3544 y=parser.parDouble(ok,3);
3547 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3548 emitSelectionChanged();
3554 } else if ( selti->getType() == TreeItem::Image)
3556 if (parser.checkParCount(1))
3558 // 0 selectstring of parent
3559 s=parser.parString(ok,0);
3560 TreeItem *dst=findBySelectString (s);
3563 if (dst->isBranchLikeType())
3564 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3566 parser.setError (Aborted,"Destination is not a branch");
3569 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3570 /////////////////////////////////////////////////////////////////////
3571 } else if (com=="loadImage")
3575 parser.setError (Aborted,"Nothing selected");
3576 } else if (! selbi )
3578 parser.setError (Aborted,"Type of selection is not a branch");
3579 } else if (parser.checkParCount(1))
3581 s=parser.parString(ok,0);
3582 if (ok) loadFloatImageInt (selbi,s);
3584 /////////////////////////////////////////////////////////////////////
3585 } else if (com=="loadNote")
3589 parser.setError (Aborted,"Nothing selected");
3590 } else if (! selbi )
3592 parser.setError (Aborted,"Type of selection is not a branch");
3593 } else if (parser.checkParCount(1))
3595 s=parser.parString(ok,0);
3596 if (ok) loadNote (s);
3598 /////////////////////////////////////////////////////////////////////
3599 } else if (com=="moveUp")
3603 parser.setError (Aborted,"Nothing selected");
3604 } else if (! selbi )
3606 parser.setError (Aborted,"Type of selection is not a branch");
3607 } else if (parser.checkParCount(0))
3611 /////////////////////////////////////////////////////////////////////
3612 } else if (com=="moveDown")
3616 parser.setError (Aborted,"Nothing selected");
3617 } else if (! selbi )
3619 parser.setError (Aborted,"Type of selection is not a branch");
3620 } else if (parser.checkParCount(0))
3624 /////////////////////////////////////////////////////////////////////
3625 } else if (com=="move")
3629 parser.setError (Aborted,"Nothing selected");
3630 } else if ( selectionType()!=TreeItem::Branch &&
3631 selectionType()!=TreeItem::MapCenter &&
3632 selectionType()!=TreeItem::Image )
3634 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3635 } else if (parser.checkParCount(2))
3637 x=parser.parDouble (ok,0);
3640 y=parser.parDouble (ok,1);
3644 /////////////////////////////////////////////////////////////////////
3645 } else if (com=="moveRel")
3649 parser.setError (Aborted,"Nothing selected");
3650 } else if ( selectionType()!=TreeItem::Branch &&
3651 selectionType()!=TreeItem::MapCenter &&
3652 selectionType()!=TreeItem::Image )
3654 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3655 } else if (parser.checkParCount(2))
3657 x=parser.parDouble (ok,0);
3660 y=parser.parDouble (ok,1);
3661 if (ok) moveRel (x,y);
3664 /////////////////////////////////////////////////////////////////////
3665 } else if (com=="nop")
3667 /////////////////////////////////////////////////////////////////////
3668 } else if (com=="paste")
3672 parser.setError (Aborted,"Nothing selected");
3673 } else if (! selbi )
3675 parser.setError (Aborted,"Type of selection is not a branch");
3676 } else if (parser.checkParCount(1))
3678 n=parser.parInt (ok,0);
3679 if (ok) pasteNoSave(n);
3681 /////////////////////////////////////////////////////////////////////
3682 } else if (com=="qa")
3686 parser.setError (Aborted,"Nothing selected");
3687 } else if (! selbi )
3689 parser.setError (Aborted,"Type of selection is not a branch");
3690 } else if (parser.checkParCount(4))
3693 c=parser.parString (ok,0);
3696 parser.setError (Aborted,"No comment given");
3699 s=parser.parString (ok,1);
3702 parser.setError (Aborted,"First parameter is not a string");
3705 t=parser.parString (ok,2);
3708 parser.setError (Aborted,"Condition is not a string");
3711 u=parser.parString (ok,3);
3714 parser.setError (Aborted,"Third parameter is not a string");
3719 parser.setError (Aborted,"Unknown type: "+s);
3724 parser.setError (Aborted,"Unknown operator: "+t);
3729 parser.setError (Aborted,"Type of selection is not a branch");
3732 if (selbi->getHeading() == u)
3734 cout << "PASSED: " << qPrintable (c) << endl;
3737 cout << "FAILED: " << qPrintable (c) << endl;
3747 /////////////////////////////////////////////////////////////////////
3748 } else if (com=="saveImage")
3750 ImageItem *ii=getSelectedImage();
3753 parser.setError (Aborted,"No image selected");
3754 } else if (parser.checkParCount(2))
3756 s=parser.parString(ok,0);
3759 t=parser.parString(ok,1);
3760 if (ok) saveFloatImageInt (ii,t,s);
3763 /////////////////////////////////////////////////////////////////////
3764 } else if (com=="saveNote")
3768 parser.setError (Aborted,"Nothing selected");
3769 } else if (! selbi )
3771 parser.setError (Aborted,"Type of selection is not a branch");
3772 } else if (parser.checkParCount(1))
3774 s=parser.parString(ok,0);
3775 if (ok) saveNote (s);
3777 /////////////////////////////////////////////////////////////////////
3778 } else if (com=="scroll")
3782 parser.setError (Aborted,"Nothing selected");
3783 } else if (! selbi )
3785 parser.setError (Aborted,"Type of selection is not a branch");
3786 } else if (parser.checkParCount(0))
3788 if (!scrollBranch (selbi))
3789 parser.setError (Aborted,"Could not scroll branch");
3791 /////////////////////////////////////////////////////////////////////
3792 } else if (com=="select")
3794 if (parser.checkParCount(1))
3796 s=parser.parString(ok,0);
3799 /////////////////////////////////////////////////////////////////////
3800 } else if (com=="selectLastBranch")
3804 parser.setError (Aborted,"Nothing selected");
3805 } else if (! selbi )
3807 parser.setError (Aborted,"Type of selection is not a branch");
3808 } else if (parser.checkParCount(0))
3810 BranchItem *bi=selbi->getLastBranch();
3812 parser.setError (Aborted,"Could not select last branch");
3813 select (bi); // FIXME-3 was selectInt
3816 /////////////////////////////////////////////////////////////////////
3817 } else /* FIXME-2 if (com=="selectLastImage")
3821 parser.setError (Aborted,"Nothing selected");
3822 } else if (! selbi )
3824 parser.setError (Aborted,"Type of selection is not a branch");
3825 } else if (parser.checkParCount(0))
3827 FloatImageObj *fio=selb->getLastFloatImage();
3829 parser.setError (Aborted,"Could not select last image");
3830 select (fio); // FIXME-3 was selectInt
3833 /////////////////////////////////////////////////////////////////////
3834 } else */ if (com=="selectLatestAdded")
3836 if (!latestAddedItem)
3838 parser.setError (Aborted,"No latest added object");
3841 if (!select (latestAddedItem))
3842 parser.setError (Aborted,"Could not select latest added object ");
3844 /////////////////////////////////////////////////////////////////////
3845 } else if (com=="setFlag")
3849 parser.setError (Aborted,"Nothing selected");
3850 } else if (! selbi )
3852 parser.setError (Aborted,"Type of selection is not a branch");
3853 } else if (parser.checkParCount(1))
3855 s=parser.parString(ok,0);
3857 selbi->activateStandardFlag(s);
3859 /////////////////////////////////////////////////////////////////////
3860 } else if (com=="setFrameType")
3862 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3864 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3866 else if (parser.checkParCount(1))
3868 s=parser.parString(ok,0);
3869 if (ok) setFrameType (s);
3871 /////////////////////////////////////////////////////////////////////
3872 } else if (com=="setFramePenColor")
3874 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3876 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3878 else if (parser.checkParCount(1))
3880 QColor c=parser.parColor(ok,0);
3881 if (ok) setFramePenColor (c);
3883 /////////////////////////////////////////////////////////////////////
3884 } else if (com=="setFrameBrushColor")
3886 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3888 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3890 else if (parser.checkParCount(1))
3892 QColor c=parser.parColor(ok,0);
3893 if (ok) setFrameBrushColor (c);
3895 /////////////////////////////////////////////////////////////////////
3896 } else if (com=="setFramePadding")
3898 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3900 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3902 else if (parser.checkParCount(1))
3904 n=parser.parInt(ok,0);
3905 if (ok) setFramePadding(n);
3907 /////////////////////////////////////////////////////////////////////
3908 } else if (com=="setFrameBorderWidth")
3910 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3912 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3914 else if (parser.checkParCount(1))
3916 n=parser.parInt(ok,0);
3917 if (ok) setFrameBorderWidth (n);
3919 /////////////////////////////////////////////////////////////////////
3920 /* FIXME-2 else if (com=="setFrameType")
3924 parser.setError (Aborted,"Nothing selected");
3927 parser.setError (Aborted,"Type of selection is not a branch");
3928 } else if (parser.checkParCount(1))
3930 s=parser.parString(ok,0);
3934 /////////////////////////////////////////////////////////////////////
3936 /////////////////////////////////////////////////////////////////////
3937 } else if (com=="setHeading")
3941 parser.setError (Aborted,"Nothing selected");
3942 } else if (! selbi )
3944 parser.setError (Aborted,"Type of selection is not a branch");
3945 } else if (parser.checkParCount(1))
3947 s=parser.parString (ok,0);
3951 /////////////////////////////////////////////////////////////////////
3952 } else if (com=="setHideExport")
3956 parser.setError (Aborted,"Nothing selected");
3957 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3959 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3960 } else if (parser.checkParCount(1))
3962 b=parser.parBool(ok,0);
3963 if (ok) setHideExport (b);
3965 /////////////////////////////////////////////////////////////////////
3966 } else if (com=="setIncludeImagesHorizontally")
3970 parser.setError (Aborted,"Nothing selected");
3973 parser.setError (Aborted,"Type of selection is not a branch");
3974 } else if (parser.checkParCount(1))
3976 b=parser.parBool(ok,0);
3977 if (ok) setIncludeImagesHor(b);
3979 /////////////////////////////////////////////////////////////////////
3980 } else if (com=="setIncludeImagesVertically")
3984 parser.setError (Aborted,"Nothing selected");
3987 parser.setError (Aborted,"Type of selection is not a branch");
3988 } else if (parser.checkParCount(1))
3990 b=parser.parBool(ok,0);
3991 if (ok) setIncludeImagesVer(b);
3993 /////////////////////////////////////////////////////////////////////
3994 } else if (com=="setHideLinkUnselected")
3998 parser.setError (Aborted,"Nothing selected");
3999 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
4001 parser.setError (Aborted,"Type of selection does not allow hiding the link");
4002 } else if (parser.checkParCount(1))
4004 b=parser.parBool(ok,0);
4005 if (ok) setHideLinkUnselected(b);
4007 /////////////////////////////////////////////////////////////////////
4008 } else if (com=="setMapAuthor")
4010 if (parser.checkParCount(1))
4012 s=parser.parString(ok,0);
4013 if (ok) setAuthor (s);
4015 /////////////////////////////////////////////////////////////////////
4016 } else if (com=="setMapComment")
4018 if (parser.checkParCount(1))
4020 s=parser.parString(ok,0);
4021 if (ok) setComment(s);
4023 /////////////////////////////////////////////////////////////////////
4024 } else if (com=="setMapBackgroundColor")
4028 parser.setError (Aborted,"Nothing selected");
4029 } else if (! selbi )
4031 parser.setError (Aborted,"Type of selection is not a branch");
4032 } else if (parser.checkParCount(1))
4034 QColor c=parser.parColor (ok,0);
4035 if (ok) setMapBackgroundColor (c);
4037 /////////////////////////////////////////////////////////////////////
4038 } else if (com=="setMapDefLinkColor")
4042 parser.setError (Aborted,"Nothing selected");
4043 } else if (! selbi )
4045 parser.setError (Aborted,"Type of selection is not a branch");
4046 } else if (parser.checkParCount(1))
4048 QColor c=parser.parColor (ok,0);
4049 if (ok) setMapDefLinkColor (c);
4051 /////////////////////////////////////////////////////////////////////
4052 } else if (com=="setMapLinkStyle")
4054 if (parser.checkParCount(1))
4056 s=parser.parString (ok,0);
4057 if (ok) setMapLinkStyle(s);
4059 /////////////////////////////////////////////////////////////////////
4060 } else if (com=="setNote")
4064 parser.setError (Aborted,"Nothing selected");
4065 } else if (! selbi )
4067 parser.setError (Aborted,"Type of selection is not a branch");
4068 } else if (parser.checkParCount(1))
4070 s=parser.parString (ok,0);
4074 /////////////////////////////////////////////////////////////////////
4075 } else if (com=="setSelectionColor")
4077 if (parser.checkParCount(1))
4079 QColor c=parser.parColor (ok,0);
4080 if (ok) setSelectionColorInt (c);
4082 /////////////////////////////////////////////////////////////////////
4083 } else if (com=="setURL")
4087 parser.setError (Aborted,"Nothing selected");
4088 } else if (! selbi )
4090 parser.setError (Aborted,"Type of selection is not a branch");
4091 } else if (parser.checkParCount(1))
4093 s=parser.parString (ok,0);
4096 /////////////////////////////////////////////////////////////////////
4097 } else if (com=="setVymLink")
4101 parser.setError (Aborted,"Nothing selected");
4102 } else if (! selbi )
4104 parser.setError (Aborted,"Type of selection is not a branch");
4105 } else if (parser.checkParCount(1))
4107 s=parser.parString (ok,0);
4108 if (ok) setVymLink(s);
4110 } else if (com=="sortChildren")
4114 parser.setError (Aborted,"Nothing selected");
4115 } else if (! selbi )
4117 parser.setError (Aborted,"Type of selection is not a branch");
4118 } else if (parser.checkParCount(0))
4121 } else if (parser.checkParCount(1))
4123 b=parser.parBool(ok,0);
4124 if (ok) sortChildren(b);
4126 /////////////////////////////////////////////////////////////////////
4127 } else if (com=="toggleFlag")
4131 parser.setError (Aborted,"Nothing selected");
4132 } else if (! selbi )
4134 parser.setError (Aborted,"Type of selection is not a branch");
4135 } else if (parser.checkParCount(1))
4137 s=parser.parString(ok,0);
4139 selbi->toggleStandardFlag(s);
4141 /////////////////////////////////////////////////////////////////////
4142 } else if (com=="unscroll")
4146 parser.setError (Aborted,"Nothing selected");
4147 } else if (! selbi )
4149 parser.setError (Aborted,"Type of selection is not a branch");
4150 } else if (parser.checkParCount(0))
4152 if (!unscrollBranch (selbi))
4153 parser.setError (Aborted,"Could not unscroll branch");
4155 /////////////////////////////////////////////////////////////////////
4156 } else if (com=="unscrollChildren")
4160 parser.setError (Aborted,"Nothing selected");
4161 } else if (! selbi )
4163 parser.setError (Aborted,"Type of selection is not a branch");
4164 } else if (parser.checkParCount(0))
4166 unscrollChildren ();
4168 /////////////////////////////////////////////////////////////////////
4169 } else if (com=="unsetFlag")
4173 parser.setError (Aborted,"Nothing selected");
4174 } else if (! selbi )
4176 parser.setError (Aborted,"Type of selection is not a branch");
4177 } else if (parser.checkParCount(1))
4179 s=parser.parString(ok,0);
4181 selbi->deactivateStandardFlag(s);
4184 parser.setError (Aborted,"Unknown command");
4187 if (parser.errorLevel()==NoError)
4195 // TODO Error handling
4196 qWarning("VymModel::parseAtom: Error!");
4198 qWarning(parser.errorMessage());
4200 errorMsg=parser.errorMessage();
4201 returnValue=errorMsg;
4206 QVariant VymModel::runScript (const QString &script)
4208 parser.setScript (script);
4213 while (parser.next() && noErr)
4215 r=parseAtom(parser.getAtom(),noErr,errMsg);
4216 if (!noErr) //FIXME-3 need dialog box here
4217 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4222 void VymModel::setExportMode (bool b)
4224 // should be called before and after exports
4225 // depending on the settings
4226 if (b && settings.value("/export/useHideExport","true")=="true")
4227 setHideTmpMode (TreeItem::HideExport);
4229 setHideTmpMode (TreeItem::HideNone);
4232 void VymModel::exportImage(QString fname, bool askName, QString format)
4236 fname=getMapName()+".png";
4243 QFileDialog *fd=new QFileDialog (NULL);
4244 fd->setCaption (tr("Export map as image"));
4245 fd->setDirectory (lastImageDir);
4246 fd->setFileMode(QFileDialog::AnyFile);
4247 fd->setFilters (imageIO.getFilters() );
4250 fl=fd->selectedFiles();
4252 format=imageIO.getType(fd->selectedFilter());
4256 setExportMode (true);
4257 mapEditor->getScene()->update(); // FIXME-3 check this...
4258 QImage img (mapEditor->getImage()); //FIXME-3 calls getTotalBBox, but also in ExportHTML::doExport()
4259 img.save(fname, format);
4260 setExportMode (false);
4264 void VymModel::exportXML(QString dir, bool askForName)
4268 dir=browseDirectory(NULL,tr("Export XML to directory"));
4269 if (dir =="" && !reallyWriteDirectory(dir) )
4273 // Hide stuff during export, if settings want this
4274 setExportMode (true);
4276 // Create subdirectories
4279 // write to directory //FIXME-4 check totalBBox here...
4280 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4283 file.setName ( dir + "/"+mapName+".xml");
4284 if ( !file.open( QIODevice::WriteOnly ) )
4286 // This should neverever happen
4287 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4291 // Write it finally, and write in UTF8, no matter what
4292 QTextStream ts( &file );
4293 ts.setEncoding (QTextStream::UnicodeUTF8);
4297 // Now write image, too
4298 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4300 setExportMode (false);
4303 void VymModel::exportAO (QString fname,bool askName)
4308 ex.setFile (mapName+".txt");
4314 //ex.addFilter ("TXT (*.txt)");
4315 ex.setDir(lastImageDir);
4316 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4321 setExportMode(true);
4323 setExportMode(false);
4327 void VymModel::exportASCII(QString fname,bool askName)
4332 ex.setFile (mapName+".txt");
4338 //ex.addFilter ("TXT (*.txt)");
4339 ex.setDir(lastImageDir);
4340 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4345 setExportMode(true);
4347 setExportMode(false);
4351 void VymModel::exportHTML (const QString &dir, bool useDialog)
4353 ExportHTML ex (this);
4355 ex.doExport(useDialog);
4358 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4363 if (ex.setConfigFile(cf))
4365 setExportMode (true);
4366 ex.exportPresentation();
4367 setExportMode (false);
4374 //////////////////////////////////////////////
4376 //////////////////////////////////////////////
4378 void VymModel::registerEditor(QWidget *me)
4380 mapEditor=(MapEditor*)me;
4383 void VymModel::unregisterEditor(QWidget *)
4388 void VymModel::setMapZoomFactor (const double &d)
4393 void VymModel::setContextPos(QPointF p)
4398 void VymModel::unsetContextPos()
4400 contextPos=QPointF();
4403 void VymModel::updateNoteFlag()
4405 TreeItem *selti=getSelectedItem();
4414 if (textEditor->isEmpty())
4417 selti->setNote (textEditor->getText());
4418 emitDataHasChanged(selti);
4422 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4424 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4425 if (blockReposition) return;
4428 for (int i=0;i<rootItem->branchCount(); i++)
4430 bo=rootItem->getBranchObjNum(i);
4432 bo->reposition(); // for positioning heading
4434 qDebug()<<"VM::reposition bo=0";
4436 //emitSelectionChanged();
4440 void VymModel::setMapLinkStyle (const QString & s)
4445 case LinkableMapObj::Line :
4448 case LinkableMapObj::Parabel:
4449 snow="StyleParabel";
4451 case LinkableMapObj::PolyLine:
4452 snow="StylePolyLine";
4454 case LinkableMapObj::PolyParabel:
4455 snow="StylePolyParabel";
4458 snow="UndefinedStyle";
4463 QString("setMapLinkStyle (\"%1\")").arg(s),
4464 QString("setMapLinkStyle (\"%1\")").arg(snow),
4465 QString("Set map link style (\"%1\")").arg(s)
4469 linkstyle=LinkableMapObj::Line;
4470 else if (s=="StyleParabel")
4471 linkstyle=LinkableMapObj::Parabel;
4472 else if (s=="StylePolyLine")
4473 linkstyle=LinkableMapObj::PolyLine;
4474 else if (s=="StylePolyParabel")
4475 linkstyle=LinkableMapObj::PolyParabel;
4477 linkstyle=LinkableMapObj::UndefinedStyle;
4479 BranchItem *cur=NULL;
4480 BranchItem *prev=NULL;
4482 nextBranch (cur,prev);
4485 bo=(BranchObj*)(cur->getLMO() );
4486 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4487 cur=nextBranch(cur,prev);
4492 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4497 uint VymModel::getID()
4502 void VymModel::setMapDefLinkColor(QColor col)
4504 if ( !col.isValid() ) return;
4506 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4507 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4508 QString("Set map link color to %1").arg(col.name())
4512 BranchItem *cur=NULL;
4513 BranchItem *prev=NULL;
4515 cur=nextBranch(cur,prev);
4518 bo=(BranchObj*)(cur->getLMO() );
4520 nextBranch(cur,prev);
4525 void VymModel::setMapLinkColorHintInt()
4527 // called from setMapLinkColorHint(lch) or at end of parse
4528 BranchItem *cur=NULL;
4529 BranchItem *prev=NULL;
4531 cur=nextBranch(cur,prev);
4534 bo=(BranchObj*)(cur->getLMO() );
4536 cur=nextBranch(cur,prev);
4540 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4543 setMapLinkColorHintInt();
4546 void VymModel::toggleMapLinkColorHint()
4548 if (linkcolorhint==LinkableMapObj::HeadingColor)
4549 linkcolorhint=LinkableMapObj::DefaultColor;
4551 linkcolorhint=LinkableMapObj::HeadingColor;
4552 BranchItem *cur=NULL;
4553 BranchItem *prev=NULL;
4555 cur=nextBranch(cur,prev);
4558 bo=(BranchObj*)(cur->getLMO() );
4560 nextBranch(cur,prev);
4564 void VymModel::selectMapBackgroundImage () // FIXME-3 for using background image: view.setCacheMode(QGraphicsView::CacheBackground); Also this belongs into ME
4566 Q3FileDialog *fd=new Q3FileDialog( NULL);
4567 fd->setMode (Q3FileDialog::ExistingFile);
4568 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4569 ImagePreview *p =new ImagePreview (fd);
4570 fd->setContentsPreviewEnabled( TRUE );
4571 fd->setContentsPreview( p, p );
4572 fd->setPreviewMode( Q3FileDialog::Contents );
4573 fd->setCaption(vymName+" - " +tr("Load background image"));
4574 fd->setDir (lastImageDir);
4577 if ( fd->exec() == QDialog::Accepted )
4579 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4580 lastImageDir=QDir (fd->dirPath());
4581 setMapBackgroundImage (fd->selectedFile());
4585 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4587 QColor oldcol=mapScene->backgroundBrush().color();
4591 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4593 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4594 QString("Set background color of map to %1").arg(col.name()));
4597 brush.setTextureImage (QPixmap (fn));
4598 mapScene->setBackgroundBrush(brush);
4601 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4603 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4604 if ( !col.isValid() ) return;
4605 setMapBackgroundColor( col );
4609 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4611 QColor oldcol=mapScene->backgroundBrush().color();
4613 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4614 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4615 QString("Set background color of map to %1").arg(col.name()));
4616 mapScene->setBackgroundBrush(col);
4619 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4621 return mapScene->backgroundBrush().color();
4625 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4627 return linkcolorhint;
4630 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4632 return defLinkColor;
4635 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4640 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4642 return defXLinkColor;
4645 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4650 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4652 return defXLinkWidth;
4655 void VymModel::move(const double &x, const double &y)
4658 MapItem *seli = (MapItem*)getSelectedItem();
4659 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4661 LinkableMapObj *lmo=seli->getLMO();
4664 QPointF ap(lmo->getAbsPos());
4668 QString ps=qpointFToString(ap);
4669 QString s=getSelectString(seli);
4672 s, "move "+qpointFToString(to),
4673 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4676 emitSelectionChanged();
4682 void VymModel::moveRel (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 rp(lmo->getRelPos());
4695 QString ps=qpointFToString (lmo->getRelPos());
4696 QString s=getSelectString(seli);
4699 s, "moveRel "+qpointFToString(to),
4700 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4701 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4703 lmo->updateLinkGeometry();
4704 emitSelectionChanged();
4711 void VymModel::animate()
4713 animationTimer->stop();
4716 while (i<animObjList.size() )
4718 bo=(BranchObj*)animObjList.at(i);
4723 animObjList.removeAt(i);
4730 QItemSelection sel=selModel->selection();
4731 emit (selectionChanged(sel,sel));
4734 if (!animObjList.isEmpty()) animationTimer->start();
4738 void VymModel::startAnimation(BranchObj *bo, const QPointF &v)
4742 if (bo->getUseRelPos())
4743 startAnimation (bo,bo->getRelPos(),bo->getRelPos()+v);
4745 startAnimation (bo,bo->getAbsPos(),bo->getAbsPos()+v);
4748 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4750 if (start==dest) return;
4751 if (bo && bo->getTreeItem()->depth()>=0)
4754 ap.setStart (start);
4756 ap.setTicks (animationTicks);
4757 ap.setAnimated (true);
4758 bo->setAnimation (ap);
4759 if (!animObjList.contains(bo))
4760 animObjList.append( bo );
4761 animationTimer->setSingleShot (true);
4762 animationTimer->start(animationInterval);
4766 void VymModel::stopAnimation (MapObj *mo)
4768 int i=animObjList.indexOf(mo);
4770 animObjList.removeAt (i);
4773 void VymModel::stopAllAnimation ()
4777 while (i<animObjList.size() )
4779 bo=(BranchObj*)animObjList.at(i);
4780 bo->stopAnimation();
4781 bo->requestReposition();
4787 void VymModel::sendSelection()
4789 if (netstate!=Server) return;
4790 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4793 void VymModel::newServer()
4797 tcpServer = new QTcpServer(this);
4798 if (!tcpServer->listen(QHostAddress::Any,port)) {
4799 QMessageBox::critical(NULL, "vym server",
4800 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4801 //FIXME-3 needed? we are no widget any longer... close();
4804 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4806 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4809 void VymModel::connectToServer()
4812 server="salam.suse.de";
4814 clientSocket = new QTcpSocket (this);
4815 clientSocket->abort();
4816 clientSocket->connectToHost(server ,port);
4817 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4818 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4819 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4821 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4826 void VymModel::newClient()
4828 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4829 connect(newClient, SIGNAL(disconnected()),
4830 newClient, SLOT(deleteLater()));
4832 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4834 clientList.append (newClient);
4838 void VymModel::sendData(const QString &s)
4840 if (clientList.size()==0) return;
4842 // Create bytearray to send
4844 QDataStream out(&block, QIODevice::WriteOnly);
4845 out.setVersion(QDataStream::Qt_4_0);
4847 // Reserve some space for blocksize
4850 // Write sendCounter
4851 out << sendCounter++;
4856 // Go back and write blocksize so far
4857 out.device()->seek(0);
4858 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4862 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4864 for (int i=0; i<clientList.size(); ++i)
4866 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4867 clientList.at(i)->write (block);
4871 void VymModel::readData ()
4873 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4876 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4880 QDataStream in(clientSocket);
4881 in.setVersion(QDataStream::Qt_4_0);
4889 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4892 parseAtom (t,noErr,errMsg);
4898 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4900 switch (socketError) {
4901 case QAbstractSocket::RemoteHostClosedError:
4903 case QAbstractSocket::HostNotFoundError:
4904 QMessageBox::information(NULL, vymName +" Network client",
4905 "The host was not found. Please check the "
4906 "host name and port settings.");
4908 case QAbstractSocket::ConnectionRefusedError:
4909 QMessageBox::information(NULL, vymName + " Network client",
4910 "The connection was refused by the peer. "
4911 "Make sure the fortune server is running, "
4912 "and check that the host name and port "
4913 "settings are correct.");
4916 QMessageBox::information(NULL, vymName + " Network client",
4917 QString("The following error occurred: %1.")
4918 .arg(clientSocket->errorString()));
4922 /* FIXME-3 Playing with DBUS...
4923 QDBusVariant VymModel::query (const QString &query)
4925 TreeItem *selti=getSelectedItem();
4927 return QDBusVariant (selti->getHeading());
4929 return QDBusVariant ("Nothing selected.");
4933 void VymModel::testslot() //FIXME-3 Playing with DBUS
4935 cout << "VM::testslot called\n";
4938 void VymModel::selectMapSelectionColor()
4940 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4941 setSelectionColor (col);
4944 void VymModel::setSelectionColorInt (QColor col)
4946 if ( !col.isValid() ) return;
4948 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4949 QString("setSelectionColor (%1)").arg(col.name()),
4950 QString("Set color of selection box to %1").arg(col.name())
4953 mapEditor->setSelectionColor (col);
4956 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4958 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4959 //FIXME-3 emitShowSelection();
4963 void VymModel::emitSelectionChanged()
4965 QItemSelection newsel=selModel->selection();
4966 emitSelectionChanged (newsel);
4969 void VymModel::setSelectionColor(QColor col)
4971 if ( !col.isValid() ) return;
4973 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4974 QString("setSelectionColor (%1)").arg(col.name()),
4975 QString("Set color of selection box to %1").arg(col.name())
4977 setSelectionColorInt (col);
4980 QColor VymModel::getSelectionColor()
4982 return mapEditor->getSelectionColor();
4985 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
4988 for (int i=0;i<rootItem->branchCount();i++)
4989 rootItem->getBranchNum(i)->setHideTmp (mode);
4991 if (mode==TreeItem::HideExport)
4997 //////////////////////////////////////////////
4998 // Selection related
4999 //////////////////////////////////////////////
5001 void VymModel::setSelectionModel (QItemSelectionModel *sm)
5006 QItemSelectionModel* VymModel::getSelectionModel()
5011 void VymModel::setSelectionBlocked (bool b)
5016 bool VymModel::isSelectionBlocked()
5018 return selectionBlocked;
5021 bool VymModel::select ()
5023 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
5026 bool VymModel::select (const QString &s)
5033 TreeItem *ti=findBySelectString(s);
5034 if (ti) return select (index(ti));
5038 bool VymModel::select (LinkableMapObj *lmo)
5040 QItemSelection oldsel=selModel->selection();
5043 return select (index (lmo->getTreeItem()) );
5048 bool VymModel::select (TreeItem *ti)
5050 if (ti) return select (index(ti));
5054 bool VymModel::select (TreeItem *ti, int i)
5056 if (!ti || i<0) return false;
5057 if (select (index(ti)))
5059 qDebug ()<<"VM::select with index: "<<i<<" Trying to find text in note ";
5060 QTextCursor c=textEditor->getTextCursor();
5061 c.setPosition (i-1,QTextCursor::MoveAnchor);
5062 textEditor->setTextCursor (c);
5064 qDebug ()<<"VM::select with index: "<<i<<" Giving up to find text in note ";
5068 bool VymModel::select (const QModelIndex &index)
5070 if (index.isValid() )
5072 selModel->select (index,QItemSelectionModel::ClearAndSelect );
5073 BranchItem *bi=getSelectedBranch();
5074 if (bi) bi->setLastSelectedBranch();
5080 void VymModel::unselect()
5082 if (!selModel->selectedIndexes().isEmpty())
5084 lastSelectString=getSelectString();
5085 selModel->clearSelection();
5089 bool VymModel::reselect()
5091 return select (lastSelectString);
5094 void VymModel::emitShowSelection()
5096 if (!blockReposition)
5097 emit (showSelection() );
5100 void VymModel::emitNoteHasChanged (TreeItem *ti)
5102 QModelIndex ix=index(ti);
5103 emit (noteHasChanged (ix) );
5106 void VymModel::emitDataHasChanged (TreeItem *ti)
5108 QModelIndex ix=index(ti);
5109 emit (dataChanged (ix,ix) );
5112 void VymModel::emitUpdateLayout()
5114 if (settings.value("/mainwindow/autoLayout/use","true")=="true")
5115 emit (updateLayout());
5118 bool VymModel::selectFirstBranch()
5120 TreeItem *ti=getSelectedBranch();
5123 TreeItem *par=ti->parent();
5126 TreeItem *ti2=par->getFirstBranch();
5127 if (ti2) return select(ti2);
5133 bool VymModel::selectLastBranch()
5135 TreeItem *ti=getSelectedBranch();
5138 TreeItem *par=ti->parent();
5141 TreeItem *ti2=par->getLastBranch();
5142 if (ti2) return select(ti2);
5148 bool VymModel::selectLastSelectedBranch()
5150 BranchItem *bi=getSelectedBranch();
5153 bi=bi->getLastSelectedBranch();
5154 if (bi) return select (bi);
5159 bool VymModel::selectParent()
5161 TreeItem *ti=getSelectedItem();
5172 TreeItem::Type VymModel::selectionType()
5174 QModelIndexList list=selModel->selectedIndexes();
5175 if (list.isEmpty()) return TreeItem::Undefined;
5176 TreeItem *ti = getItem (list.first() );
5177 return ti->getType();
5181 LinkableMapObj* VymModel::getSelectedLMO()
5183 QModelIndexList list=selModel->selectedIndexes();
5184 if (!list.isEmpty() )
5186 TreeItem *ti = getItem (list.first() );
5187 TreeItem::Type type=ti->getType();
5188 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5189 return ((MapItem*)ti)->getLMO();
5194 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5196 TreeItem *ti = getSelectedBranch();
5198 return (BranchObj*)( ((MapItem*)ti)->getLMO());
5203 BranchItem* VymModel::getSelectedBranch()
5205 QModelIndexList list=selModel->selectedIndexes();
5206 if (!list.isEmpty() )
5208 TreeItem *ti = getItem (list.first() );
5209 TreeItem::Type type=ti->getType();
5210 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5211 return (BranchItem*)ti;
5216 ImageItem* VymModel::getSelectedImage()
5218 QModelIndexList list=selModel->selectedIndexes();
5219 if (!list.isEmpty())
5221 TreeItem *ti=getItem (list.first());
5222 if (ti && ti->getType()==TreeItem::Image)
5223 return (ImageItem*)ti;
5228 AttributeItem* VymModel::getSelectedAttribute()
5230 QModelIndexList list=selModel->selectedIndexes();
5231 if (!list.isEmpty() )
5233 TreeItem *ti = getItem (list.first() );
5234 TreeItem::Type type=ti->getType();
5235 if (type ==TreeItem::Attribute)
5236 return (AttributeItem*)ti;
5241 TreeItem* VymModel::getSelectedItem()
5243 QModelIndexList list=selModel->selectedIndexes();
5244 if (!list.isEmpty() )
5245 return getItem (list.first() );
5250 QModelIndex VymModel::getSelectedIndex()
5252 QModelIndexList list=selModel->selectedIndexes();
5253 if (list.isEmpty() )
5254 return QModelIndex();
5256 return list.first();
5259 QString VymModel::getSelectString ()
5261 return getSelectString (getSelectedItem());
5264 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5266 if (!lmo) return QString();
5267 return getSelectString (lmo->getTreeItem() );
5270 QString VymModel::getSelectString (TreeItem *ti)
5274 switch (ti->getType())
5276 case TreeItem::MapCenter: s="mc:"; break;
5277 case TreeItem::Branch: s="bo:";break;
5278 case TreeItem::Image: s="fi:";break;
5279 case TreeItem::Attribute: s="ai:";break;
5280 case TreeItem::XLink: s="xl:";break;
5282 s="unknown type in VymModel::getSelectString()";
5285 s= s + QString("%1").arg(ti->num());
5287 // call myself recursively
5288 s= getSelectString(ti->parent()) +","+s;
5293 QString VymModel::getSelectString (BranchItem *bi)
5295 return getSelectString ((TreeItem*)bi);