1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
9 #include "editxlinkdialog.h"
11 #include "exportxhtmldialog.h"
13 #include "geometry.h" // for addBBox
14 #include "mainwindow.h"
19 #include "warningdialog.h"
20 #include "xlinkitem.h"
21 #include "xml-freemind.h"
27 extern Main *mainWindow;
28 extern QDBusConnection dbusConnection;
30 extern Settings settings;
31 extern QString tmpVymDir;
33 extern TextEditor *textEditor;
34 extern FlagRow *standardFlagsMaster;
36 extern QString clipboardDir;
37 extern QString clipboardFile;
38 extern bool clipboardEmpty;
40 extern ImageIO imageIO;
42 extern QString vymName;
43 extern QString vymVersion;
44 extern QDir vymBaseDir;
46 extern QDir lastImageDir;
47 extern QDir lastFileDir;
49 extern Settings settings;
53 int VymModel::mapNum=0; // make instance
57 //cout << "Const VymModel\n";
59 rootItem->setModel (this);
65 //cout << "Destr VymModel\n";
66 autosaveTimer->stop();
67 fileChangedTimer->stop();
71 void VymModel::clear()
73 while (rootItem->childCount() >0)
74 deleteItem (rootItem->getChildNum(0) );
77 void VymModel::init ()
82 // Also no scene yet (should not be needed anyway) FIXME-3 VM
95 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
96 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
97 mainWindow->updateHistory (undoSet);
100 makeTmpDirectories();
105 fileName=tr("unnamed");
107 blockReposition=false;
108 blockSaveState=false;
110 autosaveTimer=new QTimer (this);
111 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
113 fileChangedTimer=new QTimer (this);
114 fileChangedTimer->start(3000);
115 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
120 selectionBlocked=false;
125 // animations // FIXME-3 switch to new animation system
126 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
127 animationTicks=settings.readNumEntry("/animation/ticks",10);
128 animationInterval=settings.readNumEntry("/animation/interval",50);
130 animationTimer=new QTimer (this);
131 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
134 defLinkColor=QColor (0,0,255);
135 defXLinkColor=QColor (180,180,180);
136 linkcolorhint=LinkableMapObj::DefaultColor;
137 linkstyle=LinkableMapObj::PolyParabel;
139 defXLinkColor=QColor (230,230,230);
141 hidemode=TreeItem::HideNone;
147 // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
149 //Initialize DBUS object
150 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
151 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapNum),this))
152 qWarning ("VymModel: Couldn't register DBUS object!");
155 void VymModel::makeTmpDirectories()
157 // Create unique temporary directories
158 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
159 histPath = tmpMapDir+"/history";
165 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
170 bool VymModel::isRepositionBlocked()
172 return blockReposition;
175 void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
177 //cout << "VM::updateActions \n";
178 // Tell mainwindow to update states of actions
179 mainWindow->updateActions();
184 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
186 // tmpdir temporary directory to which data will be written
187 // prefix mapname, which will be appended to images etc.
188 // writeflags Only write flags for "real" save of map, not undo
189 // offset offset of bbox of whole map in scene.
190 // Needed for XML export
199 case LinkableMapObj::Line:
202 case LinkableMapObj::Parabel:
205 case LinkableMapObj::PolyLine:
209 ls="StylePolyParabel";
213 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
215 if (linkcolorhint==LinkableMapObj::HeadingColor)
216 colhint=xml.attribut("linkColorHint","HeadingColor");
218 QString mapAttr=xml.attribut("version",vymVersion);
220 mapAttr+= xml.attribut("author",author) +
221 xml.attribut("comment",comment) +
222 xml.attribut("date",getDate()) +
223 xml.attribut("branchCount", QString().number(branchCount())) +
224 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
225 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
226 xml.attribut("linkStyle", ls ) +
227 xml.attribut("linkColor", defLinkColor.name() ) +
228 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
229 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
231 s+=xml.beginElement("vymmap",mapAttr);
234 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
235 standardFlagsMaster->resetUsedCounter();
237 // Build xml recursivly
239 // Save all mapcenters as complete map, if saveSel not set
240 s+=saveTreeToDir(tmpdir,prefix,offset);
243 switch (saveSel->getType())
245 case TreeItem::Branch:
247 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
249 case TreeItem::MapCenter:
251 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
253 case TreeItem::Image:
255 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
258 // other types shouldn't be safed directly...
263 // Save local settings
264 s+=settings.getDataXML (destPath);
267 if (getSelectedItem() && !saveSel )
268 s+=xml.valueElement("select",getSelectString());
271 s+=xml.endElement("vymmap");
273 //cout << s.toStdString() << endl;
275 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
279 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset)
283 for (int i=0; i<rootItem->branchCount(); i++)
284 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
288 void VymModel::setFilePath(QString fpath, QString destname)
290 if (fpath.isEmpty() || fpath=="")
297 filePath=fpath; // becomes absolute path
298 fileName=fpath; // gets stripped of path
299 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
301 // If fpath is not an absolute path, complete it
302 filePath=QDir(fpath).absPath();
303 fileDir=filePath.left (1+filePath.findRev ("/"));
305 // Set short name, too. Search from behind:
306 int i=fileName.findRev("/");
307 if (i>=0) fileName=fileName.remove (0,i+1);
309 // Forget the .vym (or .xml) for name of map
310 mapName=fileName.left(fileName.findRev(".",-1,true) );
314 void VymModel::setFilePath(QString fpath)
316 setFilePath (fpath,fpath);
319 QString VymModel::getFilePath()
324 QString VymModel::getFileName()
329 QString VymModel::getMapName()
334 QString VymModel::getDestPath()
339 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
341 ErrorCode err=success;
343 parseBaseHandler *handler;
347 case VymMap: handler=new parseVYMHandler; break;
348 case FreemindMap : handler=new parseFreemindHandler; break;
350 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
351 "Unknown FileType in VymModel::load()");
355 bool zipped_org=zipped;
359 selModel->clearSelection();
360 // FIXME-2 VM not needed??? model->setMapEditor(this);
361 // (map state is set later at end of load...)
364 BranchItem *bi=getSelectedBranch();
365 if (!bi) return aborted;
366 if (lmode==ImportAdd)
367 saveStateChangingPart(
370 QString("addMapInsert (%1)").arg(fname),
371 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
373 saveStateChangingPart(
376 QString("addMapReplace(%1)").arg(fname),
377 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
381 // Create temporary directory for packing
383 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
386 QMessageBox::critical( 0, tr( "Critical Load Error" ),
387 tr("Couldn't create temporary directory before load\n"));
392 err=unzipDir (tmpZipDir,fname);
402 // Look for mapname.xml
403 xmlfile= fname.left(fname.findRev(".",-1,true));
404 xmlfile=xmlfile.section( '/', -1 );
405 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
406 if (!mfile.exists() )
408 // mapname.xml does not exist, well,
409 // maybe someone renamed the mapname.vym file...
410 // Try to find any .xml in the toplevel
411 // directory of the .vym file
412 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
413 if (flist.count()==1)
415 // Only one entry, take this one
416 xmlfile=tmpZipDir + "/"+flist.first();
419 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
420 *it=tmpZipDir + "/" + *it;
421 // TODO Multiple entries, load all (but only the first one into this ME)
422 //mainWindow->fileLoadFromTmp (flist);
423 //returnCode=1; // Silently forget this attempt to load
424 qWarning ("MainWindow::load (fn) multimap found...");
427 if (flist.isEmpty() )
429 QMessageBox::critical( 0, tr( "Critical Load Error" ),
430 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
433 } //file doesn't exist
435 xmlfile=mfile.name();
438 QFile file( xmlfile);
440 // I am paranoid: file should exist anyway
441 // according to check in mainwindow.
444 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
445 tr(QString("Couldn't open map %1").arg(file.name())));
449 bool blockSaveStateOrg=blockSaveState;
450 blockReposition=true;
452 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
453 QXmlInputSource source( file);
454 QXmlSimpleReader reader;
455 reader.setContentHandler( handler );
456 reader.setErrorHandler( handler );
457 handler->setModel ( this);
460 // We need to set the tmpDir in order to load files with rel. path
465 tmpdir=fname.left(fname.findRev("/",-1));
466 handler->setTmpDir (tmpdir);
467 handler->setInputFile (file.name());
468 handler->setLoadMode (lmode);
469 bool ok = reader.parse( source );
470 blockReposition=false;
471 blockSaveState=blockSaveStateOrg;
472 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
476 reposition(); // FIXME-2 VM reposition the view instead...
477 emitSelectionChanged();
483 autosaveTimer->stop();
486 // Reset timestamp to check for later updates of file
487 fileChangedTime=QFileInfo (destPath).lastModified();
490 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
491 tr( handler->errorProtocol() ) );
493 // Still return "success": the map maybe at least
494 // partially read by the parser
499 removeDir (QDir(tmpZipDir));
501 // Restore original zip state
508 ErrorCode VymModel::save (const SaveMode &savemode)
512 QString safeFilePath;
514 ErrorCode err=success;
518 mapFileName=mapName+".xml";
520 // use name given by user, even if he chooses .doc
521 mapFileName=fileName;
523 // Look, if we should zip the data:
526 QMessageBox mb( vymName,
527 tr("The map %1\ndid not use the compressed "
528 "vym file format.\nWriting it uncompressed will also write images \n"
529 "and flags and thus may overwrite files in the "
530 "given directory\n\nDo you want to write the map").arg(filePath),
531 QMessageBox::Warning,
532 QMessageBox::Yes | QMessageBox::Default,
534 QMessageBox::Cancel | QMessageBox::Escape);
535 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
536 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
537 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
540 case QMessageBox::Yes:
541 // save compressed (default file format)
544 case QMessageBox::No:
548 case QMessageBox::Cancel:
555 // First backup existing file, we
556 // don't want to add to old zip archives
560 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
562 QString backupFileName(destPath + "~");
563 QFile backupFile(backupFileName);
564 if (backupFile.exists() && !backupFile.remove())
566 QMessageBox::warning(0, tr("Save Error"),
567 tr("%1\ncould not be removed before saving").arg(backupFileName));
569 else if (!f.rename(backupFileName))
571 QMessageBox::warning(0, tr("Save Error"),
572 tr("%1\ncould not be renamed before saving").arg(destPath));
579 // Create temporary directory for packing
581 tmpZipDir=makeTmpDir (ok,"vym-zip");
584 QMessageBox::critical( 0, tr( "Critical Load Error" ),
585 tr("Couldn't create temporary directory before save\n"));
589 safeFilePath=filePath;
590 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
593 // Create mapName and fileDir
594 makeSubDirs (fileDir);
597 if (savemode==CompleteMap || selModel->selection().isEmpty())
600 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
603 autosaveTimer->stop();
608 if (selectionType()==TreeItem::Image)
611 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
612 // TODO take care of multiselections
615 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
618 qWarning ("ME::saveStringToDisk failed!");
624 if (err==success) err=zipDir (tmpZipDir,destPath);
627 removeDir (QDir(tmpZipDir));
629 // Restore original filepath outside of tmp zip dir
630 setFilePath (safeFilePath);
634 fileChangedTime=QFileInfo (destPath).lastModified();
638 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
640 QString pathDir=path.left(path.findRev("/"));
646 // We need to parse saved XML data
647 parseVYMHandler handler;
648 QXmlInputSource source( file);
649 QXmlSimpleReader reader;
650 reader.setContentHandler( &handler );
651 reader.setErrorHandler( &handler );
652 handler.setModel ( this);
653 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
654 if (undoSel.isEmpty())
658 handler.setLoadMode (NewMap);
662 handler.setLoadMode (ImportReplace);
664 blockReposition=true;
665 bool ok = reader.parse( source );
666 blockReposition=false;
669 // This should never ever happen
670 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
671 handler.errorProtocol());
674 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
677 bool VymModel::addMapInsertInt (const QString &path)
679 QString pathDir=path.left(path.findRev("/"));
685 // We need to parse saved XML data
686 parseVYMHandler handler;
687 QXmlInputSource source( file);
688 QXmlSimpleReader reader;
689 reader.setContentHandler( &handler );
690 reader.setErrorHandler( &handler );
691 handler.setModel (this);
692 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
693 handler.setLoadMode (ImportAdd);
694 blockReposition=true;
695 bool ok = reader.parse( source );
696 blockReposition=false;
697 if ( ok ) return true;
699 // This should never ever happen
700 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
701 handler.errorProtocol());
704 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
708 bool VymModel::addMapInsertInt (const QString &path, int pos)
710 BranchItem *selbi=getSelectedBranch();
713 if (addMapInsertInt (path))
715 if (selbi->depth()>0)
716 relinkBranch (selbi->getLastBranch(), selbi,pos);
720 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
724 qWarning ("ME::addMapInsertInt nothing selected");
728 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
730 ImageItem *ii=createImage(dst);
740 void VymModel::loadFloatImage ()
742 BranchItem *selbi=getSelectedBranch();
746 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
747 fd->setMode (Q3FileDialog::ExistingFiles);
748 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
749 ImagePreview *p =new ImagePreview (fd);
750 fd->setContentsPreviewEnabled( TRUE );
751 fd->setContentsPreview( p, p );
752 fd->setPreviewMode( Q3FileDialog::Contents );
753 fd->setCaption(vymName+" - " +tr("Load image"));
754 fd->setDir (lastImageDir);
757 if ( fd->exec() == QDialog::Accepted )
759 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
760 lastImageDir=QDir (fd->dirPath());
763 for (int j=0; j<fd->selectedFiles().count(); j++)
765 s=fd->selectedFiles().at(j);
766 ii=loadFloatImageInt (selbi,s);
767 //FIXME-3 check savestate for loadImage
773 QString ("loadImage (%1)").arg(s ),
774 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
777 // TODO loadFIO error handling
778 qWarning ("Failed to load "+s);
786 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
791 void VymModel::saveFloatImage ()
793 ImageItem *ii=getSelectedImage();
796 QFileDialog *fd=new QFileDialog( NULL);
797 fd->setFilters (imageIO.getFilters());
798 fd->setCaption(vymName+" - " +tr("Save image"));
799 fd->setFileMode( QFileDialog::AnyFile );
800 fd->setDirectory (lastImageDir);
801 // fd->setSelection (fio->getOriginalFilename());
805 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
807 fn=fd->selectedFiles().at(0);
808 if (QFile (fn).exists() )
810 QMessageBox mb( vymName,
811 tr("The file %1 exists already.\n"
812 "Do you want to overwrite it?").arg(fn),
813 QMessageBox::Warning,
814 QMessageBox::Yes | QMessageBox::Default,
815 QMessageBox::Cancel | QMessageBox::Escape,
816 QMessageBox::NoButton );
818 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
819 mb.setButtonText( QMessageBox::No, tr("Cancel"));
822 case QMessageBox::Yes:
825 case QMessageBox::Cancel:
832 saveFloatImageInt (ii,fd->selectedFilter(),fn );
839 void VymModel::importDirInt(BranchItem *dst, QDir d)
841 BranchItem *selbi=getSelectedBranch();
845 // Traverse directories
846 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
847 QFileInfoList list = d.entryInfoList();
850 for (int i = 0; i < list.size(); ++i)
853 if (fi.fileName() != "." && fi.fileName() != ".." )
855 bi=addNewBranchInt(dst,-2);
856 bi->setHeading (fi.fileName() ); // FIXME-3 check this
857 bi->setHeadingColor (QColor("blue"));
859 if ( !d.cd(fi.fileName()) )
860 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
863 // Recursively add subdirs
870 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
871 list = d.entryInfoList();
873 for (int i = 0; i < list.size(); ++i)
876 bi=addNewBranchInt (dst,-2);
877 bi->setHeading (fi.fileName() );
878 bi->setHeadingColor (QColor("black"));
879 if (fi.fileName().right(4) == ".vym" )
880 bi->setVymLink (fi.filePath());
885 void VymModel::importDirInt (const QString &s)
887 BranchItem *selbi=getSelectedBranch();
890 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
893 importDirInt (selbi,d);
897 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
899 BranchItem *selbi=getSelectedBranch();
903 filters <<"VYM map (*.vym)";
904 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
905 fd->setMode (QFileDialog::DirectoryOnly);
906 fd->setFilters (filters);
907 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
911 if ( fd->exec() == QDialog::Accepted )
913 importDirInt (fd->selectedFile() );
915 //FIXME-3 VM needed? scene()->update();
921 void VymModel::autosave()
926 cout << "VymModel::autosave rejected due to missing filePath\n";
929 QDateTime now=QDateTime().currentDateTime();
931 // Disable autosave, while we have gone back in history
932 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
933 if (redosAvail>0) return;
935 // Also disable autosave for new map without filename
936 if (filePath.isEmpty()) return;
939 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
941 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
942 mainWindow->fileSave (this);
945 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
950 void VymModel::fileChanged()
952 // Check if file on disk has changed meanwhile
953 if (!filePath.isEmpty())
955 QDateTime tmod=QFileInfo (filePath).lastModified();
956 if (tmod>fileChangedTime)
958 // FIXME-2 VM switch to current mapeditor and finish lineedits...
959 QMessageBox mb( vymName,
960 tr("The file of the map on disk has changed:\n\n"
961 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
962 QMessageBox::Question,
964 QMessageBox::Cancel | QMessageBox::Default,
965 QMessageBox::NoButton );
967 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
968 mb.setButtonText( QMessageBox::No, tr("Ignore"));
971 case QMessageBox::Yes:
973 load (filePath,NewMap,fileType);
974 case QMessageBox::Cancel:
975 fileChangedTime=tmod; // allow autosave to overwrite newer file!
981 bool VymModel::isDefault()
986 void VymModel::makeDefault()
992 bool VymModel::hasChanged()
997 void VymModel::setChanged()
1000 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1004 latestAddedItem=NULL;
1008 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1010 if (!lmo || !lmo->getTreeItem() ) return QString();
1011 return getObjectName (lmo->getTreeItem() );
1015 QString VymModel::getObjectName (TreeItem *ti)
1018 if (!ti) return QString("Error: NULL has no name!");
1020 if (s=="") s="unnamed";
1022 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1025 void VymModel::redo()
1027 // Can we undo at all?
1028 if (redosAvail<1) return;
1030 bool blockSaveStateOrg=blockSaveState;
1031 blockSaveState=true;
1035 if (undosAvail<stepsTotal) undosAvail++;
1037 if (curStep>stepsTotal) curStep=1;
1038 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1039 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1040 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1041 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1042 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1043 QString version=undoSet.readEntry ("/history/version");
1045 /* TODO Maybe check for version, if we save the history
1046 if (!checkVersion(version))
1047 QMessageBox::warning(0,tr("Warning"),
1048 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1051 // Find out current undo directory
1052 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1056 cout << "VymModel::redo() begin\n";
1057 cout << " undosAvail="<<undosAvail<<endl;
1058 cout << " redosAvail="<<redosAvail<<endl;
1059 cout << " curStep="<<curStep<<endl;
1060 cout << " ---------------------------"<<endl;
1061 cout << " comment="<<comment.toStdString()<<endl;
1062 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1063 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1064 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1065 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1066 cout << " ---------------------------"<<endl<<endl;
1069 // select object before redo
1070 if (!redoSelection.isEmpty())
1071 select (redoSelection);
1076 parseAtom (redoCommand,noErr,errMsg);
1078 blockSaveState=blockSaveStateOrg;
1080 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1081 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1082 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1083 undoSet.writeSettings(histPath);
1085 mainWindow->updateHistory (undoSet);
1088 /* TODO remove testing
1089 cout << "ME::redo() end\n";
1090 cout << " undosAvail="<<undosAvail<<endl;
1091 cout << " redosAvail="<<redosAvail<<endl;
1092 cout << " curStep="<<curStep<<endl;
1093 cout << " ---------------------------"<<endl<<endl;
1099 bool VymModel::isRedoAvailable()
1101 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1107 void VymModel::undo()
1109 // Can we undo at all?
1110 if (undosAvail<1) return;
1112 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1114 bool blockSaveStateOrg=blockSaveState;
1115 blockSaveState=true;
1117 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1118 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1119 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1120 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1121 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1122 QString version=undoSet.readEntry ("/history/version");
1124 /* TODO Maybe check for version, if we save the history
1125 if (!checkVersion(version))
1126 QMessageBox::warning(0,tr("Warning"),
1127 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1130 // Find out current undo directory
1131 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1133 // select object before undo
1134 if (!select (undoSelection))
1136 qWarning ("VymModel::undo() Could not select object for undo");
1143 cout << "VymModel::undo() begin\n";
1144 cout << " undosAvail="<<undosAvail<<endl;
1145 cout << " redosAvail="<<redosAvail<<endl;
1146 cout << " curStep="<<curStep<<endl;
1147 cout << " ---------------------------"<<endl;
1148 cout << " comment="<<comment.toStdString()<<endl;
1149 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1150 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1151 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1152 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1153 cout << " ---------------------------"<<endl<<endl;
1158 parseAtom (undoCommand,noErr,errMsg);
1162 if (curStep<1) curStep=stepsTotal;
1166 blockSaveState=blockSaveStateOrg;
1168 cout << "VymModel::undo() end\n";
1169 cout << " undosAvail="<<undosAvail<<endl;
1170 cout << " redosAvail="<<redosAvail<<endl;
1171 cout << " curStep="<<curStep<<endl;
1172 cout << " ---------------------------"<<endl<<endl;
1175 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1176 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1177 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1178 undoSet.writeSettings(histPath);
1180 mainWindow->updateHistory (undoSet);
1182 //emitSelectionChanged();
1185 bool VymModel::isUndoAvailable()
1187 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1193 void VymModel::gotoHistoryStep (int i)
1195 // Restore variables
1196 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1197 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1199 if (i<0) i=undosAvail+redosAvail;
1201 // Clicking above current step makes us undo things
1204 for (int j=0; j<undosAvail-i; j++) undo();
1207 // Clicking below current step makes us redo things
1209 for (int j=undosAvail; j<i; j++)
1211 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1215 // And ignore clicking the current row ;-)
1219 QString VymModel::getHistoryPath()
1221 QString histName(QString("history-%1").arg(curStep));
1222 return (tmpMapDir+"/"+histName);
1225 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1227 sendData(redoCom); //FIXME-3 testing
1232 if (blockSaveState) return;
1234 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1236 // Find out current undo directory
1237 if (undosAvail<stepsTotal) undosAvail++;
1239 if (curStep>stepsTotal) curStep=1;
1241 QString backupXML="";
1242 QString histDir=getHistoryPath();
1243 QString bakMapPath=histDir+"/map.xml";
1245 // Create histDir if not available
1248 makeSubDirs (histDir);
1250 // Save depending on how much needs to be saved
1252 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1254 QString undoCommand="";
1255 if (savemode==UndoCommand)
1257 undoCommand=undoCom;
1259 else if (savemode==PartOfMap )
1261 undoCommand=undoCom;
1262 undoCommand.replace ("PATH",bakMapPath);
1266 if (!backupXML.isEmpty())
1267 // Write XML Data to disk
1268 saveStringToDisk (bakMapPath,backupXML);
1270 // We would have to save all actions in a tree, to keep track of
1271 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1274 // Write the current state to disk
1275 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1276 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1277 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1278 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1279 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1280 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1281 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1282 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1283 undoSet.setEntry (QString("/history/version"),vymVersion);
1284 undoSet.writeSettings(histPath);
1288 // TODO remove after testing
1289 //cout << " into="<< histPath.toStdString()<<endl;
1290 cout << " stepsTotal="<<stepsTotal<<
1291 ", undosAvail="<<undosAvail<<
1292 ", redosAvail="<<redosAvail<<
1293 ", curStep="<<curStep<<endl;
1294 cout << " ---------------------------"<<endl;
1295 cout << " comment="<<comment.toStdString()<<endl;
1296 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1297 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1298 cout << " redoCom="<<redoCom.toStdString()<<endl;
1299 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1300 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1301 cout << " ---------------------------"<<endl;
1304 mainWindow->updateHistory (undoSet);
1310 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1312 // save the selected part of the map, Undo will replace part of map
1313 QString undoSelection="";
1315 undoSelection=getSelectString(undoSel);
1317 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1318 QString redoSelection="";
1320 redoSelection=getSelectString(undoSel);
1322 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1325 saveState (PartOfMap,
1326 undoSelection, "addMapReplace (\"PATH\")",
1332 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1336 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1339 QString undoSelection;
1340 QString redoSelection=getSelectString(redoSel);
1341 if (redoSel->getType()==TreeItem::Branch)
1343 undoSelection=getSelectString (redoSel->parent());
1344 // save the selected branch of the map, Undo will insert part of map
1345 saveState (PartOfMap,
1346 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1347 redoSelection, "delete ()",
1351 if (redoSel->getType()==TreeItem::MapCenter)
1353 // save the selected branch of the map, Undo will insert part of map
1354 saveState (PartOfMap,
1355 undoSelection, QString("addMapInsert (\"PATH\")"),
1356 redoSelection, "delete ()",
1363 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1365 // "Normal" savestate: save commands, selections and comment
1366 // so just save commands for undo and redo
1367 // and use current selection
1369 QString redoSelection="";
1370 if (redoSel) redoSelection=getSelectString(redoSel);
1371 QString undoSelection="";
1372 if (undoSel) undoSelection=getSelectString(undoSel);
1374 saveState (UndoCommand,
1381 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1383 // "Normal" savestate: save commands, selections and comment
1384 // so just save commands for undo and redo
1385 // and use current selection
1386 saveState (UndoCommand,
1393 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1395 // "Normal" savestate applied to model (no selection needed):
1396 // save commands and comment
1397 saveState (UndoCommand,
1405 QGraphicsScene* VymModel::getScene ()
1410 TreeItem* VymModel::findBySelectString(QString s)
1412 if (s.isEmpty() ) return NULL;
1414 // Old maps don't have multiple mapcenters and don't save full path
1415 if (s.left(2) !="mc")
1418 QStringList parts=s.split (",");
1421 TreeItem *ti=rootItem;
1423 while (!parts.isEmpty() )
1425 typ=parts.first().left(2);
1426 n=parts.first().right(parts.first().length() - 3).toInt();
1427 parts.removeFirst();
1428 if (typ=="mc" || typ=="bo")
1429 ti=ti->getBranchNum (n);
1431 ti=ti->getImageNum (n);
1433 ti=ti->getAttributeNum (n);
1435 ti=ti->getXLinkNum (n);
1436 if(!ti) return NULL;
1441 TreeItem* VymModel::findID (const QString &s) //FIXME-4 Search also other types...
1443 BranchItem *cur=NULL;
1444 BranchItem *prev=NULL;
1445 nextBranch(cur,prev);
1448 if (s==cur->getID() ) return cur;
1449 nextBranch(cur,prev);
1454 //////////////////////////////////////////////
1456 //////////////////////////////////////////////
1457 void VymModel::setVersion (const QString &s)
1462 QString VymModel::getVersion()
1467 void VymModel::setAuthor (const QString &s)
1470 QString ("setMapAuthor (\"%1\")").arg(author),
1471 QString ("setMapAuthor (\"%1\")").arg(s),
1472 QString ("Set author of map to \"%1\"").arg(s)
1477 QString VymModel::getAuthor()
1482 void VymModel::setComment (const QString &s)
1485 QString ("setMapComment (\"%1\")").arg(comment),
1486 QString ("setMapComment (\"%1\")").arg(s),
1487 QString ("Set comment of map")
1492 QString VymModel::getComment ()
1497 QString VymModel::getDate ()
1499 return QDate::currentDate().toString ("yyyy-MM-dd");
1502 int VymModel::branchCount()
1505 BranchItem *cur=NULL;
1506 BranchItem *prev=NULL;
1507 nextBranch(cur,prev);
1511 nextBranch(cur,prev);
1516 void VymModel::setSortFilter (const QString &s)
1519 emit (sortFilterChanged (sortFilter));
1522 QString VymModel::getSortFilter ()
1527 void VymModel::setHeading(const QString &s)
1529 BranchItem *selbi=getSelectedBranch();
1534 "setHeading (\""+selbi->getHeading()+"\")",
1536 "setHeading (\""+s+"\")",
1537 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1538 selbi->setHeading(s );
1539 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1541 emitSelectionChanged();
1545 QString VymModel::getHeading()
1547 TreeItem *selti=getSelectedItem();
1549 return selti->getHeading();
1554 void VymModel::setNote(const QString &s)
1556 cout << "VM::setNote\n";
1557 TreeItem *selti=getSelectedItem();
1560 emitNoteHasChanged(selti);
1563 "setNote (\""+selti->getNote()+"\")",
1565 "setNote (\""+s+"\")",
1566 QString("Set note of %1 ").arg(getObjectName(selti)) );
1571 QString VymModel::getNote()
1573 TreeItem *selti=getSelectedItem();
1575 return selti->getNote();
1580 void VymModel::findDuplicateURLs() // FIXME-3 needs GUI
1582 // Generate map containing _all_ URLs and branches
1584 QMap <QString,BranchItem*> map;
1585 BranchItem *cur=NULL;
1586 BranchItem *prev=NULL;
1587 nextBranch(cur,prev);
1592 map.insertMulti (u,cur);
1593 nextBranch(cur,prev);
1596 // Extract duplicate URLs
1597 QMap <QString, BranchItem*>::const_iterator i=map.constBegin();
1598 QMap <QString, BranchItem*>::const_iterator firstdup=map.constEnd(); //invalid
1599 while (i != map.constEnd())
1601 if (i!=map.constBegin() && i.key()==firstdup.key())
1603 if ( i-1==firstdup )
1605 cout << firstdup.key().toStdString() << endl;
1606 cout << " - "<< firstdup.value() <<" - "<<firstdup.value()->getHeadingStd()<<endl;
1608 cout << " - "<< i.value() <<" - "<<i.value()->getHeadingStd()<<endl;
1616 BranchItem* VymModel::findText (QString s, bool cs)
1618 if (!s.isEmpty() && s!=findString)
1624 QTextDocument::FindFlags flags=0;
1625 if (cs) flags=QTextDocument::FindCaseSensitively;
1628 { // Nothing found or new find process
1630 // nothing found, start again
1634 nextBranch (findCurrent,findPrevious);
1636 bool searching=true;
1637 bool foundNote=false;
1638 while (searching && !EOFind)
1642 // Searching in Note
1643 if (findCurrent->getNote().contains(findString,cs))
1645 select (findCurrent);
1647 if (getSelectedBranch()!=itFind)
1650 emitShowSelection();
1653 if (textEditor->findText(findString,flags))
1659 // Searching in Heading
1660 if (searching && findCurrent->getHeading().contains (findString,cs) )
1662 select(findCurrent);
1668 if (!nextBranch(findCurrent,findPrevious) )
1671 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1674 return getSelectedBranch();
1679 void VymModel::findReset()
1680 { // Necessary if text to find changes during a find process
1687 void VymModel::emitShowFindWidget()
1689 emit (showFindWidget());
1692 void VymModel::setScene (QGraphicsScene *s)
1697 void VymModel::setURL(const QString &url)
1699 TreeItem *selti=getSelectedItem();
1702 QString oldurl=selti->getURL();
1703 selti->setURL (url);
1706 QString ("setURL (\"%1\")").arg(oldurl),
1708 QString ("setURL (\"%1\")").arg(url),
1709 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1712 emitDataHasChanged (selti);
1713 emitShowSelection();
1717 QString VymModel::getURL()
1719 TreeItem *selti=getSelectedItem();
1721 return selti->getURL();
1726 QStringList VymModel::getURLs(bool ignoreScrolled)
1729 BranchItem *selbi=getSelectedBranch();
1730 BranchItem *cur=selbi;
1731 BranchItem *prev=NULL;
1734 if (!cur->getURL().isEmpty() && !(ignoreScrolled && cur->hasScrolledParent(cur) ))
1735 urls.append( cur->getURL());
1736 cur=nextBranch (cur,prev,true,selbi);
1742 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1744 BranchItem *bi=getSelectedBranch();
1747 BranchObj *bo=(BranchObj*)(bi->getLMO());
1750 QString s=bo->getFrameTypeName();
1751 bo->setFrameType (t);
1752 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1753 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1755 bo->updateLinkGeometry();
1760 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1762 BranchItem *bi=getSelectedBranch();
1765 BranchObj *bo=(BranchObj*)(bi->getLMO());
1768 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1769 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1770 bo->setFrameType (s);
1772 bo->updateLinkGeometry();
1777 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1780 BranchItem *bi=getSelectedBranch();
1783 BranchObj *bo=(BranchObj*)(bi->getLMO());
1786 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1787 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1788 bo->setFramePenColor (c);
1793 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1795 BranchItem *bi=getSelectedBranch();
1798 BranchObj *bo=(BranchObj*)(bi->getLMO());
1801 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1802 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1803 bo->setFrameBrushColor (c);
1808 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1810 BranchItem *bi=getSelectedBranch();
1813 BranchObj *bo=(BranchObj*)(bi->getLMO());
1816 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1817 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1818 bo->setFramePadding (i);
1820 bo->updateLinkGeometry();
1825 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1827 BranchItem *bi=getSelectedBranch();
1830 BranchObj *bo=(BranchObj*)(bi->getLMO());
1833 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1834 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1835 bo->setFrameBorderWidth (i);
1837 bo->updateLinkGeometry();
1842 void VymModel::setIncludeImagesVer(bool b)
1844 BranchItem *bi=getSelectedBranch();
1847 QString u= b ? "false" : "true";
1848 QString r=!b ? "false" : "true";
1852 QString("setIncludeImagesVertically (%1)").arg(u),
1854 QString("setIncludeImagesVertically (%1)").arg(r),
1855 QString("Include images vertically in %1").arg(getObjectName(bi))
1857 bi->setIncludeImagesVer(b);
1858 emitDataHasChanged ( bi);
1863 void VymModel::setIncludeImagesHor(bool b)
1865 BranchItem *bi=getSelectedBranch();
1868 QString u= b ? "false" : "true";
1869 QString r=!b ? "false" : "true";
1873 QString("setIncludeImagesHorizontally (%1)").arg(u),
1875 QString("setIncludeImagesHorizontally (%1)").arg(r),
1876 QString("Include images horizontally in %1").arg(getObjectName(bi))
1878 bi->setIncludeImagesHor(b);
1879 emitDataHasChanged ( bi);
1884 void VymModel::setHideLinkUnselected (bool b)//FIXME-2
1886 TreeItem *ti=getSelectedItem();
1887 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1889 QString u= b ? "false" : "true";
1890 QString r=!b ? "false" : "true";
1894 QString("setHideLinkUnselected (%1)").arg(u),
1896 QString("setHideLinkUnselected (%1)").arg(r),
1897 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1899 ((MapItem*)ti)->setHideLinkUnselected(b);
1903 void VymModel::setHideExport(bool b)
1905 TreeItem *ti=getSelectedItem();
1907 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1909 ti->setHideInExport (b);
1910 QString u= b ? "false" : "true";
1911 QString r=!b ? "false" : "true";
1915 QString ("setHideExport (%1)").arg(u),
1917 QString ("setHideExport (%1)").arg(r),
1918 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1920 emitDataHasChanged(ti);
1921 emitSelectionChanged();
1924 // emitSelectionChanged();
1925 // FIXME-3 VM needed? scene()->update();
1929 void VymModel::toggleHideExport()
1931 TreeItem *selti=getSelectedItem();
1933 setHideExport ( !selti->hideInExport() );
1936 void VymModel::addTimestamp() //FIXME-3 new function, localize
1938 BranchItem *selbi=addNewBranch();
1941 QDate today=QDate::currentDate();
1943 selbi->setHeading (QString ("%1-%2-%3")
1944 .arg(today.year(),4,10,c)
1945 .arg(today.month(),2,10,c)
1946 .arg(today.day(),2,10,c));
1947 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1954 void VymModel::copy()
1956 TreeItem *selti=getSelectedItem();
1958 (selti->getType() == TreeItem::Branch ||
1959 selti->getType() == TreeItem::MapCenter ||
1960 selti->getType() == TreeItem::Image ))
1962 if (redosAvail == 0)
1965 QString s=getSelectString(selti);
1966 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
1967 curClipboard=curStep;
1970 // Copy also to global clipboard, because we are at last step in history
1971 QString bakMapName(QString("history-%1").arg(curStep));
1972 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1973 copyDir (bakMapDir,clipboardDir );
1975 clipboardEmpty=false;
1981 void VymModel::pasteNoSave(const int &n)
1983 bool old=blockSaveState;
1984 blockSaveState=true;
1985 bool zippedOrg=zipped;
1986 if (redosAvail > 0 || n!=0)
1988 // Use the "historical" buffer
1989 QString bakMapName(QString("history-%1").arg(n));
1990 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1991 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1993 // Use the global buffer
1994 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1999 void VymModel::paste()
2001 BranchItem *selbi=getSelectedBranch();
2004 saveStateChangingPart(
2007 QString ("paste (%1)").arg(curClipboard),
2008 QString("Paste to %1").arg( getObjectName(selbi))
2015 void VymModel::cut()
2017 TreeItem *selti=getSelectedItem();
2018 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
2026 bool VymModel::moveUp(BranchItem *bi) //FIXME-2 crashes if trying to move MCO
2028 if (bi && bi->canMoveUp())
2029 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
2034 void VymModel::moveUp()
2036 BranchItem *selbi=getSelectedBranch();
2039 QString oldsel=getSelectString();
2042 getSelectString(),"moveDown ()",
2044 QString("Move up %1").arg(getObjectName(selbi)));
2048 bool VymModel::moveDown(BranchItem *bi)
2050 if (bi && bi->canMoveDown())
2051 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2056 void VymModel::moveDown()
2058 BranchItem *selbi=getSelectedBranch();
2061 QString oldsel=getSelectString();
2062 if ( moveDown(selbi))
2064 getSelectString(),"moveUp ()",
2065 oldsel,"moveDown ()",
2066 QString("Move down %1").arg(getObjectName(selbi)));
2070 void VymModel::detach()
2072 BranchItem *selbi=getSelectedBranch();
2073 if (selbi && selbi->depth()>0)
2075 // if no relPos have been set before, try to use current rel positions
2076 if (selbi->getLMO())
2077 for (int i=0; i<selbi->branchCount();++i)
2078 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2080 QString oldsel=getSelectString();
2083 BranchObj *bo=selbi->getBranchObj();
2084 if (bo) p=bo->getAbsPos();
2085 QString parsel=getSelectString(selbi->parent());
2086 if ( relinkBranch (selbi,rootItem,-1) )
2088 getSelectString (selbi),
2089 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2092 QString("Detach %1").arg(getObjectName(selbi))
2097 void VymModel::sortChildren()
2099 BranchItem* selbi=getSelectedBranch();
2102 if(selbi->branchCount()>1)
2104 saveStateChangingPart(
2105 selbi,selbi, "sortChildren ()",
2106 QString("Sort children of %1").arg(getObjectName(selbi)));
2107 selbi->sortChildren();
2109 emitShowSelection();
2114 BranchItem* VymModel::createMapCenter()
2116 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2120 BranchItem* VymModel::createBranch(BranchItem *dst)
2123 return addNewBranchInt (dst,-2);
2128 ImageItem* VymModel::createImage(BranchItem *dst)
2135 QList<QVariant> cData;
2136 cData << "new" << "undef";
2138 ImageItem *newii=new ImageItem(cData) ;
2139 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2141 emit (layoutAboutToBeChanged() );
2144 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2145 n=dst->getRowNumAppend(newii);
2146 beginInsertRows (parix,n,n);
2147 dst->appendChild (newii);
2150 emit (layoutChanged() );
2152 // save scroll state. If scrolled, automatically select
2153 // new branch in order to tmp unscroll parent...
2154 newii->createMapObj(mapScene);
2161 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2168 QList<QVariant> cData;
2169 cData << "new xLink"<<"undef";
2171 XLinkItem *newxli=new XLinkItem(cData) ;
2172 newxli->setBegin (bi);
2174 emit (layoutAboutToBeChanged() );
2177 n=bi->getRowNumAppend(newxli);
2178 beginInsertRows (parix,n,n);
2179 bi->appendChild (newxli);
2182 emit (layoutChanged() );
2184 // save scroll state. If scrolled, automatically select
2185 // new branch in order to tmp unscroll parent...
2188 newxli->createMapObj(mapScene);
2196 AttributeItem* VymModel::addAttribute()
2198 BranchItem *selbi=getSelectedBranch();
2201 QList<QVariant> cData;
2202 cData << "new attribute" << "undef";
2203 AttributeItem *a=new AttributeItem (cData);
2204 if (addAttribute (a)) return a;
2209 AttributeItem* VymModel::addAttribute(AttributeItem *ai) // FIXME-2 savestate missing
2211 BranchItem *selbi=getSelectedBranch();
2214 emit (layoutAboutToBeChanged() );
2216 QModelIndex parix=index(selbi);
2217 int n=selbi->getRowNumAppend (ai);
2218 beginInsertRows (parix,n,n);
2219 selbi->appendChild (ai);
2222 emit (layoutChanged() );
2230 BranchItem* VymModel::addMapCenter ()
2232 BranchItem *bi=addMapCenter (contextPos);
2234 emitShowSelection();
2239 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2240 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2245 BranchItem* VymModel::addMapCenter(QPointF absPos)
2246 // createMapCenter could then probably be merged with createBranch
2250 QModelIndex parix=index(rootItem);
2252 QList<QVariant> cData;
2253 cData << "VM:addMapCenter" << "undef";
2254 BranchItem *newbi=new BranchItem (cData,rootItem);
2255 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2256 int n=rootItem->getRowNumAppend (newbi);
2258 emit (layoutAboutToBeChanged() );
2259 beginInsertRows (parix,n,n);
2261 rootItem->appendChild (newbi);
2264 emit (layoutChanged() );
2267 newbi->setPositionMode (MapItem::Absolute);
2268 BranchObj *bo=newbi->createMapObj(mapScene);
2269 if (bo) bo->move (absPos);
2274 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2276 // Depending on pos:
2277 // -3 insert in children of parent above selection
2278 // -2 add branch to selection
2279 // -1 insert in children of parent below selection
2280 // 0..n insert in children of parent at pos
2283 QList<QVariant> cData;
2284 cData << "" << "undef";
2289 BranchItem *newbi=new BranchItem (cData);
2290 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2292 emit (layoutAboutToBeChanged() );
2298 n=parbi->getRowNumAppend (newbi);
2299 beginInsertRows (parix,n,n);
2300 parbi->appendChild (newbi);
2302 }else if (num==-1 || num==-3)
2304 // insert below selection
2305 parbi=(BranchItem*)dst->parent();
2308 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2309 beginInsertRows (parix,n,n);
2310 parbi->insertBranch(n,newbi);
2313 emit (layoutChanged() );
2315 // Set color of heading to that of parent
2316 newbi->setHeadingColor (parbi->getHeadingColor());
2318 // save scroll state. If scrolled, automatically select
2319 // new branch in order to tmp unscroll parent...
2320 newbi->createMapObj(mapScene);
2325 BranchItem* VymModel::addNewBranch(int pos)
2327 // Different meaning than num in addNewBranchInt!
2331 BranchItem *newbi=NULL;
2332 BranchItem *selbi=getSelectedBranch();
2336 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2338 newbi=addNewBranchInt (selbi,pos-2);
2346 QString ("addBranch (%1)").arg(pos),
2347 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2350 // emitSelectionChanged(); FIXME-3
2351 latestAddedItem=newbi;
2352 // In Network mode, the client needs to know where the new branch is,
2353 // so we have to pass on this information via saveState.
2354 // TODO: Get rid of this positioning workaround
2355 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2356 sendData ("selectLatestAdded ()");
2357 sendData (QString("move %1").arg(ps));
2366 BranchItem* VymModel::addNewBranchBefore()
2368 BranchItem *newbi=NULL;
2369 BranchItem *selbi=getSelectedBranch();
2370 if (selbi && selbi->getType()==TreeItem::Branch)
2371 // We accept no MapCenter here, so we _have_ a parent
2373 //QPointF p=bo->getRelPos();
2376 // add below selection
2377 newbi=addNewBranchInt (selbi,-1);
2381 //newbi->move2RelPos (p);
2383 // Move selection to new branch
2384 relinkBranch (selbi,newbi,0);
2386 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2387 QString ("Add branch before %1").arg(getObjectName(selbi)));
2389 // FIXME-3 needed? reposition();
2390 // emitSelectionChanged(); FIXME-3
2396 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2402 emit (layoutAboutToBeChanged() );
2403 BranchItem *branchpi=(BranchItem*)branch->parent();
2404 // Remove at current position
2405 int n=branch->childNum();
2407 /* FIXME-4 seg since 20091207, if ModelTest active. strange.
2408 // error occured if relinking branch to empty mainbranch
2409 cout<<"VM::relinkBranch:\n";
2410 cout<<" b="<<branch->getHeadingStd()<<endl;
2411 cout<<" dst="<<dst->getHeadingStd()<<endl;
2412 cout<<" pos="<<pos<<endl;
2413 cout<<" n1="<<n<<endl;
2415 beginRemoveRows (index(branchpi),n,n);
2416 branchpi->removeChild (n);
2419 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2421 // Append as last branch to dst
2422 if (dst->branchCount()==0)
2425 n=dst->getFirstBranch()->childNumber();
2426 beginInsertRows (index(dst),n+pos,n+pos);
2427 dst->insertBranch (pos,branch);
2430 // Correct type if necessesary
2431 if (branch->getType()==TreeItem::MapCenter)
2432 branch->setType(TreeItem::Branch);
2434 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2435 branch->updateStyles();
2437 emit (layoutChanged() );
2438 reposition(); // both for moveUp/Down and relinking
2439 if (dst->isScrolled() )
2442 branch->updateVisibility();
2451 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2455 emit (layoutAboutToBeChanged() );
2457 BranchItem *pi=(BranchItem*)(image->parent());
2458 QString oldParString=getSelectString (pi);
2459 // Remove at current position
2460 int n=image->childNum();
2461 beginRemoveRows (index(pi),n,n);
2462 pi->removeChild (n);
2466 QModelIndex dstix=index(dst);
2467 n=dst->getRowNumAppend (image);
2468 beginInsertRows (dstix,n,n+1);
2469 dst->appendChild (image);
2472 // Set new parent also for lmo
2473 if (image->getLMO() && dst->getLMO() )
2474 image->getLMO()->setParObj (dst->getLMO() );
2476 emit (layoutChanged() );
2479 QString("relinkTo (\"%1\")").arg(oldParString),
2481 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2482 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2488 void VymModel::deleteSelection()
2490 BranchItem *selbi=getSelectedBranch();
2495 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2497 BranchItem *pi=(BranchItem*)(deleteItem (selbi));
2500 if (pi->isScrolled() && pi->branchCount()==0)
2503 emitDataHasChanged(pi);
2506 emitShowSelection();
2510 TreeItem *ti=getSelectedItem();
2512 { // Delete other item
2513 TreeItem *pi=ti->parent();
2515 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2517 saveStateChangingPart(
2521 QString("Delete %1").arg(getObjectName(ti))
2525 emitDataHasChanged (pi);
2528 emitShowSelection();
2529 } else if (ti->getType()==TreeItem::XLink)
2531 //FIXME-2 savestate missing
2534 qWarning ("VymmModel::deleteSelection() unknown type?!");
2538 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2541 BranchItem *selbi=getSelectedBranch();
2545 // Don't use this on mapcenter
2546 if (selbi->depth()<2) return;
2548 pi=(BranchItem*)(selbi->parent());
2549 // Check if we have childs at all to keep
2550 if (selbi->branchCount()==0)
2557 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2558 saveStateChangingPart(
2561 "deleteKeepChildren ()",
2562 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2565 QString sel=getSelectString(selbi);
2567 int pos=selbi->num();
2568 BranchItem *bi=selbi->getFirstBranch();
2571 relinkBranch (bi,pi,pos);
2572 bi=selbi->getFirstBranch();
2578 BranchObj *bo=getSelectedBranchObj();
2581 bo->move2RelPos (p);
2587 void VymModel::deleteChildren()
2590 BranchItem *selbi=getSelectedBranch();
2593 saveStateChangingPart(
2596 "deleteChildren ()",
2597 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2599 emit (layoutAboutToBeChanged() );
2601 QModelIndex ix=index (selbi);
2602 int n=selbi->branchCount()-1;
2603 beginRemoveRows (ix,0,n);
2604 removeRows (0,n+1,ix);
2606 if (selbi->isScrolled()) selbi->unScroll();
2607 emit (layoutChanged() );
2612 TreeItem* VymModel::deleteItem (TreeItem *ti)
2616 TreeItem *pi=ti->parent();
2617 QModelIndex parentIndex=index(pi);
2619 emit (layoutAboutToBeChanged() );
2621 int n=ti->childNum();
2622 beginRemoveRows (parentIndex,n,n);
2623 removeRows (n,1,parentIndex);
2627 emit (layoutChanged() );
2628 if (pi->depth()>=0) return pi;
2633 void VymModel::clearItem (TreeItem *ti)
2637 QModelIndex parentIndex=index(ti);
2638 if (!parentIndex.isValid()) return;
2640 int n=ti->childCount();
2643 emit (layoutAboutToBeChanged() );
2645 beginRemoveRows (parentIndex,0,n-1);
2646 removeRows (0,n,parentIndex);
2650 emit (layoutChanged() );
2656 bool VymModel::scrollBranch(BranchItem *bi)
2660 if (bi->isScrolled()) return false;
2661 if (bi->branchCount()==0) return false;
2662 if (bi->depth()==0) return false;
2663 if (bi->toggleScroll())
2671 QString ("%1 ()").arg(u),
2673 QString ("%1 ()").arg(r),
2674 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2676 emitDataHasChanged(bi);
2677 emitSelectionChanged();
2678 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2685 bool VymModel::unscrollBranch(BranchItem *bi)
2689 if (!bi->isScrolled()) return false;
2690 if (bi->branchCount()==0) return false;
2691 if (bi->depth()==0) return false;
2692 if (bi->toggleScroll())
2700 QString ("%1 ()").arg(u),
2702 QString ("%1 ()").arg(r),
2703 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2705 emitDataHasChanged(bi);
2706 emitSelectionChanged();
2707 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2714 void VymModel::toggleScroll()
2716 BranchItem *bi=(BranchItem*)getSelectedBranch();
2717 if (bi && bi->isBranchLikeType() )
2719 if (bi->isScrolled())
2720 unscrollBranch (bi);
2724 // saveState & reposition are called in above functions
2727 void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault
2729 BranchItem *selbi=getSelectedBranch();
2730 BranchItem *prev=NULL;
2731 BranchItem *cur=selbi;
2734 saveStateChangingPart(
2737 QString ("unscrollChildren ()"),
2738 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2742 if (cur->isScrolled())
2744 cur->toggleScroll();
2745 emitDataHasChanged (cur);
2747 cur=nextBranch (cur,prev,true,selbi);
2754 void VymModel::emitExpandAll()
2756 emit (expandAll() );
2759 void VymModel::emitExpandOneLevel()
2761 emit (expandOneLevel () );
2764 void VymModel::emitCollapseOneLevel()
2766 emit (collapseOneLevel () );
2769 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2771 BranchItem *bi=getSelectedBranch();
2775 if (bi->isActiveStandardFlag(name))
2787 QString("%1 (\"%2\")").arg(u).arg(name),
2789 QString("%1 (\"%2\")").arg(r).arg(name),
2790 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2791 bi->toggleStandardFlag (name, master);
2793 emitSelectionChanged();
2797 void VymModel::addFloatImage (const QPixmap &img)
2799 BranchItem *selbi=getSelectedBranch();
2802 ImageItem *ii=createImage (selbi);
2804 ii->setOriginalFilename("No original filename (image added by dropevent)");
2805 QString s=getSelectString(selbi);
2806 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2807 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2809 // FIXME-3 VM needed? scene()->update();
2814 void VymModel::colorBranch (QColor c)
2816 BranchItem *selbi=getSelectedBranch();
2821 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2823 QString ("colorBranch (\"%1\")").arg(c.name()),
2824 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2826 selbi->setHeadingColor(c); // color branch
2831 void VymModel::colorSubtree (QColor c)
2833 BranchItem *selbi=getSelectedBranch();
2836 saveStateChangingPart(
2839 QString ("colorSubtree (\"%1\")").arg(c.name()),
2840 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2842 BranchItem *prev=NULL;
2843 BranchItem *cur=selbi;
2846 cur->setHeadingColor(c); // color links, color children
2847 cur=nextBranch (cur,prev,true,selbi);
2853 QColor VymModel::getCurrentHeadingColor()
2855 BranchItem *selbi=getSelectedBranch();
2856 if (selbi) return selbi->getHeadingColor();
2858 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2864 void VymModel::editURL()
2866 TreeItem *selti=getSelectedItem();
2870 QString text = QInputDialog::getText(
2871 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2872 selti->getURL(), &ok, NULL);
2874 // user entered something and pressed OK
2879 void VymModel::editLocalURL()
2881 TreeItem *selti=getSelectedItem();
2884 QStringList filters;
2885 filters <<"All files (*)";
2886 filters << tr("Text","Filedialog") + " (*.txt)";
2887 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2888 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2889 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2890 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2891 fd->setFilters (filters);
2892 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2893 fd->setDirectory (lastFileDir);
2894 if (! selti->getVymLink().isEmpty() )
2895 fd->selectFile( selti->getURL() );
2898 if ( fd->exec() == QDialog::Accepted )
2900 lastFileDir=QDir (fd->directory().path());
2901 setURL (fd->selectedFile() );
2907 void VymModel::editHeading2URL()
2909 TreeItem *selti=getSelectedItem();
2911 setURL (selti->getHeading());
2914 void VymModel::editBugzilla2URL()
2916 TreeItem *selti=getSelectedItem();
2919 QString h=selti->getHeading();
2920 QRegExp rx("^(\\d+)");
2921 if (rx.indexIn(h) !=-1)
2922 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
2926 void VymModel::getBugzillaData()
2928 TreeItem *selti=getSelectedItem();
2931 QString url=selti->getURL();
2934 QRegExp rx("(\\d+)");
2935 if (rx.indexIn(url) !=-1)
2937 QString bugID=rx.cap(1);
2938 cout << "VM::getBugzillaData bug="<<bugID.toStdString()<<endl;
2940 QString script="test/vym-bug.pl";
2942 QProgressDialog progress2("Copying files...", "Abort Copy", 0, 40, mainWindow);
2943 progress2.setWindowModality(Qt::WindowModal);
2944 progress2.setValue (3);
2946 QProgressDialog progress ("Contacting Bugzilla...","empty",0,0);
2947 progress.setCancelButton (NULL);
2948 progress.setWindowModality(Qt::WindowModal);
2953 p.start (script,QStringList()<<bugID);
2954 if (!p.waitForStarted())
2956 cout <<"VM::getBugzillaData couldn't start "<<script.toStdString()<<endl;
2959 if (!p.waitForFinished())
2961 cout <<"VM::getBugzillaData couldn't finish "<<script.toStdString()<<endl;
2966 //QByteArray result=p.readAll();
2967 QString result=p.getStdout();
2968 while (result.endsWith("\n")) result.chop(1);
2969 //cout << QString(result).toStdString()<<endl;
2970 QString err=p.getErrout();
2973 cout << "VM::getBugzillaData Error:\n";
2974 cout <<err.toStdString()<<endl;
2976 else if (!result.isEmpty())
2978 QString heading,cdate,mdate,state,whiteboard;
2979 QRegExp re("short_desc:(.*)\n");
2980 re.setMinimal(true);
2981 if (re.indexIn (result) !=-1) heading=re.cap(1);
2983 re.setPattern ("creation_ts:(.*)\\s");
2984 if (re.indexIn (result) !=-1) cdate=re.cap(1);
2986 re.setPattern ("delta_ts:(.*)\\s");
2987 if (re.indexIn (result) !=-1) mdate=re.cap(1);
2989 re.setPattern ("bug_status:(.*)\n");
2990 if (re.indexIn (result) !=-1) state=re.cap(1);
2992 re.setPattern ("status_whiteboard:(.*)\n");
2993 if (re.indexIn (result) !=-1) whiteboard=re.cap(1);
2995 setHeading (bugID + " - " + heading);
2996 cout << "VM: heading="<<heading.toStdString()<<endl;
2997 cout << "VM: cdate="<<cdate.toStdString()<<endl;
2998 cout << "VM: mdate="<<mdate.toStdString()<<endl;
2999 cout << "VM: state="<<state.toStdString()<<endl;
3000 cout << "VM: wboard="<<whiteboard.toStdString()<<endl;
3002 //cout <<"VM::getBugzillaData "<<script.toStdString()<<" returned:\n";
3003 //cout <<QString(result).toStdString()<<endl;
3005 cout << "VM::getBugzillaData "<<script.toStdString()<<" returned nothing\n";
3011 void VymModel::editFATE2URL()
3013 TreeItem *selti=getSelectedItem();
3016 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
3019 "setURL (\""+selti->getURL()+"\")",
3021 "setURL (\""+url+"\")",
3022 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
3024 selti->setURL (url);
3025 // FIXME-4 updateActions();
3029 void VymModel::editVymLink()
3031 BranchItem *bi=getSelectedBranch();
3034 QStringList filters;
3035 filters <<"VYM map (*.vym)";
3036 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
3037 fd->setFilters (filters);
3038 fd->setCaption(vymName+" - " +tr("Link to another map"));
3039 fd->setDirectory (lastFileDir);
3040 if (! bi->getVymLink().isEmpty() )
3041 fd->selectFile( bi->getVymLink() );
3045 if ( fd->exec() == QDialog::Accepted )
3047 lastFileDir=QDir (fd->directory().path());
3050 "setVymLink (\""+bi->getVymLink()+"\")",
3052 "setVymLink (\""+fd->selectedFile()+"\")",
3053 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
3055 setVymLink (fd->selectedFile() ); // FIXME-2 ok?
3060 void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
3062 // Internal function, no saveState needed
3063 TreeItem *selti=getSelectedItem();
3066 selti->setVymLink(s);
3068 emitDataHasChanged (selti);
3069 emitShowSelection();
3073 void VymModel::deleteVymLink()
3075 BranchItem *bi=getSelectedBranch();
3080 "setVymLink (\""+bi->getVymLink()+"\")",
3082 "setVymLink (\"\")",
3083 QString("Unset vymlink of %1").arg(getObjectName(bi))
3085 bi->setVymLink ("" );
3091 QString VymModel::getVymLink()
3093 BranchItem *bi=getSelectedBranch();
3095 return bi->getVymLink();
3101 QStringList VymModel::getVymLinks()
3104 BranchItem *selbi=getSelectedBranch();
3105 BranchItem *cur=selbi;
3106 BranchItem *prev=NULL;
3109 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
3110 cur=nextBranch (cur,prev,true,selbi);
3116 void VymModel::followXLink(int i)
3119 BranchItem *selbi=getSelectedBranch();
3122 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
3123 if (selbi) select (selbi);
3127 void VymModel::editXLink(int i)
3130 BranchItem *selbi=getSelectedBranch();
3133 XLinkItem *xli=selbi->getXLinkNum(i);
3136 EditXLinkDialog dia;
3138 dia.setSelection(selbi);
3139 if (dia.exec() == QDialog::Accepted)
3141 if (dia.useSettingsGlobal() )
3143 setMapDefXLinkColor (xli->getColor() );
3144 setMapDefXLinkWidth (xli->getWidth() );
3146 if (dia.deleteXLink()) deleteItem (xli);
3156 //////////////////////////////////////////////
3158 //////////////////////////////////////////////
3160 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3162 TreeItem* selti=getSelectedItem();
3163 BranchItem *selbi=getSelectedBranch();
3168 QVariant returnValue;
3170 // Split string s into command and parameters
3171 parser.parseAtom (atom);
3172 QString com=parser.getCommand();
3174 // External commands
3175 /////////////////////////////////////////////////////////////////////
3176 if (com=="addBranch")
3180 parser.setError (Aborted,"Nothing selected");
3181 } else if (! selbi )
3183 parser.setError (Aborted,"Type of selection is not a branch");
3188 if (parser.checkParCount(pl))
3190 if (parser.parCount()==0)
3194 n=parser.parInt (ok,0);
3195 if (ok ) addNewBranch (n);
3199 /////////////////////////////////////////////////////////////////////
3200 } else if (com=="addBranchBefore")
3204 parser.setError (Aborted,"Nothing selected");
3205 } else if (! selbi )
3207 parser.setError (Aborted,"Type of selection is not a branch");
3210 if (parser.parCount()==0)
3212 addNewBranchBefore ();
3215 /////////////////////////////////////////////////////////////////////
3216 } else if (com==QString("addMapCenter"))
3218 if (parser.checkParCount(2))
3220 x=parser.parDouble (ok,0);
3223 y=parser.parDouble (ok,1);
3224 if (ok) addMapCenter (QPointF(x,y));
3227 /////////////////////////////////////////////////////////////////////
3228 } else if (com==QString("addMapReplace"))
3232 parser.setError (Aborted,"Nothing selected");
3233 } else if (! selbi )
3235 parser.setError (Aborted,"Type of selection is not a branch");
3236 } else if (parser.checkParCount(1))
3238 //s=parser.parString (ok,0); // selection
3239 t=parser.parString (ok,0); // path to map
3240 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3241 addMapReplaceInt(getSelectString(selbi),t);
3243 /////////////////////////////////////////////////////////////////////
3244 } else if (com==QString("addMapInsert"))
3246 if (parser.parCount()==2)
3251 parser.setError (Aborted,"Nothing selected");
3252 } else if (! selbi )
3254 parser.setError (Aborted,"Type of selection is not a branch");
3257 t=parser.parString (ok,0); // path to map
3258 n=parser.parInt(ok,1); // position
3259 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3260 addMapInsertInt(t,n);
3262 } else if (parser.parCount()==1)
3264 t=parser.parString (ok,0); // path to map
3265 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3268 parser.setError (Aborted,"Wrong number of parameters");
3269 /////////////////////////////////////////////////////////////////////
3270 } else if (com==QString("addXLink"))
3272 if (parser.parCount()>1)
3274 s=parser.parString (ok,0); // begin
3275 t=parser.parString (ok,1); // end
3276 BranchItem *begin=(BranchItem*)findBySelectString(s);
3277 BranchItem *end=(BranchItem*)findBySelectString(t);
3280 if (begin->isBranchLikeType() && end->isBranchLikeType())
3282 XLinkItem *xl=createXLink (begin,true);
3288 parser.setError (Aborted,"Failed to create xLink");
3291 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3294 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3296 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3297 /////////////////////////////////////////////////////////////////////
3298 } else if (com=="clearFlags")
3302 parser.setError (Aborted,"Nothing selected");
3303 } else if (! selbi )
3305 parser.setError (Aborted,"Type of selection is not a branch");
3306 } else if (parser.checkParCount(0))
3308 selbi->deactivateAllStandardFlags();
3310 /////////////////////////////////////////////////////////////////////
3311 } else if (com=="colorBranch")
3315 parser.setError (Aborted,"Nothing selected");
3316 } else if (! selbi )
3318 parser.setError (Aborted,"Type of selection is not a branch");
3319 } else if (parser.checkParCount(1))
3321 QColor c=parser.parColor (ok,0);
3322 if (ok) colorBranch (c);
3324 /////////////////////////////////////////////////////////////////////
3325 } else if (com=="colorSubtree")
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) colorSubtree (c);
3338 /////////////////////////////////////////////////////////////////////
3339 } else if (com=="copy")
3343 parser.setError (Aborted,"Nothing selected");
3344 } else if ( selectionType()!=TreeItem::Branch &&
3345 selectionType()!=TreeItem::MapCenter &&
3346 selectionType()!=TreeItem::Image )
3348 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3349 } else if (parser.checkParCount(0))
3353 /////////////////////////////////////////////////////////////////////
3354 } else if (com=="cut")
3358 parser.setError (Aborted,"Nothing selected");
3359 } else if ( selectionType()!=TreeItem::Branch &&
3360 selectionType()!=TreeItem::MapCenter &&
3361 selectionType()!=TreeItem::Image )
3363 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3364 } else if (parser.checkParCount(0))
3368 /////////////////////////////////////////////////////////////////////
3369 } else if (com=="delete")
3373 parser.setError (Aborted,"Nothing selected");
3375 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3377 parser.setError (Aborted,"Type of selection is wrong.");
3380 else if (parser.checkParCount(0))
3384 /////////////////////////////////////////////////////////////////////
3385 } else if (com=="deleteKeepChildren")
3389 parser.setError (Aborted,"Nothing selected");
3390 } else if (! selbi )
3392 parser.setError (Aborted,"Type of selection is not a branch");
3393 } else if (parser.checkParCount(0))
3395 deleteKeepChildren();
3397 /////////////////////////////////////////////////////////////////////
3398 } else if (com=="deleteChildren")
3402 parser.setError (Aborted,"Nothing selected");
3405 parser.setError (Aborted,"Type of selection is not a branch");
3406 } else if (parser.checkParCount(0))
3410 /////////////////////////////////////////////////////////////////////
3411 } else if (com=="exportAO")
3415 if (parser.parCount()>=1)
3416 // Hey, we even have a filename
3417 fname=parser.parString(ok,0);
3420 parser.setError (Aborted,"Could not read filename");
3423 exportAO (fname,false);
3425 /////////////////////////////////////////////////////////////////////
3426 } else if (com=="exportASCII")
3430 if (parser.parCount()>=1)
3431 // Hey, we even have a filename
3432 fname=parser.parString(ok,0);
3435 parser.setError (Aborted,"Could not read filename");
3438 exportASCII (fname,false);
3440 /////////////////////////////////////////////////////////////////////
3441 } else if (com=="exportImage")
3445 if (parser.parCount()>=2)
3446 // Hey, we even have a filename
3447 fname=parser.parString(ok,0);
3450 parser.setError (Aborted,"Could not read filename");
3453 QString format="PNG";
3454 if (parser.parCount()>=2)
3456 format=parser.parString(ok,1);
3458 exportImage (fname,false,format);
3460 /////////////////////////////////////////////////////////////////////
3461 } else if (com=="exportXHTML")
3465 if (parser.parCount()>=2)
3466 // Hey, we even have a filename
3467 fname=parser.parString(ok,1);
3470 parser.setError (Aborted,"Could not read filename");
3473 exportXHTML (fname,false);
3475 /////////////////////////////////////////////////////////////////////
3476 } else if (com=="exportXML")
3480 if (parser.parCount()>=2)
3481 // Hey, we even have a filename
3482 fname=parser.parString(ok,1);
3485 parser.setError (Aborted,"Could not read filename");
3488 exportXML (fname,false);
3490 /////////////////////////////////////////////////////////////////////
3491 } else if (com=="getHeading")
3495 parser.setError (Aborted,"Nothing selected");
3496 } else if (parser.checkParCount(0))
3497 returnValue=selti->getHeading();
3498 /////////////////////////////////////////////////////////////////////
3499 } else if (com=="importDir")
3503 parser.setError (Aborted,"Nothing selected");
3504 } else if (! selbi )
3506 parser.setError (Aborted,"Type of selection is not a branch");
3507 } else if (parser.checkParCount(1))
3509 s=parser.parString(ok,0);
3510 if (ok) importDirInt(s);
3512 /////////////////////////////////////////////////////////////////////
3513 } else if (com=="relinkTo")
3517 parser.setError (Aborted,"Nothing selected");
3520 if (parser.checkParCount(4))
3522 // 0 selectstring of parent
3523 // 1 num in parent (for branches)
3524 // 2,3 x,y of mainbranch or mapcenter
3525 s=parser.parString(ok,0);
3526 TreeItem *dst=findBySelectString (s);
3529 if (dst->getType()==TreeItem::Branch)
3531 // Get number in parent
3532 n=parser.parInt (ok,1);
3535 relinkBranch (selbi,(BranchItem*)dst,n);
3536 emitSelectionChanged();
3538 } else if (dst->getType()==TreeItem::MapCenter)
3540 relinkBranch (selbi,(BranchItem*)dst);
3541 // Get coordinates of mainbranch
3542 x=parser.parDouble(ok,2);
3545 y=parser.parDouble(ok,3);
3548 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3549 emitSelectionChanged();
3555 } else if ( selti->getType() == TreeItem::Image)
3557 if (parser.checkParCount(1))
3559 // 0 selectstring of parent
3560 s=parser.parString(ok,0);
3561 TreeItem *dst=findBySelectString (s);
3564 if (dst->isBranchLikeType())
3565 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3567 parser.setError (Aborted,"Destination is not a branch");
3570 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3571 /////////////////////////////////////////////////////////////////////
3572 } else if (com=="loadImage")
3576 parser.setError (Aborted,"Nothing selected");
3577 } else if (! selbi )
3579 parser.setError (Aborted,"Type of selection is not a branch");
3580 } else if (parser.checkParCount(1))
3582 s=parser.parString(ok,0);
3583 if (ok) loadFloatImageInt (selbi,s);
3585 /////////////////////////////////////////////////////////////////////
3586 } else if (com=="moveUp")
3590 parser.setError (Aborted,"Nothing selected");
3591 } else if (! selbi )
3593 parser.setError (Aborted,"Type of selection is not a branch");
3594 } else if (parser.checkParCount(0))
3598 /////////////////////////////////////////////////////////////////////
3599 } else if (com=="moveDown")
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=="move")
3616 parser.setError (Aborted,"Nothing selected");
3617 } else if ( selectionType()!=TreeItem::Branch &&
3618 selectionType()!=TreeItem::MapCenter &&
3619 selectionType()!=TreeItem::Image )
3621 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3622 } else if (parser.checkParCount(2))
3624 x=parser.parDouble (ok,0);
3627 y=parser.parDouble (ok,1);
3631 /////////////////////////////////////////////////////////////////////
3632 } else if (com=="moveRel")
3636 parser.setError (Aborted,"Nothing selected");
3637 } else if ( selectionType()!=TreeItem::Branch &&
3638 selectionType()!=TreeItem::MapCenter &&
3639 selectionType()!=TreeItem::Image )
3641 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3642 } else if (parser.checkParCount(2))
3644 x=parser.parDouble (ok,0);
3647 y=parser.parDouble (ok,1);
3648 if (ok) moveRel (x,y);
3651 /////////////////////////////////////////////////////////////////////
3652 } else if (com=="nop")
3654 /////////////////////////////////////////////////////////////////////
3655 } else if (com=="paste")
3659 parser.setError (Aborted,"Nothing selected");
3660 } else if (! selbi )
3662 parser.setError (Aborted,"Type of selection is not a branch");
3663 } else if (parser.checkParCount(1))
3665 n=parser.parInt (ok,0);
3666 if (ok) pasteNoSave(n);
3668 /////////////////////////////////////////////////////////////////////
3669 } else if (com=="qa")
3673 parser.setError (Aborted,"Nothing selected");
3674 } else if (! selbi )
3676 parser.setError (Aborted,"Type of selection is not a branch");
3677 } else if (parser.checkParCount(4))
3680 c=parser.parString (ok,0);
3683 parser.setError (Aborted,"No comment given");
3686 s=parser.parString (ok,1);
3689 parser.setError (Aborted,"First parameter is not a string");
3692 t=parser.parString (ok,2);
3695 parser.setError (Aborted,"Condition is not a string");
3698 u=parser.parString (ok,3);
3701 parser.setError (Aborted,"Third parameter is not a string");
3706 parser.setError (Aborted,"Unknown type: "+s);
3711 parser.setError (Aborted,"Unknown operator: "+t);
3716 parser.setError (Aborted,"Type of selection is not a branch");
3719 if (selbi->getHeading() == u)
3721 cout << "PASSED: " << qPrintable (c) << endl;
3724 cout << "FAILED: " << qPrintable (c) << endl;
3734 /////////////////////////////////////////////////////////////////////
3735 } else if (com=="saveImage")
3737 ImageItem *ii=getSelectedImage();
3740 parser.setError (Aborted,"No image selected");
3741 } else if (parser.checkParCount(2))
3743 s=parser.parString(ok,0);
3746 t=parser.parString(ok,1);
3747 if (ok) saveFloatImageInt (ii,t,s);
3750 /////////////////////////////////////////////////////////////////////
3751 } else if (com=="scroll")
3755 parser.setError (Aborted,"Nothing selected");
3756 } else if (! selbi )
3758 parser.setError (Aborted,"Type of selection is not a branch");
3759 } else if (parser.checkParCount(0))
3761 if (!scrollBranch (selbi))
3762 parser.setError (Aborted,"Could not scroll branch");
3764 /////////////////////////////////////////////////////////////////////
3765 } else if (com=="select")
3767 if (parser.checkParCount(1))
3769 s=parser.parString(ok,0);
3772 /////////////////////////////////////////////////////////////////////
3773 } else if (com=="selectLastBranch")
3777 parser.setError (Aborted,"Nothing selected");
3778 } else if (! selbi )
3780 parser.setError (Aborted,"Type of selection is not a branch");
3781 } else if (parser.checkParCount(0))
3783 BranchItem *bi=selbi->getLastBranch();
3785 parser.setError (Aborted,"Could not select last branch");
3786 select (bi); // FIXME-3 was selectInt
3789 /////////////////////////////////////////////////////////////////////
3790 } else /* FIXME-2 if (com=="selectLastImage")
3794 parser.setError (Aborted,"Nothing selected");
3795 } else if (! selbi )
3797 parser.setError (Aborted,"Type of selection is not a branch");
3798 } else if (parser.checkParCount(0))
3800 FloatImageObj *fio=selb->getLastFloatImage();
3802 parser.setError (Aborted,"Could not select last image");
3803 select (fio); // FIXME-3 was selectInt
3806 /////////////////////////////////////////////////////////////////////
3807 } else */ if (com=="selectLatestAdded")
3809 if (!latestAddedItem)
3811 parser.setError (Aborted,"No latest added object");
3814 if (!select (latestAddedItem))
3815 parser.setError (Aborted,"Could not select latest added object ");
3817 /////////////////////////////////////////////////////////////////////
3818 } else if (com=="setFlag")
3822 parser.setError (Aborted,"Nothing selected");
3823 } else if (! selbi )
3825 parser.setError (Aborted,"Type of selection is not a branch");
3826 } else if (parser.checkParCount(1))
3828 s=parser.parString(ok,0);
3830 selbi->activateStandardFlag(s);
3832 /////////////////////////////////////////////////////////////////////
3833 } else if (com=="setFrameType")
3835 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3837 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3839 else if (parser.checkParCount(1))
3841 s=parser.parString(ok,0);
3842 if (ok) setFrameType (s);
3844 /////////////////////////////////////////////////////////////////////
3845 } else if (com=="setFramePenColor")
3847 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3849 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3851 else if (parser.checkParCount(1))
3853 QColor c=parser.parColor(ok,0);
3854 if (ok) setFramePenColor (c);
3856 /////////////////////////////////////////////////////////////////////
3857 } else if (com=="setFrameBrushColor")
3859 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3861 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3863 else if (parser.checkParCount(1))
3865 QColor c=parser.parColor(ok,0);
3866 if (ok) setFrameBrushColor (c);
3868 /////////////////////////////////////////////////////////////////////
3869 } else if (com=="setFramePadding")
3871 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3873 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3875 else if (parser.checkParCount(1))
3877 n=parser.parInt(ok,0);
3878 if (ok) setFramePadding(n);
3880 /////////////////////////////////////////////////////////////////////
3881 } else if (com=="setFrameBorderWidth")
3883 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3885 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3887 else if (parser.checkParCount(1))
3889 n=parser.parInt(ok,0);
3890 if (ok) setFrameBorderWidth (n);
3892 /////////////////////////////////////////////////////////////////////
3893 /* FIXME-2 else if (com=="setFrameType")
3897 parser.setError (Aborted,"Nothing selected");
3900 parser.setError (Aborted,"Type of selection is not a branch");
3901 } else if (parser.checkParCount(1))
3903 s=parser.parString(ok,0);
3907 /////////////////////////////////////////////////////////////////////
3909 /////////////////////////////////////////////////////////////////////
3910 } else if (com=="setHeading")
3914 parser.setError (Aborted,"Nothing selected");
3915 } else if (! selbi )
3917 parser.setError (Aborted,"Type of selection is not a branch");
3918 } else if (parser.checkParCount(1))
3920 s=parser.parString (ok,0);
3924 /////////////////////////////////////////////////////////////////////
3925 } else if (com=="setHideExport")
3929 parser.setError (Aborted,"Nothing selected");
3930 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3932 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3933 } else if (parser.checkParCount(1))
3935 b=parser.parBool(ok,0);
3936 if (ok) setHideExport (b);
3938 /////////////////////////////////////////////////////////////////////
3939 } else if (com=="setIncludeImagesHorizontally")
3943 parser.setError (Aborted,"Nothing selected");
3946 parser.setError (Aborted,"Type of selection is not a branch");
3947 } else if (parser.checkParCount(1))
3949 b=parser.parBool(ok,0);
3950 if (ok) setIncludeImagesHor(b);
3952 /////////////////////////////////////////////////////////////////////
3953 } else if (com=="setIncludeImagesVertically")
3957 parser.setError (Aborted,"Nothing selected");
3960 parser.setError (Aborted,"Type of selection is not a branch");
3961 } else if (parser.checkParCount(1))
3963 b=parser.parBool(ok,0);
3964 if (ok) setIncludeImagesVer(b);
3966 /////////////////////////////////////////////////////////////////////
3967 } else if (com=="setHideLinkUnselected")
3971 parser.setError (Aborted,"Nothing selected");
3972 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3974 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3975 } else if (parser.checkParCount(1))
3977 b=parser.parBool(ok,0);
3978 if (ok) setHideLinkUnselected(b);
3980 /////////////////////////////////////////////////////////////////////
3981 } else if (com=="setMapAuthor")
3983 if (parser.checkParCount(1))
3985 s=parser.parString(ok,0);
3986 if (ok) setAuthor (s);
3988 /////////////////////////////////////////////////////////////////////
3989 } else if (com=="setMapComment")
3991 if (parser.checkParCount(1))
3993 s=parser.parString(ok,0);
3994 if (ok) setComment(s);
3996 /////////////////////////////////////////////////////////////////////
3997 } else if (com=="setMapBackgroundColor")
4001 parser.setError (Aborted,"Nothing selected");
4002 } else if (! selbi )
4004 parser.setError (Aborted,"Type of selection is not a branch");
4005 } else if (parser.checkParCount(1))
4007 QColor c=parser.parColor (ok,0);
4008 if (ok) setMapBackgroundColor (c);
4010 /////////////////////////////////////////////////////////////////////
4011 } else if (com=="setMapDefLinkColor")
4015 parser.setError (Aborted,"Nothing selected");
4016 } else if (! selbi )
4018 parser.setError (Aborted,"Type of selection is not a branch");
4019 } else if (parser.checkParCount(1))
4021 QColor c=parser.parColor (ok,0);
4022 if (ok) setMapDefLinkColor (c);
4024 /////////////////////////////////////////////////////////////////////
4025 } else if (com=="setMapLinkStyle")
4027 if (parser.checkParCount(1))
4029 s=parser.parString (ok,0);
4030 if (ok) setMapLinkStyle(s);
4032 /////////////////////////////////////////////////////////////////////
4033 } else if (com=="setNote")
4037 parser.setError (Aborted,"Nothing selected");
4038 } else if (! selbi )
4040 parser.setError (Aborted,"Type of selection is not a branch");
4041 } else if (parser.checkParCount(1))
4043 s=parser.parString (ok,0);
4047 /////////////////////////////////////////////////////////////////////
4048 } else if (com=="setSelectionColor")
4050 if (parser.checkParCount(1))
4052 QColor c=parser.parColor (ok,0);
4053 if (ok) setSelectionColorInt (c);
4055 /////////////////////////////////////////////////////////////////////
4056 } else if (com=="setURL")
4060 parser.setError (Aborted,"Nothing selected");
4061 } else if (! selbi )
4063 parser.setError (Aborted,"Type of selection is not a branch");
4064 } else if (parser.checkParCount(1))
4066 s=parser.parString (ok,0);
4069 /////////////////////////////////////////////////////////////////////
4070 } else if (com=="setVymLink")
4074 parser.setError (Aborted,"Nothing selected");
4075 } else if (! selbi )
4077 parser.setError (Aborted,"Type of selection is not a branch");
4078 } else if (parser.checkParCount(1))
4080 s=parser.parString (ok,0);
4081 if (ok) setVymLink(s);
4083 } else if (com=="sortChildren")
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(0))
4095 /////////////////////////////////////////////////////////////////////
4096 } else if (com=="toggleFlag")
4100 parser.setError (Aborted,"Nothing selected");
4101 } else if (! selbi )
4103 parser.setError (Aborted,"Type of selection is not a branch");
4104 } else if (parser.checkParCount(1))
4106 s=parser.parString(ok,0);
4108 selbi->toggleStandardFlag(s);
4110 /////////////////////////////////////////////////////////////////////
4111 } else if (com=="unscroll")
4115 parser.setError (Aborted,"Nothing selected");
4116 } else if (! selbi )
4118 parser.setError (Aborted,"Type of selection is not a branch");
4119 } else if (parser.checkParCount(0))
4121 if (!unscrollBranch (selbi))
4122 parser.setError (Aborted,"Could not unscroll branch");
4124 /////////////////////////////////////////////////////////////////////
4125 } else if (com=="unscrollChildren")
4129 parser.setError (Aborted,"Nothing selected");
4130 } else if (! selbi )
4132 parser.setError (Aborted,"Type of selection is not a branch");
4133 } else if (parser.checkParCount(0))
4135 unscrollChildren ();
4137 /////////////////////////////////////////////////////////////////////
4138 } else if (com=="unsetFlag")
4142 parser.setError (Aborted,"Nothing selected");
4143 } else if (! selbi )
4145 parser.setError (Aborted,"Type of selection is not a branch");
4146 } else if (parser.checkParCount(1))
4148 s=parser.parString(ok,0);
4150 selbi->deactivateStandardFlag(s);
4153 parser.setError (Aborted,"Unknown command");
4156 if (parser.errorLevel()==NoError)
4158 // setChanged(); FIXME-2 should not be called e.g. for export?!
4165 // TODO Error handling
4166 qWarning("VymModel::parseAtom: Error!");
4168 qWarning(parser.errorMessage());
4170 errorMsg=parser.errorMessage();
4175 QVariant VymModel::runScript (const QString &script)
4177 parser.setScript (script);
4182 while (parser.next() && noErr)
4184 r=parseAtom(parser.getAtom(),noErr,errMsg);
4185 if (!noErr) //FIXME-3 need dialog box here
4186 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4191 void VymModel::setExportMode (bool b)
4193 // should be called before and after exports
4194 // depending on the settings
4195 if (b && settings.value("/export/useHideExport","true")=="true")
4196 setHideTmpMode (TreeItem::HideExport);
4198 setHideTmpMode (TreeItem::HideNone);
4201 void VymModel::exportImage(QString fname, bool askName, QString format)
4205 fname=getMapName()+".png";
4212 QFileDialog *fd=new QFileDialog (NULL);
4213 fd->setCaption (tr("Export map as image"));
4214 fd->setDirectory (lastImageDir);
4215 fd->setFileMode(QFileDialog::AnyFile);
4216 fd->setFilters (imageIO.getFilters() );
4219 fl=fd->selectedFiles();
4221 format=imageIO.getType(fd->selectedFilter());
4225 setExportMode (true);
4226 mapEditor->getScene()->update(); // FIXME-2 check this...
4227 QImage img (mapEditor->getImage()); //FIXME-2 calls getTotalBBox, but also in ExportHTML::doExport()
4228 img.save(fname, format);
4229 setExportMode (false);
4233 void VymModel::exportXML(QString dir, bool askForName)
4237 dir=browseDirectory(NULL,tr("Export XML to directory"));
4238 if (dir =="" && !reallyWriteDirectory(dir) )
4242 // Hide stuff during export, if settings want this
4243 setExportMode (true);
4245 // Create subdirectories
4248 // write to directory //FIXME-4 check totalBBox here...
4249 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4252 file.setName ( dir + "/"+mapName+".xml");
4253 if ( !file.open( QIODevice::WriteOnly ) )
4255 // This should neverever happen
4256 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4260 // Write it finally, and write in UTF8, no matter what
4261 QTextStream ts( &file );
4262 ts.setEncoding (QTextStream::UnicodeUTF8);
4266 // Now write image, too
4267 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4269 setExportMode (false);
4272 void VymModel::exportAO (QString fname,bool askName)
4277 ex.setFile (mapName+".txt");
4283 //ex.addFilter ("TXT (*.txt)");
4284 ex.setDir(lastImageDir);
4285 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4290 setExportMode(true);
4292 setExportMode(false);
4296 void VymModel::exportASCII(QString fname,bool askName)
4301 ex.setFile (mapName+".txt");
4307 //ex.addFilter ("TXT (*.txt)");
4308 ex.setDir(lastImageDir);
4309 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4314 setExportMode(true);
4316 setExportMode(false);
4320 void VymModel::exportHTML (const QString &dir, bool askForName)
4322 ExportXHTMLDialog dia(NULL);
4323 dia.setFilePath (filePath );
4324 dia.setMapName (mapName );
4326 if (dir!="") dia.setDir (dir);
4333 if (dia.exec()!=QDialog::Accepted)
4337 QDir d (dia.getDir());
4338 // Check, if warnings should be used before overwriting
4339 // the output directory
4340 if (d.exists() && d.count()>0)
4343 warn.showCancelButton (true);
4344 warn.setText(QString(
4345 "The directory %1 is not empty.\n"
4346 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4347 warn.setCaption("Warning: Directory not empty");
4348 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4350 if (warn.exec()!=QDialog::Accepted) ok=false;
4358 // Hide stuff during export, if settings want this
4359 setExportMode (true);
4361 ExportHTML ex (this);
4362 ex.setFile ("x/xxx.html");
4364 setExportMode (false);
4366 //exportXML (dia.getDir(),false );
4367 //dia.doExport(mapName );
4368 //if (dia.hasChanged()) setChanged();
4371 exportImage ("x/xxx.png",false,"PNG");
4376 void VymModel::exportXHTML (const QString &dir, bool askForName)
4378 ExportXHTMLDialog dia(NULL);
4379 dia.setFilePath (filePath );
4380 dia.setMapName (mapName );
4382 if (dir!="") dia.setDir (dir);
4388 if (dia.exec()!=QDialog::Accepted)
4392 QDir d (dia.getDir());
4393 // Check, if warnings should be used before overwriting
4394 // the output directory
4395 if (d.exists() && d.count()>0)
4398 warn.showCancelButton (true);
4399 warn.setText(QString(
4400 "The directory %1 is not empty.\n"
4401 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4402 warn.setCaption("Warning: Directory not empty");
4403 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4405 if (warn.exec()!=QDialog::Accepted) ok=false;
4412 exportXML (dia.getDir(),false );
4413 dia.doExport(mapName );
4414 //if (dia.hasChanged()) setChanged();
4418 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4423 if (ex.setConfigFile(cf))
4425 setExportMode (true);
4426 ex.exportPresentation();
4427 setExportMode (false);
4434 //////////////////////////////////////////////
4436 //////////////////////////////////////////////
4438 void VymModel::registerEditor(QWidget *me)
4440 mapEditor=(MapEditor*)me;
4443 void VymModel::unregisterEditor(QWidget *)
4448 void VymModel::setContextPos(QPointF p)
4453 void VymModel::unsetContextPos()
4455 contextPos=QPointF();
4458 void VymModel::updateNoteFlag()
4460 TreeItem *selti=getSelectedItem();
4469 if (textEditor->isEmpty())
4472 selti->setNote (textEditor->getText());
4473 emitDataHasChanged(selti);
4477 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4479 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4480 if (blockReposition) return;
4482 for (int i=0;i<rootItem->branchCount(); i++)
4483 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4484 //emitSelectionChanged();
4488 void VymModel::setMapLinkStyle (const QString & s)
4493 case LinkableMapObj::Line :
4496 case LinkableMapObj::Parabel:
4497 snow="StyleParabel";
4499 case LinkableMapObj::PolyLine:
4500 snow="StylePolyLine";
4502 case LinkableMapObj::PolyParabel:
4503 snow="StylePolyParabel";
4506 snow="UndefinedStyle";
4511 QString("setMapLinkStyle (\"%1\")").arg(s),
4512 QString("setMapLinkStyle (\"%1\")").arg(snow),
4513 QString("Set map link style (\"%1\")").arg(s)
4517 linkstyle=LinkableMapObj::Line;
4518 else if (s=="StyleParabel")
4519 linkstyle=LinkableMapObj::Parabel;
4520 else if (s=="StylePolyLine")
4521 linkstyle=LinkableMapObj::PolyLine;
4522 else if (s=="StylePolyParabel")
4523 linkstyle=LinkableMapObj::PolyParabel;
4525 linkstyle=LinkableMapObj::UndefinedStyle;
4527 BranchItem *cur=NULL;
4528 BranchItem *prev=NULL;
4530 nextBranch (cur,prev);
4533 bo=(BranchObj*)(cur->getLMO() );
4534 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4535 cur=nextBranch(cur,prev);
4540 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4545 void VymModel::setMapDefLinkColor(QColor col)
4547 if ( !col.isValid() ) return;
4549 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4550 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4551 QString("Set map link color to %1").arg(col.name())
4555 BranchItem *cur=NULL;
4556 BranchItem *prev=NULL;
4558 cur=nextBranch(cur,prev);
4561 bo=(BranchObj*)(cur->getLMO() );
4563 nextBranch(cur,prev);
4568 void VymModel::setMapLinkColorHintInt()
4570 // called from setMapLinkColorHint(lch) or at end of parse
4571 BranchItem *cur=NULL;
4572 BranchItem *prev=NULL;
4574 cur=nextBranch(cur,prev);
4577 bo=(BranchObj*)(cur->getLMO() );
4579 cur=nextBranch(cur,prev);
4583 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4586 setMapLinkColorHintInt();
4589 void VymModel::toggleMapLinkColorHint()
4591 if (linkcolorhint==LinkableMapObj::HeadingColor)
4592 linkcolorhint=LinkableMapObj::DefaultColor;
4594 linkcolorhint=LinkableMapObj::HeadingColor;
4595 BranchItem *cur=NULL;
4596 BranchItem *prev=NULL;
4598 cur=nextBranch(cur,prev);
4601 bo=(BranchObj*)(cur->getLMO() );
4603 nextBranch(cur,prev);
4607 void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
4608 // FIXME-4 for using background image: view.setCacheMode(QGraphicsView::CacheBackground);
4610 Q3FileDialog *fd=new Q3FileDialog( NULL);
4611 fd->setMode (Q3FileDialog::ExistingFile);
4612 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4613 ImagePreview *p =new ImagePreview (fd);
4614 fd->setContentsPreviewEnabled( TRUE );
4615 fd->setContentsPreview( p, p );
4616 fd->setPreviewMode( Q3FileDialog::Contents );
4617 fd->setCaption(vymName+" - " +tr("Load background image"));
4618 fd->setDir (lastImageDir);
4621 if ( fd->exec() == QDialog::Accepted )
4623 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4624 lastImageDir=QDir (fd->dirPath());
4625 setMapBackgroundImage (fd->selectedFile());
4629 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4631 QColor oldcol=mapScene->backgroundBrush().color();
4635 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4637 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4638 QString("Set background color of map to %1").arg(col.name()));
4641 brush.setTextureImage (QPixmap (fn));
4642 mapScene->setBackgroundBrush(brush);
4645 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4647 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4648 if ( !col.isValid() ) return;
4649 setMapBackgroundColor( col );
4653 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4655 QColor oldcol=mapScene->backgroundBrush().color();
4657 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4658 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4659 QString("Set background color of map to %1").arg(col.name()));
4660 mapScene->setBackgroundBrush(col);
4663 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4665 return mapScene->backgroundBrush().color();
4669 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4671 return linkcolorhint;
4674 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4676 return defLinkColor;
4679 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4684 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4686 return defXLinkColor;
4689 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4694 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4696 return defXLinkWidth;
4699 void VymModel::move(const double &x, const double &y)
4702 MapItem *seli = (MapItem*)getSelectedItem();
4703 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4705 LinkableMapObj *lmo=seli->getLMO();
4708 QPointF ap(lmo->getAbsPos());
4712 QString ps=qpointFToString(ap);
4713 QString s=getSelectString(seli);
4716 s, "move "+qpointFToString(to),
4717 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4720 emitSelectionChanged();
4726 void VymModel::moveRel (const double &x, const double &y)
4729 MapItem *seli = (MapItem*)getSelectedItem();
4730 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4732 LinkableMapObj *lmo=seli->getLMO();
4735 QPointF rp(lmo->getRelPos());
4739 QString ps=qpointFToString (lmo->getRelPos());
4740 QString s=getSelectString(seli);
4743 s, "moveRel "+qpointFToString(to),
4744 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4745 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4747 lmo->updateLinkGeometry();
4748 emitSelectionChanged();
4755 void VymModel::animate()
4757 animationTimer->stop();
4760 while (i<animObjList.size() )
4762 bo=(BranchObj*)animObjList.at(i);
4767 animObjList.removeAt(i);
4774 QItemSelection sel=selModel->selection();
4775 emit (selectionChanged(sel,sel));
4778 if (!animObjList.isEmpty()) animationTimer->start();
4782 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4784 if (start==dest) return;
4785 if (bo && bo->getTreeItem()->depth()>0)
4788 ap.setStart (start);
4790 ap.setTicks (animationTicks);
4791 ap.setAnimated (true);
4792 bo->setAnimation (ap);
4793 animObjList.append( bo );
4794 animationTimer->setSingleShot (true);
4795 animationTimer->start(animationInterval);
4799 void VymModel::stopAnimation (MapObj *mo)
4801 int i=animObjList.indexOf(mo);
4803 animObjList.removeAt (i);
4806 void VymModel::sendSelection()
4808 if (netstate!=Server) return;
4809 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4812 void VymModel::newServer()
4816 tcpServer = new QTcpServer(this);
4817 if (!tcpServer->listen(QHostAddress::Any,port)) {
4818 QMessageBox::critical(NULL, "vym server",
4819 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4820 //FIXME-3 needed? we are no widget any longer... close();
4823 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4825 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4828 void VymModel::connectToServer()
4831 server="salam.suse.de";
4833 clientSocket = new QTcpSocket (this);
4834 clientSocket->abort();
4835 clientSocket->connectToHost(server ,port);
4836 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4837 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4838 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4840 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4845 void VymModel::newClient()
4847 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4848 connect(newClient, SIGNAL(disconnected()),
4849 newClient, SLOT(deleteLater()));
4851 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4853 clientList.append (newClient);
4857 void VymModel::sendData(const QString &s)
4859 if (clientList.size()==0) return;
4861 // Create bytearray to send
4863 QDataStream out(&block, QIODevice::WriteOnly);
4864 out.setVersion(QDataStream::Qt_4_0);
4866 // Reserve some space for blocksize
4869 // Write sendCounter
4870 out << sendCounter++;
4875 // Go back and write blocksize so far
4876 out.device()->seek(0);
4877 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4881 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4883 for (int i=0; i<clientList.size(); ++i)
4885 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4886 clientList.at(i)->write (block);
4890 void VymModel::readData ()
4892 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4895 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4899 QDataStream in(clientSocket);
4900 in.setVersion(QDataStream::Qt_4_0);
4908 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4911 parseAtom (t,noErr,errMsg);
4917 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4919 switch (socketError) {
4920 case QAbstractSocket::RemoteHostClosedError:
4922 case QAbstractSocket::HostNotFoundError:
4923 QMessageBox::information(NULL, vymName +" Network client",
4924 "The host was not found. Please check the "
4925 "host name and port settings.");
4927 case QAbstractSocket::ConnectionRefusedError:
4928 QMessageBox::information(NULL, vymName + " Network client",
4929 "The connection was refused by the peer. "
4930 "Make sure the fortune server is running, "
4931 "and check that the host name and port "
4932 "settings are correct.");
4935 QMessageBox::information(NULL, vymName + " Network client",
4936 QString("The following error occurred: %1.")
4937 .arg(clientSocket->errorString()));
4941 /* FIXME-3 Playing with DBUS...
4942 QDBusVariant VymModel::query (const QString &query)
4944 TreeItem *selti=getSelectedItem();
4946 return QDBusVariant (selti->getHeading());
4948 return QDBusVariant ("Nothing selected.");
4952 void VymModel::testslot() //FIXME-3 Playing with DBUS
4954 cout << "VM::testslot called\n";
4957 void VymModel::selectMapSelectionColor()
4959 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4960 setSelectionColor (col);
4963 void VymModel::setSelectionColorInt (QColor col)
4965 if ( !col.isValid() ) return;
4967 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4968 QString("setSelectionColor (%1)").arg(col.name()),
4969 QString("Set color of selection box to %1").arg(col.name())
4972 mapEditor->setSelectionColor (col);
4975 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4977 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4978 //FIXME-3 emitShowSelection();
4982 void VymModel::emitSelectionChanged()
4984 QItemSelection newsel=selModel->selection();
4985 emitSelectionChanged (newsel);
4988 void VymModel::setSelectionColor(QColor col)
4990 if ( !col.isValid() ) return;
4992 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4993 QString("setSelectionColor (%1)").arg(col.name()),
4994 QString("Set color of selection box to %1").arg(col.name())
4996 setSelectionColorInt (col);
4999 QColor VymModel::getSelectionColor()
5001 return mapEditor->getSelectionColor();
5004 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
5007 for (int i=0;i<rootItem->branchCount();i++)
5008 rootItem->getBranchNum(i)->setHideTmp (mode);
5010 if (mode==TreeItem::HideExport)
5016 //////////////////////////////////////////////
5017 // Selection related
5018 //////////////////////////////////////////////
5020 void VymModel::setSelectionModel (QItemSelectionModel *sm)
5025 QItemSelectionModel* VymModel::getSelectionModel()
5030 void VymModel::setSelectionBlocked (bool b)
5035 bool VymModel::isSelectionBlocked()
5037 return selectionBlocked;
5040 bool VymModel::select ()
5042 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
5045 bool VymModel::select (const QString &s)
5052 TreeItem *ti=findBySelectString(s);
5053 if (ti) return select (index(ti));
5057 bool VymModel::select (LinkableMapObj *lmo)
5059 QItemSelection oldsel=selModel->selection();
5062 return select (index (lmo->getTreeItem()) );
5067 bool VymModel::select (TreeItem *ti)
5069 if (ti) return select (index(ti));
5073 bool VymModel::select (const QModelIndex &index)
5075 if (index.isValid() )
5077 selModel->select (index,QItemSelectionModel::ClearAndSelect );
5078 BranchItem *bi=getSelectedBranch();
5079 if (bi) bi->setLastSelectedBranch();
5085 void VymModel::unselect()
5087 if (!selModel->selectedIndexes().isEmpty())
5089 lastSelectString=getSelectString();
5090 selModel->clearSelection();
5094 bool VymModel::reselect()
5096 return select (lastSelectString);
5099 void VymModel::emitShowSelection()
5101 if (!blockReposition)
5102 emit (showSelection() );
5105 void VymModel::emitNoteHasChanged (TreeItem *ti)
5107 QModelIndex ix=index(ti);
5108 emit (noteHasChanged (ix) );
5111 void VymModel::emitDataHasChanged (TreeItem *ti)
5113 QModelIndex ix=index(ti);
5114 emit (dataChanged (ix,ix) );
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;