1 #include <QApplication>
6 #include "attributeitem.h"
8 #include "branchitem.h"
10 #include "editxlinkdialog.h"
12 #include "exporthtmldialog.h"
13 #include "exportxhtmldialog.h"
15 #include "findresultmodel.h"
16 #include "geometry.h" // for addBBox
17 #include "mainwindow.h"
22 #include "warningdialog.h"
23 #include "xlinkitem.h"
24 #include "xml-freemind.h"
30 extern Main *mainWindow;
31 extern QDBusConnection dbusConnection;
33 extern Settings settings;
34 extern QString tmpVymDir;
36 extern TextEditor *textEditor;
37 extern FlagRow *standardFlagsMaster;
39 extern QString clipboardDir;
40 extern QString clipboardFile;
41 extern bool clipboardEmpty;
43 extern ImageIO imageIO;
45 extern QString vymName;
46 extern QString vymVersion;
47 extern QDir vymBaseDir;
49 extern QDir lastImageDir;
50 extern QDir lastFileDir;
52 extern Settings settings;
54 uint VymModel::idLast=0; // make instance
58 //cout << "Const VymModel\n";
60 rootItem->setModel (this);
66 //cout << "Destr VymModel\n";
67 autosaveTimer->stop();
68 fileChangedTimer->stop();
72 void VymModel::clear()
74 while (rootItem->childCount() >0)
75 deleteItem (rootItem->getChildNum(0) );
78 void VymModel::init ()
83 // Also no scene yet (should not be needed anyway) FIXME-3 VM
97 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
98 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
99 mainWindow->updateHistory (undoSet);
102 makeTmpDirectories();
107 fileName=tr("unnamed");
109 blockReposition=false;
110 blockSaveState=false;
112 autosaveTimer=new QTimer (this);
113 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
115 fileChangedTimer=new QTimer (this);
116 fileChangedTimer->start(3000);
117 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
122 selectionBlocked=false;
127 // animations // FIXME-3 switch to new animation system
128 animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated
129 animationTicks=settings.readNumEntry("/animation/ticks",10);
130 animationInterval=settings.readNumEntry("/animation/interval",50);
132 animationTimer=new QTimer (this);
133 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
136 defLinkColor=QColor (0,0,255);
137 defXLinkColor=QColor (180,180,180);
138 linkcolorhint=LinkableMapObj::DefaultColor;
139 linkstyle=LinkableMapObj::PolyParabel;
141 defXLinkColor=QColor (230,230,230);
144 hidemode=TreeItem::HideNone;
149 //Initialize DBUS object
150 adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt
151 if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapID),this))
152 qWarning ("VymModel: Couldn't register DBUS object!");
155 void VymModel::makeTmpDirectories()
157 // Create unique temporary directories
158 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapID);
159 histPath = tmpMapDir+"/history";
165 MapEditor* VymModel::getMapEditor() // FIXME-3 VM better return favourite editor here
170 bool VymModel::isRepositionBlocked()
172 return blockReposition;
175 void VymModel::updateActions() // FIXME-4 maybe don't update if blockReposition is set
177 //cout << "VM::updateActions \n";
178 // Tell mainwindow to update states of actions
179 mainWindow->updateActions();
184 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
186 // tmpdir temporary directory to which data will be written
187 // prefix mapname, which will be appended to images etc.
188 // writeflags Only write flags for "real" save of map, not undo
189 // offset offset of bbox of whole map in scene.
190 // Needed for XML export
199 case LinkableMapObj::Line:
202 case LinkableMapObj::Parabel:
205 case LinkableMapObj::PolyLine:
209 ls="StylePolyParabel";
213 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
215 if (linkcolorhint==LinkableMapObj::HeadingColor)
216 colhint=xml.attribut("linkColorHint","HeadingColor");
218 QString mapAttr=xml.attribut("version",vymVersion);
220 mapAttr+= xml.attribut("author",author) +
221 xml.attribut("comment",comment) +
222 xml.attribut("date",getDate()) +
223 xml.attribut("branchCount", QString().number(branchCount())) +
224 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
225 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
226 xml.attribut("linkStyle", ls ) +
227 xml.attribut("linkColor", defLinkColor.name() ) +
228 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
229 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
230 xml.attribut("mapZoomFactor", QString().setNum(mapEditor->getZoomFactorTarget()) ) +
232 s+=xml.beginElement("vymmap",mapAttr);
235 // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe...
236 standardFlagsMaster->resetUsedCounter();
238 // Build xml recursivly
240 // Save all mapcenters as complete map, if saveSel not set
241 s+=saveTreeToDir(tmpdir,prefix,offset);
244 switch (saveSel->getType())
246 case TreeItem::Branch:
248 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
250 case TreeItem::MapCenter:
252 s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
254 case TreeItem::Image:
256 s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
259 // other types shouldn't be safed directly...
264 // Save local settings
265 s+=settings.getDataXML (destPath);
268 if (getSelectedItem() && !saveSel )
269 s+=xml.valueElement("select",getSelectString());
272 s+=xml.endElement("vymmap");
274 //cout << s.toStdString() << endl;
276 if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
280 QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, const QPointF &offset)
284 for (int i=0; i<rootItem->branchCount(); i++)
285 s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset);
289 void VymModel::setFilePath(QString fpath, QString destname)
291 if (fpath.isEmpty() || fpath=="")
298 filePath=fpath; // becomes absolute path
299 fileName=fpath; // gets stripped of path
300 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
302 // If fpath is not an absolute path, complete it
303 filePath=QDir(fpath).absPath();
304 fileDir=filePath.left (1+filePath.findRev ("/"));
306 // Set short name, too. Search from behind:
307 int i=fileName.findRev("/");
308 if (i>=0) fileName=fileName.remove (0,i+1);
310 // Forget the .vym (or .xml) for name of map
311 mapName=fileName.left(fileName.findRev(".",-1,true) );
315 void VymModel::setFilePath(QString fpath)
317 setFilePath (fpath,fpath);
320 QString VymModel::getFilePath()
325 QString VymModel::getFileName()
330 QString VymModel::getMapName()
335 QString VymModel::getDestPath()
340 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
342 ErrorCode err=success;
344 parseBaseHandler *handler;
348 case VymMap: handler=new parseVYMHandler; break;
349 case FreemindMap : handler=new parseFreemindHandler; break;
351 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
352 "Unknown FileType in VymModel::load()");
356 bool zipped_org=zipped;
360 selModel->clearSelection();
363 BranchItem *bi=getSelectedBranch();
364 if (!bi) return aborted;
365 if (lmode==ImportAdd)
366 saveStateChangingPart(
369 QString("addMapInsert (%1)").arg(fname),
370 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
372 saveStateChangingPart(
375 QString("addMapReplace(%1)").arg(fname),
376 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
380 // Create temporary directory for packing
382 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
385 QMessageBox::critical( 0, tr( "Critical Load Error" ),
386 tr("Couldn't create temporary directory before load\n"));
391 err=unzipDir (tmpZipDir,fname);
401 // Look for mapname.xml
402 xmlfile= fname.left(fname.findRev(".",-1,true));
403 xmlfile=xmlfile.section( '/', -1 );
404 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
405 if (!mfile.exists() )
407 // mapname.xml does not exist, well,
408 // maybe someone renamed the mapname.vym file...
409 // Try to find any .xml in the toplevel
410 // directory of the .vym file
411 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
412 if (flist.count()==1)
414 // Only one entry, take this one
415 xmlfile=tmpZipDir + "/"+flist.first();
418 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
419 *it=tmpZipDir + "/" + *it;
420 // TODO Multiple entries, load all (but only the first one into this ME)
421 //mainWindow->fileLoadFromTmp (flist);
422 //returnCode=1; // Silently forget this attempt to load
423 qWarning ("MainWindow::load (fn) multimap found...");
426 if (flist.isEmpty() )
428 QMessageBox::critical( 0, tr( "Critical Load Error" ),
429 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
432 } //file doesn't exist
434 xmlfile=mfile.name();
437 QFile file( xmlfile);
439 // I am paranoid: file should exist anyway
440 // according to check in mainwindow.
443 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
444 tr(QString("Couldn't open map %1").arg(file.name())));
448 bool blockSaveStateOrg=blockSaveState;
449 blockReposition=true;
451 mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
452 QXmlInputSource source( file);
453 QXmlSimpleReader reader;
454 reader.setContentHandler( handler );
455 reader.setErrorHandler( handler );
456 handler->setModel ( this);
459 // We need to set the tmpDir in order to load files with rel. path
464 tmpdir=fname.left(fname.findRev("/",-1));
465 handler->setTmpDir (tmpdir);
466 handler->setInputFile (file.name());
467 handler->setLoadMode (lmode);
468 bool ok = reader.parse( source );
469 blockReposition=false;
470 blockSaveState=blockSaveStateOrg;
471 mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
476 emitSelectionChanged();
482 autosaveTimer->stop();
485 // Reset timestamp to check for later updates of file
486 fileChangedTime=QFileInfo (destPath).lastModified();
489 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
490 tr( handler->errorProtocol() ) );
492 // Still return "success": the map maybe at least
493 // partially read by the parser
498 removeDir (QDir(tmpZipDir));
500 // Restore original zip state
505 if (mapEditor) mapEditor->setZoomFactorTarget (zoomFactor);
507 //Update view (scene()->update() is not enough)
508 qApp->processEvents(); // Update view (scene()->update() is not enough)
512 ErrorCode VymModel::save (const SaveMode &savemode)
516 QString safeFilePath;
518 ErrorCode err=success;
522 mapFileName=mapName+".xml";
524 // use name given by user, even if he chooses .doc
525 mapFileName=fileName;
527 // Look, if we should zip the data:
530 QMessageBox mb( vymName,
531 tr("The map %1\ndid not use the compressed "
532 "vym file format.\nWriting it uncompressed will also write images \n"
533 "and flags and thus may overwrite files in the "
534 "given directory\n\nDo you want to write the map").arg(filePath),
535 QMessageBox::Warning,
536 QMessageBox::Yes | QMessageBox::Default,
538 QMessageBox::Cancel | QMessageBox::Escape);
539 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
540 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
541 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
544 case QMessageBox::Yes:
545 // save compressed (default file format)
548 case QMessageBox::No:
552 case QMessageBox::Cancel:
559 // First backup existing file, we
560 // don't want to add to old zip archives
564 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
566 QString backupFileName(destPath + "~");
567 QFile backupFile(backupFileName);
568 if (backupFile.exists() && !backupFile.remove())
570 QMessageBox::warning(0, tr("Save Error"),
571 tr("%1\ncould not be removed before saving").arg(backupFileName));
573 else if (!f.rename(backupFileName))
575 QMessageBox::warning(0, tr("Save Error"),
576 tr("%1\ncould not be renamed before saving").arg(destPath));
583 // Create temporary directory for packing
585 tmpZipDir=makeTmpDir (ok,"vym-zip");
588 QMessageBox::critical( 0, tr( "Critical Load Error" ),
589 tr("Couldn't create temporary directory before save\n"));
593 safeFilePath=filePath;
594 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
597 // Create mapName and fileDir
598 makeSubDirs (fileDir);
601 if (savemode==CompleteMap || selModel->selection().isEmpty())
604 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
607 autosaveTimer->stop();
612 if (selectionType()==TreeItem::Image)
615 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
616 // TODO take care of multiselections
619 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
622 qWarning ("ME::saveStringToDisk failed!");
628 if (err==success) err=zipDir (tmpZipDir,destPath);
631 removeDir (QDir(tmpZipDir));
633 // Restore original filepath outside of tmp zip dir
634 setFilePath (safeFilePath);
638 fileChangedTime=QFileInfo (destPath).lastModified();
642 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
644 QString pathDir=path.left(path.findRev("/"));
650 // We need to parse saved XML data
651 parseVYMHandler handler;
652 QXmlInputSource source( file);
653 QXmlSimpleReader reader;
654 reader.setContentHandler( &handler );
655 reader.setErrorHandler( &handler );
656 handler.setModel ( this);
657 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
658 if (undoSel.isEmpty())
662 handler.setLoadMode (NewMap);
666 handler.setLoadMode (ImportReplace);
668 blockReposition=true;
669 bool ok = reader.parse( source );
670 blockReposition=false;
673 // This should never ever happen
674 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
675 handler.errorProtocol());
678 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
681 bool VymModel::addMapInsertInt (const QString &path)
683 QString pathDir=path.left(path.findRev("/"));
689 // We need to parse saved XML data
690 parseVYMHandler handler;
691 QXmlInputSource source( file);
692 QXmlSimpleReader reader;
693 reader.setContentHandler( &handler );
694 reader.setErrorHandler( &handler );
695 handler.setModel (this);
696 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
697 handler.setLoadMode (ImportAdd);
698 blockReposition=true;
699 bool ok = reader.parse( source );
700 blockReposition=false;
701 if ( ok ) return true;
703 // This should never ever happen
704 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
705 handler.errorProtocol());
708 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
712 bool VymModel::addMapInsertInt (const QString &path, int pos)
714 BranchItem *selbi=getSelectedBranch();
717 if (addMapInsertInt (path))
719 if (selbi->depth()>0)
720 relinkBranch (selbi->getLastBranch(), selbi,pos);
724 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
728 qWarning ("ME::addMapInsertInt nothing selected");
732 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
734 ImageItem *ii=createImage(dst);
744 void VymModel::loadFloatImage ()
746 BranchItem *selbi=getSelectedBranch();
750 Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog
751 fd->setMode (Q3FileDialog::ExistingFiles);
752 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
753 ImagePreview *p =new ImagePreview (fd);
754 fd->setContentsPreviewEnabled( TRUE );
755 fd->setContentsPreview( p, p );
756 fd->setPreviewMode( Q3FileDialog::Contents );
757 fd->setCaption(vymName+" - " +tr("Load image"));
758 fd->setDir (lastImageDir);
761 if ( fd->exec() == QDialog::Accepted )
763 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
764 lastImageDir=QDir (fd->dirPath());
767 for (int j=0; j<fd->selectedFiles().count(); j++)
769 s=fd->selectedFiles().at(j);
770 ii=loadFloatImageInt (selbi,s);
771 //FIXME-3 check savestate for loadImage
777 QString ("loadImage (%1)").arg(s ),
778 QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi))
781 // TODO loadFIO error handling
782 qWarning ("Failed to load "+s);
790 void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn)
795 void VymModel::saveFloatImage ()
797 ImageItem *ii=getSelectedImage();
800 QFileDialog *fd=new QFileDialog( NULL);
801 fd->setFilters (imageIO.getFilters());
802 fd->setCaption(vymName+" - " +tr("Save image"));
803 fd->setFileMode( QFileDialog::AnyFile );
804 fd->setDirectory (lastImageDir);
805 // fd->setSelection (fio->getOriginalFilename());
809 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
811 fn=fd->selectedFiles().at(0);
812 if (QFile (fn).exists() )
814 QMessageBox mb( vymName,
815 tr("The file %1 exists already.\n"
816 "Do you want to overwrite it?").arg(fn),
817 QMessageBox::Warning,
818 QMessageBox::Yes | QMessageBox::Default,
819 QMessageBox::Cancel | QMessageBox::Escape,
820 QMessageBox::NoButton );
822 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
823 mb.setButtonText( QMessageBox::No, tr("Cancel"));
826 case QMessageBox::Yes:
829 case QMessageBox::Cancel:
836 saveFloatImageInt (ii,fd->selectedFilter(),fn );
843 void VymModel::importDirInt(BranchItem *dst, QDir d)
845 BranchItem *selbi=getSelectedBranch();
849 // Traverse directories
850 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
851 QFileInfoList list = d.entryInfoList();
854 for (int i = 0; i < list.size(); ++i)
857 if (fi.fileName() != "." && fi.fileName() != ".." )
859 bi=addNewBranchInt(dst,-2);
860 bi->setHeading (fi.fileName() ); // FIXME-3 check this
861 bi->setHeadingColor (QColor("blue"));
863 if ( !d.cd(fi.fileName()) )
864 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
867 // Recursively add subdirs
874 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
875 list = d.entryInfoList();
877 for (int i = 0; i < list.size(); ++i)
880 bi=addNewBranchInt (dst,-2);
881 bi->setHeading (fi.fileName() );
882 bi->setHeadingColor (QColor("black"));
883 if (fi.fileName().right(4) == ".vym" )
884 bi->setVymLink (fi.filePath());
889 void VymModel::importDirInt (const QString &s)
891 BranchItem *selbi=getSelectedBranch();
894 saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
897 importDirInt (selbi,d);
901 void VymModel::importDir() //FIXME-3 check me... (not tested yet)
903 BranchItem *selbi=getSelectedBranch();
907 filters <<"VYM map (*.vym)";
908 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
909 fd->setMode (QFileDialog::DirectoryOnly);
910 fd->setFilters (filters);
911 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
915 if ( fd->exec() == QDialog::Accepted )
917 importDirInt (fd->selectedFile() );
919 //FIXME-3 VM needed? scene()->update();
925 void VymModel::autosave()
930 cout << "VymModel::autosave rejected due to missing filePath\n";
933 QDateTime now=QDateTime().currentDateTime();
935 // Disable autosave, while we have gone back in history
936 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
937 if (redosAvail>0) return;
939 // Also disable autosave for new map without filename
940 if (filePath.isEmpty()) return;
943 if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
945 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
946 mainWindow->fileSave (this);
949 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
954 void VymModel::fileChanged()
956 // Check if file on disk has changed meanwhile
957 if (!filePath.isEmpty())
959 QDateTime tmod=QFileInfo (filePath).lastModified();
960 if (tmod>fileChangedTime)
962 // FIXME-3 VM switch to current mapeditor and finish lineedits...
963 QMessageBox mb( vymName,
964 tr("The file of the map on disk has changed:\n\n"
965 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
966 QMessageBox::Question,
968 QMessageBox::Cancel | QMessageBox::Default,
969 QMessageBox::NoButton );
971 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
972 mb.setButtonText( QMessageBox::No, tr("Ignore"));
975 case QMessageBox::Yes:
977 load (filePath,NewMap,fileType);
978 case QMessageBox::Cancel:
979 fileChangedTime=tmod; // allow autosave to overwrite newer file!
985 bool VymModel::isDefault()
990 void VymModel::makeDefault()
996 bool VymModel::hasChanged()
1001 void VymModel::setChanged()
1004 autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
1008 latestAddedItem=NULL;
1012 QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete
1014 if (!lmo || !lmo->getTreeItem() ) return QString();
1015 return getObjectName (lmo->getTreeItem() );
1019 QString VymModel::getObjectName (TreeItem *ti)
1022 if (!ti) return QString("Error: NULL has no name!");
1024 if (s=="") s="unnamed";
1026 return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
1029 void VymModel::redo()
1031 // Can we undo at all?
1032 if (redosAvail<1) return;
1034 bool blockSaveStateOrg=blockSaveState;
1035 blockSaveState=true;
1039 if (undosAvail<stepsTotal) undosAvail++;
1041 if (curStep>stepsTotal) curStep=1;
1042 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1043 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1044 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1045 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1046 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1047 QString version=undoSet.readEntry ("/history/version");
1049 /* TODO Maybe check for version, if we save the history
1050 if (!checkVersion(version))
1051 QMessageBox::warning(0,tr("Warning"),
1052 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1055 // Find out current undo directory
1056 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1060 cout << "VymModel::redo() begin\n";
1061 cout << " undosAvail="<<undosAvail<<endl;
1062 cout << " redosAvail="<<redosAvail<<endl;
1063 cout << " curStep="<<curStep<<endl;
1064 cout << " ---------------------------"<<endl;
1065 cout << " comment="<<comment.toStdString()<<endl;
1066 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1067 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1068 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1069 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1070 cout << " ---------------------------"<<endl<<endl;
1073 // select object before redo
1074 if (!redoSelection.isEmpty())
1075 select (redoSelection);
1080 parseAtom (redoCommand,noErr,errMsg);
1082 blockSaveState=blockSaveStateOrg;
1084 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1085 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1086 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1087 undoSet.writeSettings(histPath);
1089 mainWindow->updateHistory (undoSet);
1092 /* TODO remove testing
1093 cout << "ME::redo() end\n";
1094 cout << " undosAvail="<<undosAvail<<endl;
1095 cout << " redosAvail="<<redosAvail<<endl;
1096 cout << " curStep="<<curStep<<endl;
1097 cout << " ---------------------------"<<endl<<endl;
1103 bool VymModel::isRedoAvailable()
1105 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1111 void VymModel::undo()
1113 // Can we undo at all?
1114 if (undosAvail<1) return;
1116 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1118 bool blockSaveStateOrg=blockSaveState;
1119 blockSaveState=true;
1121 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1122 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1123 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1124 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1125 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1126 QString version=undoSet.readEntry ("/history/version");
1128 /* TODO Maybe check for version, if we save the history
1129 if (!checkVersion(version))
1130 QMessageBox::warning(0,tr("Warning"),
1131 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1134 // Find out current undo directory
1135 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1137 // select object before undo
1138 if (!select (undoSelection))
1140 qWarning ("VymModel::undo() Could not select object for undo");
1147 cout << "VymModel::undo() begin\n";
1148 cout << " undosAvail="<<undosAvail<<endl;
1149 cout << " redosAvail="<<redosAvail<<endl;
1150 cout << " curStep="<<curStep<<endl;
1151 cout << " ---------------------------"<<endl;
1152 cout << " comment="<<comment.toStdString()<<endl;
1153 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1154 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1155 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1156 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1157 cout << " ---------------------------"<<endl<<endl;
1162 parseAtom (undoCommand,noErr,errMsg);
1166 if (curStep<1) curStep=stepsTotal;
1170 blockSaveState=blockSaveStateOrg;
1172 cout << "VymModel::undo() end\n";
1173 cout << " undosAvail="<<undosAvail<<endl;
1174 cout << " redosAvail="<<redosAvail<<endl;
1175 cout << " curStep="<<curStep<<endl;
1176 cout << " ---------------------------"<<endl<<endl;
1179 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1180 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1181 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1182 undoSet.writeSettings(histPath);
1184 mainWindow->updateHistory (undoSet);
1186 //emitSelectionChanged();
1189 bool VymModel::isUndoAvailable()
1191 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1197 void VymModel::gotoHistoryStep (int i)
1199 // Restore variables
1200 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1201 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1203 if (i<0) i=undosAvail+redosAvail;
1205 // Clicking above current step makes us undo things
1208 for (int j=0; j<undosAvail-i; j++) undo();
1211 // Clicking below current step makes us redo things
1213 for (int j=undosAvail; j<i; j++)
1215 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1219 // And ignore clicking the current row ;-)
1223 QString VymModel::getHistoryPath()
1225 QString histName(QString("history-%1").arg(curStep));
1226 return (tmpMapDir+"/"+histName);
1229 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
1231 sendData(redoCom); //FIXME-3 testing
1236 if (blockSaveState) return;
1238 if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
1240 // Find out current undo directory
1241 if (undosAvail<stepsTotal) undosAvail++;
1243 if (curStep>stepsTotal) curStep=1;
1245 QString backupXML="";
1246 QString histDir=getHistoryPath();
1247 QString bakMapPath=histDir+"/map.xml";
1249 // Create histDir if not available
1252 makeSubDirs (histDir);
1254 // Save depending on how much needs to be saved
1256 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1258 QString undoCommand="";
1259 if (savemode==UndoCommand)
1261 undoCommand=undoCom;
1263 else if (savemode==PartOfMap )
1265 undoCommand=undoCom;
1266 undoCommand.replace ("PATH",bakMapPath);
1270 if (!backupXML.isEmpty())
1271 // Write XML Data to disk
1272 saveStringToDisk (bakMapPath,backupXML);
1274 // We would have to save all actions in a tree, to keep track of
1275 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1278 // Write the current state to disk
1279 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1280 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1281 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1282 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1283 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1284 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1285 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1286 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1287 undoSet.setEntry (QString("/history/version"),vymVersion);
1288 undoSet.writeSettings(histPath);
1292 // TODO remove after testing
1293 //cout << " into="<< histPath.toStdString()<<endl;
1294 cout << " stepsTotal="<<stepsTotal<<
1295 ", undosAvail="<<undosAvail<<
1296 ", redosAvail="<<redosAvail<<
1297 ", curStep="<<curStep<<endl;
1298 cout << " ---------------------------"<<endl;
1299 cout << " comment="<<comment.toStdString()<<endl;
1300 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1301 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1302 cout << " redoCom="<<redoCom.toStdString()<<endl;
1303 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1304 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1305 cout << " ---------------------------"<<endl;
1308 mainWindow->updateHistory (undoSet);
1314 void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
1316 // save the selected part of the map, Undo will replace part of map
1317 QString undoSelection="";
1319 undoSelection=getSelectString(undoSel);
1321 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1322 QString redoSelection="";
1324 redoSelection=getSelectString(undoSel);
1326 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1329 saveState (PartOfMap,
1330 undoSelection, "addMapReplace (\"PATH\")",
1336 void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
1340 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1343 QString undoSelection;
1344 QString redoSelection=getSelectString(redoSel);
1345 if (redoSel->getType()==TreeItem::Branch)
1347 undoSelection=getSelectString (redoSel->parent());
1348 // save the selected branch of the map, Undo will insert part of map
1349 saveState (PartOfMap,
1350 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
1351 redoSelection, "delete ()",
1355 if (redoSel->getType()==TreeItem::MapCenter)
1357 // save the selected branch of the map, Undo will insert part of map
1358 saveState (PartOfMap,
1359 undoSelection, QString("addMapInsert (\"PATH\")"),
1360 redoSelection, "delete ()",
1367 void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
1369 // "Normal" savestate: save commands, selections and comment
1370 // so just save commands for undo and redo
1371 // and use current selection
1373 QString redoSelection="";
1374 if (redoSel) redoSelection=getSelectString(redoSel);
1375 QString undoSelection="";
1376 if (undoSel) undoSelection=getSelectString(undoSel);
1378 saveState (UndoCommand,
1385 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1387 // "Normal" savestate: save commands, selections and comment
1388 // so just save commands for undo and redo
1389 // and use current selection
1390 saveState (UndoCommand,
1397 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1399 // "Normal" savestate applied to model (no selection needed):
1400 // save commands and comment
1401 saveState (UndoCommand,
1409 QGraphicsScene* VymModel::getScene ()
1414 TreeItem* VymModel::findBySelectString(QString s)
1416 if (s.isEmpty() ) return NULL;
1418 // Old maps don't have multiple mapcenters and don't save full path
1419 if (s.left(2) !="mc")
1422 QStringList parts=s.split (",");
1425 TreeItem *ti=rootItem;
1427 while (!parts.isEmpty() )
1429 typ=parts.first().left(2);
1430 n=parts.first().right(parts.first().length() - 3).toInt();
1431 parts.removeFirst();
1432 if (typ=="mc" || typ=="bo")
1433 ti=ti->getBranchNum (n);
1435 ti=ti->getImageNum (n);
1437 ti=ti->getAttributeNum (n);
1439 ti=ti->getXLinkNum (n);
1440 if(!ti) return NULL;
1445 TreeItem* VymModel::findID (const uint &i) //FIXME-3 Search also other types...
1447 BranchItem *cur=NULL;
1448 BranchItem *prev=NULL;
1449 nextBranch(cur,prev);
1452 if (i==cur->getID() ) return cur;
1453 nextBranch(cur,prev);
1458 //////////////////////////////////////////////
1460 //////////////////////////////////////////////
1461 void VymModel::setVersion (const QString &s)
1466 QString VymModel::getVersion()
1471 void VymModel::setAuthor (const QString &s)
1474 QString ("setMapAuthor (\"%1\")").arg(author),
1475 QString ("setMapAuthor (\"%1\")").arg(s),
1476 QString ("Set author of map to \"%1\"").arg(s)
1481 QString VymModel::getAuthor()
1486 void VymModel::setComment (const QString &s)
1489 QString ("setMapComment (\"%1\")").arg(comment),
1490 QString ("setMapComment (\"%1\")").arg(s),
1491 QString ("Set comment of map")
1496 QString VymModel::getComment ()
1501 QString VymModel::getDate ()
1503 return QDate::currentDate().toString ("yyyy-MM-dd");
1506 int VymModel::branchCount()
1509 BranchItem *cur=NULL;
1510 BranchItem *prev=NULL;
1511 nextBranch(cur,prev);
1515 nextBranch(cur,prev);
1520 void VymModel::setSortFilter (const QString &s)
1523 emit (sortFilterChanged (sortFilter));
1526 QString VymModel::getSortFilter ()
1531 void VymModel::setHeading(const QString &s)
1533 BranchItem *selbi=getSelectedBranch();
1538 "setHeading (\""+selbi->getHeading()+"\")",
1540 "setHeading (\""+s+"\")",
1541 QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
1542 selbi->setHeading(s );
1543 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
1545 emitSelectionChanged();
1549 QString VymModel::getHeading()
1551 TreeItem *selti=getSelectedItem();
1553 return selti->getHeading();
1558 void VymModel::setNote(const QString &s)
1560 TreeItem *selti=getSelectedItem();
1565 "setNote (\""+selti->getNote()+"\")",
1567 "setNote (\""+s+"\")",
1568 QString("Set note of %1 ").arg(getObjectName(selti)) );
1571 emitNoteHasChanged(selti);
1572 emitDataHasChanged(selti);
1575 QString VymModel::getNote()
1577 TreeItem *selti=getSelectedItem();
1579 return selti->getNote();
1584 void VymModel::loadNote (const QString &fn)
1586 BranchItem *selbi=getSelectedBranch();
1590 if (!loadStringFromDisk (fn,n))
1591 qWarning ()<<"VymModel::loadNote Couldn't load "<<fn;
1595 qWarning ("VymModel::loadNote no branch selected");
1598 void VymModel::saveNote (const QString &fn)
1600 BranchItem *selbi=getSelectedBranch();
1603 QString n=selbi->getNote();
1605 qWarning ()<<"VymModel::saveNote note is empty, won't save to "<<fn;
1608 if (!saveStringToDisk (fn,n))
1609 qWarning ()<<"VymModel::saveNote Couldn't save "<<fn;
1614 qWarning ("VymModel::saveNote no branch selected");
1617 void VymModel::findDuplicateURLs() // FIXME-3 needs GUI
1619 // Generate map containing _all_ URLs and branches
1621 QMap <QString,BranchItem*> map;
1622 BranchItem *cur=NULL;
1623 BranchItem *prev=NULL;
1624 nextBranch(cur,prev);
1629 map.insertMulti (u,cur);
1630 nextBranch(cur,prev);
1633 // Extract duplicate URLs
1634 QMap <QString, BranchItem*>::const_iterator i=map.constBegin();
1635 QMap <QString, BranchItem*>::const_iterator firstdup=map.constEnd(); //invalid
1636 while (i != map.constEnd())
1638 if (i!=map.constBegin() && i.key()==firstdup.key())
1640 if ( i-1==firstdup )
1642 cout << firstdup.key().toStdString() << endl;
1643 cout << " - "<< firstdup.value() <<" - "<<firstdup.value()->getHeadingStd()<<endl;
1645 cout << " - "<< i.value() <<" - "<<i.value()->getHeadingStd()<<endl;
1653 void VymModel::findAll (FindResultModel *rmodel, QString s, Qt::CaseSensitivity cs)
1656 rmodel->setSearchString (s);
1657 rmodel->setSearchFlags (0); //FIXME-2 translate cs to QTextDocument::FindFlag
1658 BranchItem *cur=NULL;
1659 BranchItem *prev=NULL;
1660 nextBranch(cur,prev);
1662 FindResultItem *lastParent=NULL;
1666 if (cur->getHeading().contains (s,cs))
1667 lastParent=rmodel->addItem (cur);
1668 QString n=cur->getNoteASCII();
1673 i=n.indexOf (s,i,cs); //FIXME-2 add subitems to rmodel
1676 // If not there yet, add "parent" item
1679 lastParent=rmodel->addItem (cur);
1681 qWarning()<<"VymModel::findAll still no lastParent?!";
1684 lastParent->setSelectable (false);
1688 // save index of occurence
1689 rmodel->addSubItem (lastParent,QString(tr("Note","FindAll in VymModel")+" "+s),cur,j);
1694 nextBranch(cur,prev);
1698 BranchItem* VymModel::findText (QString s,Qt::CaseSensitivity cs)
1700 if (!s.isEmpty() && s!=findString)
1706 QTextDocument::FindFlags flags=0;
1707 if (cs==Qt::CaseSensitive) flags=QTextDocument::FindCaseSensitively;
1710 { // Nothing found or new find process
1712 // nothing found, start again
1716 nextBranch (findCurrent,findPrevious);
1718 bool searching=true;
1719 bool foundNote=false;
1720 while (searching && !EOFind)
1724 // Searching in Note
1725 if (findCurrent->getNote().contains(findString,cs))
1727 select (findCurrent);
1728 if (textEditor->findText(findString,flags))
1734 // Searching in Heading
1735 if (searching && findCurrent->getHeading().contains (findString,cs) )
1737 select(findCurrent);
1743 if (!nextBranch(findCurrent,findPrevious) )
1748 return getSelectedBranch();
1753 void VymModel::findReset()
1754 { // Necessary if text to find changes during a find process
1761 void VymModel::setScene (QGraphicsScene *s)
1766 void VymModel::setURL(const QString &url)
1768 TreeItem *selti=getSelectedItem();
1771 QString oldurl=selti->getURL();
1772 selti->setURL (url);
1775 QString ("setURL (\"%1\")").arg(oldurl),
1777 QString ("setURL (\"%1\")").arg(url),
1778 QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
1781 emitDataHasChanged (selti);
1782 emitShowSelection();
1786 QString VymModel::getURL()
1788 TreeItem *selti=getSelectedItem();
1790 return selti->getURL();
1795 QStringList VymModel::getURLs(bool ignoreScrolled)
1798 BranchItem *selbi=getSelectedBranch();
1799 BranchItem *cur=selbi;
1800 BranchItem *prev=NULL;
1803 if (!cur->getURL().isEmpty() && !(ignoreScrolled && cur->hasScrolledParent(cur) ))
1804 urls.append( cur->getURL());
1805 cur=nextBranch (cur,prev,true,selbi);
1811 void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO
1813 BranchItem *bi=getSelectedBranch();
1816 BranchObj *bo=(BranchObj*)(bi->getLMO());
1819 QString s=bo->getFrameTypeName();
1820 bo->setFrameType (t);
1821 saveState (bi, QString("setFrameType (\"%1\")").arg(s),
1822 bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1824 bo->updateLinkGeometry();
1829 void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO
1831 BranchItem *bi=getSelectedBranch();
1834 BranchObj *bo=(BranchObj*)(bi->getLMO());
1837 saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1838 bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1839 bo->setFrameType (s);
1841 bo->updateLinkGeometry();
1846 void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1849 BranchItem *bi=getSelectedBranch();
1852 BranchObj *bo=(BranchObj*)(bi->getLMO());
1855 saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1856 bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1857 bo->setFramePenColor (c);
1862 void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO
1864 BranchItem *bi=getSelectedBranch();
1867 BranchObj *bo=(BranchObj*)(bi->getLMO());
1870 saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1871 bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1872 bo->setFrameBrushColor (c);
1877 void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO
1879 BranchItem *bi=getSelectedBranch();
1882 BranchObj *bo=(BranchObj*)(bi->getLMO());
1885 saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1886 bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1887 bo->setFramePadding (i);
1889 bo->updateLinkGeometry();
1894 void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO
1896 BranchItem *bi=getSelectedBranch();
1899 BranchObj *bo=(BranchObj*)(bi->getLMO());
1902 saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1903 bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1904 bo->setFrameBorderWidth (i);
1906 bo->updateLinkGeometry();
1911 void VymModel::setIncludeImagesVer(bool b)
1913 BranchItem *bi=getSelectedBranch();
1916 QString u= b ? "false" : "true";
1917 QString r=!b ? "false" : "true";
1921 QString("setIncludeImagesVertically (%1)").arg(u),
1923 QString("setIncludeImagesVertically (%1)").arg(r),
1924 QString("Include images vertically in %1").arg(getObjectName(bi))
1926 bi->setIncludeImagesVer(b);
1927 emitDataHasChanged ( bi);
1932 void VymModel::setIncludeImagesHor(bool b)
1934 BranchItem *bi=getSelectedBranch();
1937 QString u= b ? "false" : "true";
1938 QString r=!b ? "false" : "true";
1942 QString("setIncludeImagesHorizontally (%1)").arg(u),
1944 QString("setIncludeImagesHorizontally (%1)").arg(r),
1945 QString("Include images horizontally in %1").arg(getObjectName(bi))
1947 bi->setIncludeImagesHor(b);
1948 emitDataHasChanged ( bi);
1953 void VymModel::setHideLinkUnselected (bool b)
1955 TreeItem *ti=getSelectedItem();
1956 if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1958 QString u= b ? "false" : "true";
1959 QString r=!b ? "false" : "true";
1963 QString("setHideLinkUnselected (%1)").arg(u),
1965 QString("setHideLinkUnselected (%1)").arg(r),
1966 QString("Hide link of %1 if unselected").arg(getObjectName(ti))
1968 ((MapItem*)ti)->setHideLinkUnselected(b);
1972 void VymModel::setHideExport(bool b)
1974 TreeItem *ti=getSelectedItem();
1976 (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
1978 ti->setHideInExport (b);
1979 QString u= b ? "false" : "true";
1980 QString r=!b ? "false" : "true";
1984 QString ("setHideExport (%1)").arg(u),
1986 QString ("setHideExport (%1)").arg(r),
1987 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r)
1989 emitDataHasChanged(ti);
1990 emitSelectionChanged();
1993 // emitSelectionChanged();
1994 // FIXME-3 VM needed? scene()->update();
1998 void VymModel::toggleHideExport()
2000 TreeItem *selti=getSelectedItem();
2002 setHideExport ( !selti->hideInExport() );
2005 void VymModel::addTimestamp() //FIXME-3 new function, localize
2007 BranchItem *selbi=addNewBranch();
2010 QDate today=QDate::currentDate();
2012 selbi->setHeading (QString ("%1-%2-%3")
2013 .arg(today.year(),4,10,c)
2014 .arg(today.month(),2,10,c)
2015 .arg(today.day(),2,10,c));
2016 emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem?
2023 void VymModel::copy()
2025 TreeItem *selti=getSelectedItem();
2027 (selti->getType() == TreeItem::Branch ||
2028 selti->getType() == TreeItem::MapCenter ||
2029 selti->getType() == TreeItem::Image ))
2031 if (redosAvail == 0)
2034 QString s=getSelectString(selti);
2035 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti );
2036 curClipboard=curStep;
2039 // Copy also to global clipboard, because we are at last step in history
2040 QString bakMapName(QString("history-%1").arg(curStep));
2041 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2042 copyDir (bakMapDir,clipboardDir );
2044 clipboardEmpty=false;
2050 void VymModel::pasteNoSave(const int &n)
2052 bool old=blockSaveState;
2053 blockSaveState=true;
2054 bool zippedOrg=zipped;
2055 if (redosAvail > 0 || n!=0)
2057 // Use the "historical" buffer
2058 QString bakMapName(QString("history-%1").arg(n));
2059 QString bakMapDir(tmpMapDir +"/"+bakMapName);
2060 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
2062 // Use the global buffer
2063 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
2068 void VymModel::paste()
2070 BranchItem *selbi=getSelectedBranch();
2073 saveStateChangingPart(
2076 QString ("paste (%1)").arg(curClipboard),
2077 QString("Paste to %1").arg( getObjectName(selbi))
2084 void VymModel::cut()
2086 TreeItem *selti=getSelectedItem();
2087 if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image))
2095 bool VymModel::moveUp(BranchItem *bi)
2097 if (bi && bi->canMoveUp())
2098 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
2103 void VymModel::moveUp()
2105 BranchItem *selbi=getSelectedBranch();
2108 QString oldsel=getSelectString();
2111 getSelectString(),"moveDown ()",
2113 QString("Move up %1").arg(getObjectName(selbi)));
2117 bool VymModel::moveDown(BranchItem *bi)
2119 if (bi && bi->canMoveDown())
2120 return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
2125 void VymModel::moveDown()
2127 BranchItem *selbi=getSelectedBranch();
2130 QString oldsel=getSelectString();
2131 if ( moveDown(selbi))
2133 getSelectString(),"moveUp ()",
2134 oldsel,"moveDown ()",
2135 QString("Move down %1").arg(getObjectName(selbi)));
2139 void VymModel::detach()
2141 BranchItem *selbi=getSelectedBranch();
2142 if (selbi && selbi->depth()>0)
2144 // if no relPos have been set before, try to use current rel positions
2145 if (selbi->getLMO())
2146 for (int i=0; i<selbi->branchCount();++i)
2147 selbi->getBranchNum(i)->getBranchObj()->setRelPos();
2149 QString oldsel=getSelectString();
2152 BranchObj *bo=selbi->getBranchObj();
2153 if (bo) p=bo->getAbsPos();
2154 QString parsel=getSelectString(selbi->parent());
2155 if ( relinkBranch (selbi,rootItem,-1) )
2157 getSelectString (selbi),
2158 QString("relinkTo (\"%1\",%2,%3,%4)").arg(parsel).arg(n).arg(p.x()).arg(p.y()),
2161 QString("Detach %1").arg(getObjectName(selbi))
2166 void VymModel::sortChildren(bool inverse)
2168 BranchItem* selbi=getSelectedBranch();
2171 if(selbi->branchCount()>1)
2175 saveStateChangingPart(
2176 selbi,selbi, "sortChildren ()",
2177 QString("Sort children of %1").arg(getObjectName(selbi)));
2179 selbi->sortChildren(inverse);
2181 emitShowSelection();
2186 BranchItem* VymModel::createMapCenter()
2188 BranchItem *newbi=addMapCenter (QPointF (0,0) );
2192 BranchItem* VymModel::createBranch(BranchItem *dst)
2195 return addNewBranchInt (dst,-2);
2200 ImageItem* VymModel::createImage(BranchItem *dst)
2207 QList<QVariant> cData;
2208 cData << "new" << "undef";
2210 ImageItem *newii=new ImageItem(cData) ;
2211 //newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
2213 emit (layoutAboutToBeChanged() );
2216 if (!parix.isValid()) cout << "VM::createII invalid index\n";
2217 n=dst->getRowNumAppend(newii);
2218 beginInsertRows (parix,n,n);
2219 dst->appendChild (newii);
2222 emit (layoutChanged() );
2224 // save scroll state. If scrolled, automatically select
2225 // new branch in order to tmp unscroll parent...
2226 newii->createMapObj(mapScene);
2233 XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
2240 QList<QVariant> cData;
2241 cData << "new xLink"<<"undef";
2243 XLinkItem *newxli=new XLinkItem(cData) ;
2244 newxli->setBegin (bi);
2246 emit (layoutAboutToBeChanged() );
2249 n=bi->getRowNumAppend(newxli);
2250 beginInsertRows (parix,n,n);
2251 bi->appendChild (newxli);
2254 emit (layoutChanged() );
2256 // save scroll state. If scrolled, automatically select
2257 // new branch in order to tmp unscroll parent...
2260 newxli->createMapObj(mapScene);
2268 AttributeItem* VymModel::addAttribute()
2270 BranchItem *selbi=getSelectedBranch();
2273 QList<QVariant> cData;
2274 cData << "new attribute" << "undef";
2275 AttributeItem *a=new AttributeItem (cData);
2276 if (addAttribute (a)) return a;
2281 AttributeItem* VymModel::addAttribute(AttributeItem *ai) // FIXME-2 savestate missing
2283 BranchItem *selbi=getSelectedBranch();
2286 emit (layoutAboutToBeChanged() );
2288 QModelIndex parix=index(selbi);
2289 int n=selbi->getRowNumAppend (ai);
2290 beginInsertRows (parix,n,n);
2291 selbi->appendChild (ai);
2294 emit (layoutChanged() );
2296 ai->createMapObj(mapScene); //FIXME-2 check that...
2303 BranchItem* VymModel::addMapCenter ()
2305 BranchItem *bi=addMapCenter (contextPos);
2307 emitShowSelection();
2312 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2313 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2319 BranchItem* VymModel::addMapCenter(QPointF absPos)
2320 // createMapCenter could then probably be merged with createBranch
2324 QModelIndex parix=index(rootItem);
2326 QList<QVariant> cData;
2327 cData << "VM:addMapCenter" << "undef";
2328 BranchItem *newbi=new BranchItem (cData,rootItem);
2329 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2330 int n=rootItem->getRowNumAppend (newbi);
2332 emit (layoutAboutToBeChanged() );
2333 beginInsertRows (parix,n,n);
2335 rootItem->appendChild (newbi);
2338 emit (layoutChanged() );
2341 newbi->setPositionMode (MapItem::Absolute);
2342 BranchObj *bo=newbi->createMapObj(mapScene);
2343 if (bo) bo->move (absPos);
2348 BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
2350 // Depending on pos:
2351 // -3 insert in children of parent above selection
2352 // -2 add branch to selection
2353 // -1 insert in children of parent below selection
2354 // 0..n insert in children of parent at pos
2357 QList<QVariant> cData;
2358 cData << "" << "undef";
2363 BranchItem *newbi=new BranchItem (cData);
2364 //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
2366 emit (layoutAboutToBeChanged() );
2372 n=parbi->getRowNumAppend (newbi);
2373 beginInsertRows (parix,n,n);
2374 parbi->appendChild (newbi);
2376 }else if (num==-1 || num==-3)
2378 // insert below selection
2379 parbi=(BranchItem*)dst->parent();
2382 n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0
2383 beginInsertRows (parix,n,n);
2384 parbi->insertBranch(n,newbi);
2387 emit (layoutChanged() );
2389 // Set color of heading to that of parent
2390 newbi->setHeadingColor (parbi->getHeadingColor());
2392 // save scroll state. If scrolled, automatically select
2393 // new branch in order to tmp unscroll parent...
2394 newbi->createMapObj(mapScene);
2399 BranchItem* VymModel::addNewBranch(int pos)
2401 // Different meaning than num in addNewBranchInt!
2405 BranchItem *newbi=NULL;
2406 BranchItem *selbi=getSelectedBranch();
2410 // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed?
2412 newbi=addNewBranchInt (selbi,pos-2);
2420 QString ("addBranch (%1)").arg(pos),
2421 QString ("Add new branch to %1").arg(getObjectName(selbi)));
2424 // emitSelectionChanged(); FIXME-3
2425 latestAddedItem=newbi;
2426 // In Network mode, the client needs to know where the new branch is,
2427 // so we have to pass on this information via saveState.
2428 // TODO: Get rid of this positioning workaround
2429 /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
2430 sendData ("selectLatestAdded ()");
2431 sendData (QString("move %1").arg(ps));
2440 BranchItem* VymModel::addNewBranchBefore()
2442 BranchItem *newbi=NULL;
2443 BranchItem *selbi=getSelectedBranch();
2444 if (selbi && selbi->getType()==TreeItem::Branch)
2445 // We accept no MapCenter here, so we _have_ a parent
2447 //QPointF p=bo->getRelPos();
2450 // add below selection
2451 newbi=addNewBranchInt (selbi,-1);
2455 //newbi->move2RelPos (p);
2457 // Move selection to new branch
2458 relinkBranch (selbi,newbi,0);
2460 saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()",
2461 QString ("Add branch before %1").arg(getObjectName(selbi)));
2463 // FIXME-3 needed? reposition();
2464 // emitSelectionChanged(); FIXME-3
2470 bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
2476 // Do we need to update frame type?
2477 bool keepFrame=false;
2480 emit (layoutAboutToBeChanged() );
2481 BranchItem *branchpi=(BranchItem*)branch->parent();
2482 // Remove at current position
2483 int n=branch->childNum();
2485 /* FIXME-4 seg since 20091207, if ModelTest active. strange.
2486 // error occured if relinking branch to empty mainbranch
2487 cout<<"VM::relinkBranch:\n";
2488 cout<<" b="<<branch->getHeadingStd()<<endl;
2489 cout<<" dst="<<dst->getHeadingStd()<<endl;
2490 cout<<" pos="<<pos<<endl;
2491 cout<<" n1="<<n<<endl;
2493 beginRemoveRows (index(branchpi),n,n);
2494 branchpi->removeChild (n);
2497 if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
2499 // Append as last branch to dst
2500 if (dst->branchCount()==0)
2503 n=dst->getFirstBranch()->childNumber();
2504 beginInsertRows (index(dst),n+pos,n+pos);
2505 dst->insertBranch (pos,branch);
2508 // Correct type if necessesary
2509 if (branch->getType()==TreeItem::MapCenter)
2510 branch->setType(TreeItem::Branch);
2512 // reset parObj, fonts, frame, etc in related LMO or other view-objects
2513 branch->updateStyles(keepFrame);
2515 emit (layoutChanged() );
2516 reposition(); // both for moveUp/Down and relinking
2517 if (dst->isScrolled() )
2520 branch->updateVisibility();
2529 bool VymModel::relinkImage (ImageItem *image, BranchItem *dst)
2533 emit (layoutAboutToBeChanged() );
2535 BranchItem *pi=(BranchItem*)(image->parent());
2536 QString oldParString=getSelectString (pi);
2537 // Remove at current position
2538 int n=image->childNum();
2539 beginRemoveRows (index(pi),n,n);
2540 pi->removeChild (n);
2544 QModelIndex dstix=index(dst);
2545 n=dst->getRowNumAppend (image);
2546 beginInsertRows (dstix,n,n+1);
2547 dst->appendChild (image);
2550 // Set new parent also for lmo
2551 if (image->getLMO() && dst->getLMO() )
2552 image->getLMO()->setParObj (dst->getLMO() );
2554 emit (layoutChanged() );
2557 QString("relinkTo (\"%1\")").arg(oldParString),
2559 QString ("relinkTo (\"%1\")").arg(getSelectString (dst)),
2560 QString ("Relink floatimage to %1").arg(getObjectName(dst)));
2566 void VymModel::deleteSelection() //FIXME-2 xLinks in a deleted subtree are not restored on undo
2568 BranchItem *selbi=getSelectedBranch();
2573 saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
2575 BranchItem *pi=(BranchItem*)(deleteItem (selbi));
2578 if (pi->isScrolled() && pi->branchCount()==0)
2581 emitDataHasChanged(pi);
2584 emitShowSelection();
2588 TreeItem *ti=getSelectedItem();
2590 { // Delete other item
2591 TreeItem *pi=ti->parent();
2593 if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
2595 saveStateChangingPart(
2599 QString("Delete %1").arg(getObjectName(ti))
2603 emitDataHasChanged (pi);
2606 emitShowSelection();
2607 } else if (ti->getType()==TreeItem::XLink)
2609 //FIXME-2 savestate for deleting xlink missing
2612 qWarning ("VymmModel::deleteSelection() unknown type?!");
2616 void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters
2619 BranchItem *selbi=getSelectedBranch();
2623 // Don't use this on mapcenter
2624 if (selbi->depth()<2) return;
2626 pi=(BranchItem*)(selbi->parent());
2627 // Check if we have children at all to keep
2628 if (selbi->branchCount()==0)
2635 if (selbi->getLMO()) p=selbi->getLMO()->getRelPos();
2636 saveStateChangingPart(
2639 "deleteKeepChildren ()",
2640 QString("Remove %1 and keep its children").arg(getObjectName(selbi))
2643 QString sel=getSelectString(selbi);
2645 int pos=selbi->num();
2646 BranchItem *bi=selbi->getFirstBranch();
2649 relinkBranch (bi,pi,pos);
2650 bi=selbi->getFirstBranch();
2656 BranchObj *bo=getSelectedBranchObj();
2659 bo->move2RelPos (p);
2665 void VymModel::deleteChildren()
2668 BranchItem *selbi=getSelectedBranch();
2671 saveStateChangingPart(
2674 "deleteChildren ()",
2675 QString( "Remove children of branch %1").arg(getObjectName(selbi))
2677 emit (layoutAboutToBeChanged() );
2679 QModelIndex ix=index (selbi);
2680 int n=selbi->branchCount()-1;
2681 beginRemoveRows (ix,0,n);
2682 removeRows (0,n+1,ix);
2684 if (selbi->isScrolled()) selbi->unScroll();
2685 emit (layoutChanged() );
2690 TreeItem* VymModel::deleteItem (TreeItem *ti)
2694 TreeItem *pi=ti->parent();
2695 QModelIndex parentIndex=index(pi);
2697 emit (layoutAboutToBeChanged() );
2699 int n=ti->childNum();
2700 beginRemoveRows (parentIndex,n,n);
2701 removeRows (n,1,parentIndex);
2705 emit (layoutChanged() );
2706 if (pi->depth()>=0) return pi;
2711 void VymModel::clearItem (TreeItem *ti)
2715 QModelIndex parentIndex=index(ti);
2716 if (!parentIndex.isValid()) return;
2718 int n=ti->childCount();
2721 emit (layoutAboutToBeChanged() );
2723 beginRemoveRows (parentIndex,0,n-1);
2724 removeRows (0,n,parentIndex);
2728 emit (layoutChanged() );
2734 bool VymModel::scrollBranch(BranchItem *bi)
2738 if (bi->isScrolled()) return false;
2739 if (bi->branchCount()==0) return false;
2740 if (bi->depth()==0) return false;
2741 if (bi->toggleScroll())
2749 QString ("%1 ()").arg(u),
2751 QString ("%1 ()").arg(r),
2752 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2754 emitDataHasChanged(bi);
2755 emitSelectionChanged();
2756 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2763 bool VymModel::unscrollBranch(BranchItem *bi)
2767 if (!bi->isScrolled()) return false;
2768 if (bi->branchCount()==0) return false;
2769 if (bi->depth()==0) return false;
2770 if (bi->toggleScroll())
2778 QString ("%1 ()").arg(u),
2780 QString ("%1 ()").arg(r),
2781 QString ("%1 %2").arg(r).arg(getObjectName(bi))
2783 emitDataHasChanged(bi);
2784 emitSelectionChanged();
2785 mapScene->update(); //Needed for _quick_ update, even in 1.13.x
2792 void VymModel::toggleScroll()
2794 BranchItem *bi=(BranchItem*)getSelectedBranch();
2795 if (bi && bi->isBranchLikeType() )
2797 if (bi->isScrolled())
2798 unscrollBranch (bi);
2802 // saveState & reposition are called in above functions
2805 void VymModel::unscrollChildren()
2807 BranchItem *selbi=getSelectedBranch();
2808 BranchItem *prev=NULL;
2809 BranchItem *cur=selbi;
2812 saveStateChangingPart(
2815 QString ("unscrollChildren ()"),
2816 QString ("unscroll all children of %1").arg(getObjectName(selbi))
2820 if (cur->isScrolled())
2822 cur->toggleScroll();
2823 emitDataHasChanged (cur);
2825 cur=nextBranch (cur,prev,true,selbi);
2832 void VymModel::emitExpandAll()
2834 emit (expandAll() );
2837 void VymModel::emitExpandOneLevel()
2839 emit (expandOneLevel () );
2842 void VymModel::emitCollapseOneLevel()
2844 emit (collapseOneLevel () );
2847 void VymModel::toggleStandardFlag (const QString &name, FlagRow *master)
2849 BranchItem *bi=getSelectedBranch();
2853 if (bi->isActiveStandardFlag(name))
2865 QString("%1 (\"%2\")").arg(u).arg(name),
2867 QString("%1 (\"%2\")").arg(r).arg(name),
2868 QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi)));
2869 bi->toggleStandardFlag (name, master);
2871 emitSelectionChanged();
2875 void VymModel::addFloatImage (const QPixmap &img)
2877 BranchItem *selbi=getSelectedBranch();
2880 ImageItem *ii=createImage (selbi);
2882 ii->setOriginalFilename("No original filename (image added by dropevent)");
2883 QString s=getSelectString(selbi);
2884 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
2885 saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2887 // FIXME-3 VM needed? scene()->update();
2892 void VymModel::colorBranch (QColor c)
2894 BranchItem *selbi=getSelectedBranch();
2899 QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()),
2901 QString ("colorBranch (\"%1\")").arg(c.name()),
2902 QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
2904 selbi->setHeadingColor(c); // color branch
2909 void VymModel::colorSubtree (QColor c)
2911 BranchItem *selbi=getSelectedBranch();
2914 saveStateChangingPart(
2917 QString ("colorSubtree (\"%1\")").arg(c.name()),
2918 QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name())
2920 BranchItem *prev=NULL;
2921 BranchItem *cur=selbi;
2924 cur->setHeadingColor(c); // color links, color children
2925 cur=nextBranch (cur,prev,true,selbi);
2931 QColor VymModel::getCurrentHeadingColor()
2933 BranchItem *selbi=getSelectedBranch();
2934 if (selbi) return selbi->getHeadingColor();
2936 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2942 void VymModel::editURL()
2944 TreeItem *selti=getSelectedItem();
2948 QString text = QInputDialog::getText(
2949 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2950 selti->getURL(), &ok, NULL);
2952 // user entered something and pressed OK
2957 void VymModel::editLocalURL()
2959 TreeItem *selti=getSelectedItem();
2962 QStringList filters;
2963 filters <<"All files (*)";
2964 filters << tr("Text","Filedialog") + " (*.txt)";
2965 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2966 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2967 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2968 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2969 fd->setFilters (filters);
2970 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2971 fd->setDirectory (lastFileDir);
2972 if (! selti->getVymLink().isEmpty() )
2973 fd->selectFile( selti->getURL() );
2976 if ( fd->exec() == QDialog::Accepted )
2978 lastFileDir=QDir (fd->directory().path());
2979 setURL (fd->selectedFile() );
2985 void VymModel::editHeading2URL()
2987 TreeItem *selti=getSelectedItem();
2989 setURL (selti->getHeading());
2992 void VymModel::editBugzilla2URL()
2994 TreeItem *selti=getSelectedItem();
2997 QString h=selti->getHeading();
2998 QRegExp rx("^(\\d+)");
2999 if (rx.indexIn(h) !=-1)
3000 setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) );
3004 void VymModel::getBugzillaData()
3006 BranchItem *selbi=getSelectedBranch();
3009 QString url=selbi->getURL();
3012 QRegExp rx("(\\d+)");
3013 if (rx.indexIn(url) !=-1)
3015 QString bugID=rx.cap(1);
3016 qDebug()<< "VM::getBugzillaData bug="<<bugID;
3018 new BugAgent (selbi,bugID);
3024 void VymModel::editFATE2URL()
3026 TreeItem *selti=getSelectedItem();
3029 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading();
3032 "setURL (\""+selti->getURL()+"\")",
3034 "setURL (\""+url+"\")",
3035 QString("Use heading of %1 as link to FATE").arg(getObjectName(selti))
3037 selti->setURL (url);
3038 // FIXME-4 updateActions();
3042 void VymModel::editVymLink()
3044 BranchItem *bi=getSelectedBranch();
3047 QStringList filters;
3048 filters <<"VYM map (*.vym)";
3049 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
3050 fd->setFilters (filters);
3051 fd->setCaption(vymName+" - " +tr("Link to another map"));
3052 fd->setDirectory (lastFileDir);
3053 if (! bi->getVymLink().isEmpty() )
3054 fd->selectFile( bi->getVymLink() );
3058 if ( fd->exec() == QDialog::Accepted )
3060 lastFileDir=QDir (fd->directory().path());
3063 "setVymLink (\""+bi->getVymLink()+"\")",
3065 "setVymLink (\""+fd->selectedFile()+"\")",
3066 QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
3068 setVymLink (fd->selectedFile() );
3073 void VymModel::setVymLink (const QString &s)
3075 // Internal function, no saveState needed
3076 TreeItem *selti=getSelectedItem();
3079 selti->setVymLink(s);
3081 emitDataHasChanged (selti);
3082 emitShowSelection();
3086 void VymModel::deleteVymLink()
3088 BranchItem *bi=getSelectedBranch();
3093 "setVymLink (\""+bi->getVymLink()+"\")",
3095 "setVymLink (\"\")",
3096 QString("Unset vymlink of %1").arg(getObjectName(bi))
3098 bi->setVymLink ("" );
3104 QString VymModel::getVymLink()
3106 BranchItem *bi=getSelectedBranch();
3108 return bi->getVymLink();
3114 QStringList VymModel::getVymLinks()
3117 BranchItem *selbi=getSelectedBranch();
3118 BranchItem *cur=selbi;
3119 BranchItem *prev=NULL;
3122 if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink());
3123 cur=nextBranch (cur,prev,true,selbi);
3129 void VymModel::followXLink(int i)
3132 BranchItem *selbi=getSelectedBranch();
3135 selbi=selbi->getXLinkNum(i)->getPartnerBranch();
3136 if (selbi) select (selbi);
3140 void VymModel::editXLink(int i)
3143 BranchItem *selbi=getSelectedBranch();
3146 XLinkItem *xli=selbi->getXLinkNum(i);
3149 EditXLinkDialog dia;
3151 dia.setSelection(selbi);
3152 if (dia.exec() == QDialog::Accepted)
3154 if (dia.useSettingsGlobal() )
3156 setMapDefXLinkColor (xli->getColor() );
3157 setMapDefXLinkWidth (xli->getWidth() );
3159 if (dia.deleteXLink()) deleteItem (xli);
3169 //////////////////////////////////////////////
3171 //////////////////////////////////////////////
3173 QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg)
3175 TreeItem* selti=getSelectedItem();
3176 BranchItem *selbi=getSelectedBranch();
3181 QVariant returnValue="";
3183 // Split string s into command and parameters
3184 parser.parseAtom (atom);
3185 QString com=parser.getCommand();
3187 // External commands
3188 /////////////////////////////////////////////////////////////////////
3189 if (com=="addBranch")
3193 parser.setError (Aborted,"Nothing selected");
3194 } else if (! selbi )
3196 parser.setError (Aborted,"Type of selection is not a branch");
3201 if (parser.checkParCount(pl))
3203 if (parser.parCount()==0)
3207 n=parser.parInt (ok,0);
3208 if (ok ) addNewBranch (n);
3212 /////////////////////////////////////////////////////////////////////
3213 } else if (com=="addBranchBefore")
3217 parser.setError (Aborted,"Nothing selected");
3218 } else if (! selbi )
3220 parser.setError (Aborted,"Type of selection is not a branch");
3223 if (parser.parCount()==0)
3225 addNewBranchBefore ();
3228 /////////////////////////////////////////////////////////////////////
3229 } else if (com==QString("addMapCenter"))
3231 if (parser.checkParCount(2))
3233 x=parser.parDouble (ok,0);
3236 y=parser.parDouble (ok,1);
3237 if (ok) addMapCenter (QPointF(x,y));
3240 /////////////////////////////////////////////////////////////////////
3241 } else if (com==QString("addMapReplace"))
3245 parser.setError (Aborted,"Nothing selected");
3246 } else if (! selbi )
3248 parser.setError (Aborted,"Type of selection is not a branch");
3249 } else if (parser.checkParCount(1))
3251 //s=parser.parString (ok,0); // selection
3252 t=parser.parString (ok,0); // path to map
3253 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3254 addMapReplaceInt(getSelectString(selbi),t);
3256 /////////////////////////////////////////////////////////////////////
3257 } else if (com==QString("addMapInsert"))
3259 if (parser.parCount()==2)
3264 parser.setError (Aborted,"Nothing selected");
3265 } else if (! selbi )
3267 parser.setError (Aborted,"Type of selection is not a branch");
3270 t=parser.parString (ok,0); // path to map
3271 n=parser.parInt(ok,1); // position
3272 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3273 addMapInsertInt(t,n);
3275 } else if (parser.parCount()==1)
3277 t=parser.parString (ok,0); // path to map
3278 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
3281 parser.setError (Aborted,"Wrong number of parameters");
3282 /////////////////////////////////////////////////////////////////////
3283 } else if (com==QString("addXLink"))
3285 if (parser.parCount()>1)
3287 s=parser.parString (ok,0); // begin
3288 t=parser.parString (ok,1); // end
3289 BranchItem *begin=(BranchItem*)findBySelectString(s);
3290 BranchItem *end=(BranchItem*)findBySelectString(t);
3293 if (begin->isBranchLikeType() && end->isBranchLikeType())
3295 XLinkItem *xl=createXLink (begin,true);
3301 parser.setError (Aborted,"Failed to create xLink");
3304 parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
3307 parser.setError (Aborted,"Couldn't select begin or end of xLink");
3309 parser.setError (Aborted,"Need at least 2 parameters for begin and end");
3310 /////////////////////////////////////////////////////////////////////
3311 } else if (com=="clearFlags")
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(0))
3321 selbi->deactivateAllStandardFlags(); //FIXME-2 this probably should emitDataChanged and also setChanged. Similar all other direct changes should be done...
3323 /////////////////////////////////////////////////////////////////////
3324 } else if (com=="colorBranch")
3328 parser.setError (Aborted,"Nothing selected");
3329 } else if (! selbi )
3331 parser.setError (Aborted,"Type of selection is not a branch");
3332 } else if (parser.checkParCount(1))
3334 QColor c=parser.parColor (ok,0);
3335 if (ok) colorBranch (c);
3337 /////////////////////////////////////////////////////////////////////
3338 } else if (com=="colorSubtree")
3342 parser.setError (Aborted,"Nothing selected");
3343 } else if (! selbi )
3345 parser.setError (Aborted,"Type of selection is not a branch");
3346 } else if (parser.checkParCount(1))
3348 QColor c=parser.parColor (ok,0);
3349 if (ok) colorSubtree (c);
3351 /////////////////////////////////////////////////////////////////////
3352 } else if (com=="copy")
3356 parser.setError (Aborted,"Nothing selected");
3357 } else if ( selectionType()!=TreeItem::Branch &&
3358 selectionType()!=TreeItem::MapCenter &&
3359 selectionType()!=TreeItem::Image )
3361 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3362 } else if (parser.checkParCount(0))
3366 /////////////////////////////////////////////////////////////////////
3367 } else if (com=="cut")
3371 parser.setError (Aborted,"Nothing selected");
3372 } else if ( selectionType()!=TreeItem::Branch &&
3373 selectionType()!=TreeItem::MapCenter &&
3374 selectionType()!=TreeItem::Image )
3376 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3377 } else if (parser.checkParCount(0))
3381 /////////////////////////////////////////////////////////////////////
3382 } else if (com=="delete")
3386 parser.setError (Aborted,"Nothing selected");
3388 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
3390 parser.setError (Aborted,"Type of selection is wrong.");
3393 else if (parser.checkParCount(0))
3397 /////////////////////////////////////////////////////////////////////
3398 } else if (com=="deleteKeepChildren")
3402 parser.setError (Aborted,"Nothing selected");
3403 } else if (! selbi )
3405 parser.setError (Aborted,"Type of selection is not a branch");
3406 } else if (parser.checkParCount(0))
3408 deleteKeepChildren();
3410 /////////////////////////////////////////////////////////////////////
3411 } else if (com=="deleteChildren")
3415 parser.setError (Aborted,"Nothing selected");
3418 parser.setError (Aborted,"Type of selection is not a branch");
3419 } else if (parser.checkParCount(0))
3423 /////////////////////////////////////////////////////////////////////
3424 } else if (com=="exportAO")
3428 if (parser.parCount()>=1)
3429 // Hey, we even have a filename
3430 fname=parser.parString(ok,0);
3433 parser.setError (Aborted,"Could not read filename");
3436 exportAO (fname,false);
3438 /////////////////////////////////////////////////////////////////////
3439 } else if (com=="exportASCII")
3443 if (parser.parCount()>=1)
3444 // Hey, we even have a filename
3445 fname=parser.parString(ok,0);
3448 parser.setError (Aborted,"Could not read filename");
3451 exportASCII (fname,false);
3453 /////////////////////////////////////////////////////////////////////
3454 } else if (com=="exportImage")
3458 if (parser.parCount()>=2)
3459 // Hey, we even have a filename
3460 fname=parser.parString(ok,0);
3463 parser.setError (Aborted,"Could not read filename");
3466 QString format="PNG";
3467 if (parser.parCount()>=2)
3469 format=parser.parString(ok,1);
3471 exportImage (fname,false,format);
3473 /////////////////////////////////////////////////////////////////////
3474 } else if (com=="exportXHTML")
3478 if (parser.parCount()>=2)
3479 // Hey, we even have a filename
3480 fname=parser.parString(ok,1);
3483 parser.setError (Aborted,"Could not read filename");
3486 exportXHTML (fname,false);
3488 /////////////////////////////////////////////////////////////////////
3489 } else if (com=="exportXML")
3493 if (parser.parCount()>=2)
3494 // Hey, we even have a filename
3495 fname=parser.parString(ok,1);
3498 parser.setError (Aborted,"Could not read filename");
3501 exportXML (fname,false);
3503 /////////////////////////////////////////////////////////////////////
3504 } else if (com=="getHeading")
3508 parser.setError (Aborted,"Nothing selected");
3509 } else if (parser.checkParCount(0))
3510 returnValue=selti->getHeading();
3511 /////////////////////////////////////////////////////////////////////
3512 } else if (com=="importDir")
3516 parser.setError (Aborted,"Nothing selected");
3517 } else if (! selbi )
3519 parser.setError (Aborted,"Type of selection is not a branch");
3520 } else if (parser.checkParCount(1))
3522 s=parser.parString(ok,0);
3523 if (ok) importDirInt(s);
3525 /////////////////////////////////////////////////////////////////////
3526 } else if (com=="relinkTo")
3530 parser.setError (Aborted,"Nothing selected");
3533 if (parser.checkParCount(4))
3535 // 0 selectstring of parent
3536 // 1 num in parent (for branches)
3537 // 2,3 x,y of mainbranch or mapcenter
3538 s=parser.parString(ok,0);
3539 TreeItem *dst=findBySelectString (s);
3542 if (dst->getType()==TreeItem::Branch)
3544 // Get number in parent
3545 n=parser.parInt (ok,1);
3548 relinkBranch (selbi,(BranchItem*)dst,n);
3549 emitSelectionChanged();
3551 } else if (dst->getType()==TreeItem::MapCenter)
3553 relinkBranch (selbi,(BranchItem*)dst);
3554 // Get coordinates of mainbranch
3555 x=parser.parDouble(ok,2);
3558 y=parser.parDouble(ok,3);
3561 if (selbi->getLMO()) selbi->getLMO()->move (x,y);
3562 emitSelectionChanged();
3568 } else if ( selti->getType() == TreeItem::Image)
3570 if (parser.checkParCount(1))
3572 // 0 selectstring of parent
3573 s=parser.parString(ok,0);
3574 TreeItem *dst=findBySelectString (s);
3577 if (dst->isBranchLikeType())
3578 relinkImage ( ((ImageItem*)selti),(BranchItem*)dst);
3580 parser.setError (Aborted,"Destination is not a branch");
3583 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
3584 /////////////////////////////////////////////////////////////////////
3585 } else if (com=="loadImage")
3589 parser.setError (Aborted,"Nothing selected");
3590 } else if (! selbi )
3592 parser.setError (Aborted,"Type of selection is not a branch");
3593 } else if (parser.checkParCount(1))
3595 s=parser.parString(ok,0);
3596 if (ok) loadFloatImageInt (selbi,s);
3598 /////////////////////////////////////////////////////////////////////
3599 } else if (com=="loadNote")
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(1))
3609 s=parser.parString(ok,0);
3610 if (ok) loadNote (s);
3612 /////////////////////////////////////////////////////////////////////
3613 } else if (com=="moveUp")
3617 parser.setError (Aborted,"Nothing selected");
3618 } else if (! selbi )
3620 parser.setError (Aborted,"Type of selection is not a branch");
3621 } else if (parser.checkParCount(0))
3625 /////////////////////////////////////////////////////////////////////
3626 } else if (com=="moveDown")
3630 parser.setError (Aborted,"Nothing selected");
3631 } else if (! selbi )
3633 parser.setError (Aborted,"Type of selection is not a branch");
3634 } else if (parser.checkParCount(0))
3638 /////////////////////////////////////////////////////////////////////
3639 } else if (com=="move")
3643 parser.setError (Aborted,"Nothing selected");
3644 } else if ( selectionType()!=TreeItem::Branch &&
3645 selectionType()!=TreeItem::MapCenter &&
3646 selectionType()!=TreeItem::Image )
3648 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3649 } else if (parser.checkParCount(2))
3651 x=parser.parDouble (ok,0);
3654 y=parser.parDouble (ok,1);
3658 /////////////////////////////////////////////////////////////////////
3659 } else if (com=="moveRel")
3663 parser.setError (Aborted,"Nothing selected");
3664 } else if ( selectionType()!=TreeItem::Branch &&
3665 selectionType()!=TreeItem::MapCenter &&
3666 selectionType()!=TreeItem::Image )
3668 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3669 } else if (parser.checkParCount(2))
3671 x=parser.parDouble (ok,0);
3674 y=parser.parDouble (ok,1);
3675 if (ok) moveRel (x,y);
3678 /////////////////////////////////////////////////////////////////////
3679 } else if (com=="nop")
3681 /////////////////////////////////////////////////////////////////////
3682 } else if (com=="paste")
3686 parser.setError (Aborted,"Nothing selected");
3687 } else if (! selbi )
3689 parser.setError (Aborted,"Type of selection is not a branch");
3690 } else if (parser.checkParCount(1))
3692 n=parser.parInt (ok,0);
3693 if (ok) pasteNoSave(n);
3695 /////////////////////////////////////////////////////////////////////
3696 } else if (com=="qa")
3700 parser.setError (Aborted,"Nothing selected");
3701 } else if (! selbi )
3703 parser.setError (Aborted,"Type of selection is not a branch");
3704 } else if (parser.checkParCount(4))
3707 c=parser.parString (ok,0);
3710 parser.setError (Aborted,"No comment given");
3713 s=parser.parString (ok,1);
3716 parser.setError (Aborted,"First parameter is not a string");
3719 t=parser.parString (ok,2);
3722 parser.setError (Aborted,"Condition is not a string");
3725 u=parser.parString (ok,3);
3728 parser.setError (Aborted,"Third parameter is not a string");
3733 parser.setError (Aborted,"Unknown type: "+s);
3738 parser.setError (Aborted,"Unknown operator: "+t);
3743 parser.setError (Aborted,"Type of selection is not a branch");
3746 if (selbi->getHeading() == u)
3748 cout << "PASSED: " << qPrintable (c) << endl;
3751 cout << "FAILED: " << qPrintable (c) << endl;
3761 /////////////////////////////////////////////////////////////////////
3762 } else if (com=="saveImage")
3764 ImageItem *ii=getSelectedImage();
3767 parser.setError (Aborted,"No image selected");
3768 } else if (parser.checkParCount(2))
3770 s=parser.parString(ok,0);
3773 t=parser.parString(ok,1);
3774 if (ok) saveFloatImageInt (ii,t,s);
3777 /////////////////////////////////////////////////////////////////////
3778 } else if (com=="saveNote")
3782 parser.setError (Aborted,"Nothing selected");
3783 } else if (! selbi )
3785 parser.setError (Aborted,"Type of selection is not a branch");
3786 } else if (parser.checkParCount(1))
3788 s=parser.parString(ok,0);
3789 if (ok) saveNote (s);
3791 /////////////////////////////////////////////////////////////////////
3792 } else if (com=="scroll")
3796 parser.setError (Aborted,"Nothing selected");
3797 } else if (! selbi )
3799 parser.setError (Aborted,"Type of selection is not a branch");
3800 } else if (parser.checkParCount(0))
3802 if (!scrollBranch (selbi))
3803 parser.setError (Aborted,"Could not scroll branch");
3805 /////////////////////////////////////////////////////////////////////
3806 } else if (com=="select")
3808 if (parser.checkParCount(1))
3810 s=parser.parString(ok,0);
3813 /////////////////////////////////////////////////////////////////////
3814 } else if (com=="selectLastBranch")
3818 parser.setError (Aborted,"Nothing selected");
3819 } else if (! selbi )
3821 parser.setError (Aborted,"Type of selection is not a branch");
3822 } else if (parser.checkParCount(0))
3824 BranchItem *bi=selbi->getLastBranch();
3826 parser.setError (Aborted,"Could not select last branch");
3827 select (bi); // FIXME-3 was selectInt
3830 /////////////////////////////////////////////////////////////////////
3831 } else /* FIXME-2 if (com=="selectLastImage")
3835 parser.setError (Aborted,"Nothing selected");
3836 } else if (! selbi )
3838 parser.setError (Aborted,"Type of selection is not a branch");
3839 } else if (parser.checkParCount(0))
3841 FloatImageObj *fio=selb->getLastFloatImage();
3843 parser.setError (Aborted,"Could not select last image");
3844 select (fio); // FIXME-3 was selectInt
3847 /////////////////////////////////////////////////////////////////////
3848 } else */ if (com=="selectLatestAdded")
3850 if (!latestAddedItem)
3852 parser.setError (Aborted,"No latest added object");
3855 if (!select (latestAddedItem))
3856 parser.setError (Aborted,"Could not select latest added object ");
3858 /////////////////////////////////////////////////////////////////////
3859 } else if (com=="setFlag")
3863 parser.setError (Aborted,"Nothing selected");
3864 } else if (! selbi )
3866 parser.setError (Aborted,"Type of selection is not a branch");
3867 } else if (parser.checkParCount(1))
3869 s=parser.parString(ok,0);
3871 selbi->activateStandardFlag(s);
3873 /////////////////////////////////////////////////////////////////////
3874 } else if (com=="setFrameType")
3876 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3878 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3880 else if (parser.checkParCount(1))
3882 s=parser.parString(ok,0);
3883 if (ok) setFrameType (s);
3885 /////////////////////////////////////////////////////////////////////
3886 } else if (com=="setFramePenColor")
3888 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3890 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3892 else if (parser.checkParCount(1))
3894 QColor c=parser.parColor(ok,0);
3895 if (ok) setFramePenColor (c);
3897 /////////////////////////////////////////////////////////////////////
3898 } else if (com=="setFrameBrushColor")
3900 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3902 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3904 else if (parser.checkParCount(1))
3906 QColor c=parser.parColor(ok,0);
3907 if (ok) setFrameBrushColor (c);
3909 /////////////////////////////////////////////////////////////////////
3910 } else if (com=="setFramePadding")
3912 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3914 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3916 else if (parser.checkParCount(1))
3918 n=parser.parInt(ok,0);
3919 if (ok) setFramePadding(n);
3921 /////////////////////////////////////////////////////////////////////
3922 } else if (com=="setFrameBorderWidth")
3924 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3926 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3928 else if (parser.checkParCount(1))
3930 n=parser.parInt(ok,0);
3931 if (ok) setFrameBorderWidth (n);
3933 /////////////////////////////////////////////////////////////////////
3934 /* FIXME-2 else if (com=="setFrameType")
3938 parser.setError (Aborted,"Nothing selected");
3941 parser.setError (Aborted,"Type of selection is not a branch");
3942 } else if (parser.checkParCount(1))
3944 s=parser.parString(ok,0);
3948 /////////////////////////////////////////////////////////////////////
3950 /////////////////////////////////////////////////////////////////////
3951 } else if (com=="setHeading")
3955 parser.setError (Aborted,"Nothing selected");
3956 } else if (! selbi )
3958 parser.setError (Aborted,"Type of selection is not a branch");
3959 } else if (parser.checkParCount(1))
3961 s=parser.parString (ok,0);
3965 /////////////////////////////////////////////////////////////////////
3966 } else if (com=="setHideExport")
3970 parser.setError (Aborted,"Nothing selected");
3971 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3973 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3974 } else if (parser.checkParCount(1))
3976 b=parser.parBool(ok,0);
3977 if (ok) setHideExport (b);
3979 /////////////////////////////////////////////////////////////////////
3980 } else if (com=="setIncludeImagesHorizontally")
3984 parser.setError (Aborted,"Nothing selected");
3987 parser.setError (Aborted,"Type of selection is not a branch");
3988 } else if (parser.checkParCount(1))
3990 b=parser.parBool(ok,0);
3991 if (ok) setIncludeImagesHor(b);
3993 /////////////////////////////////////////////////////////////////////
3994 } else if (com=="setIncludeImagesVertically")
3998 parser.setError (Aborted,"Nothing selected");
4001 parser.setError (Aborted,"Type of selection is not a branch");
4002 } else if (parser.checkParCount(1))
4004 b=parser.parBool(ok,0);
4005 if (ok) setIncludeImagesVer(b);
4007 /////////////////////////////////////////////////////////////////////
4008 } else if (com=="setHideLinkUnselected")
4012 parser.setError (Aborted,"Nothing selected");
4013 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
4015 parser.setError (Aborted,"Type of selection does not allow hiding the link");
4016 } else if (parser.checkParCount(1))
4018 b=parser.parBool(ok,0);
4019 if (ok) setHideLinkUnselected(b);
4021 /////////////////////////////////////////////////////////////////////
4022 } else if (com=="setMapAuthor")
4024 if (parser.checkParCount(1))
4026 s=parser.parString(ok,0);
4027 if (ok) setAuthor (s);
4029 /////////////////////////////////////////////////////////////////////
4030 } else if (com=="setMapComment")
4032 if (parser.checkParCount(1))
4034 s=parser.parString(ok,0);
4035 if (ok) setComment(s);
4037 /////////////////////////////////////////////////////////////////////
4038 } else if (com=="setMapBackgroundColor")
4042 parser.setError (Aborted,"Nothing selected");
4043 } else if (! selbi )
4045 parser.setError (Aborted,"Type of selection is not a branch");
4046 } else if (parser.checkParCount(1))
4048 QColor c=parser.parColor (ok,0);
4049 if (ok) setMapBackgroundColor (c);
4051 /////////////////////////////////////////////////////////////////////
4052 } else if (com=="setMapDefLinkColor")
4056 parser.setError (Aborted,"Nothing selected");
4057 } else if (! selbi )
4059 parser.setError (Aborted,"Type of selection is not a branch");
4060 } else if (parser.checkParCount(1))
4062 QColor c=parser.parColor (ok,0);
4063 if (ok) setMapDefLinkColor (c);
4065 /////////////////////////////////////////////////////////////////////
4066 } else if (com=="setMapLinkStyle")
4068 if (parser.checkParCount(1))
4070 s=parser.parString (ok,0);
4071 if (ok) setMapLinkStyle(s);
4073 /////////////////////////////////////////////////////////////////////
4074 } else if (com=="setNote")
4078 parser.setError (Aborted,"Nothing selected");
4079 } else if (! selbi )
4081 parser.setError (Aborted,"Type of selection is not a branch");
4082 } else if (parser.checkParCount(1))
4084 s=parser.parString (ok,0);
4088 /////////////////////////////////////////////////////////////////////
4089 } else if (com=="setSelectionColor")
4091 if (parser.checkParCount(1))
4093 QColor c=parser.parColor (ok,0);
4094 if (ok) setSelectionColorInt (c);
4096 /////////////////////////////////////////////////////////////////////
4097 } else if (com=="setURL")
4101 parser.setError (Aborted,"Nothing selected");
4102 } else if (! selbi )
4104 parser.setError (Aborted,"Type of selection is not a branch");
4105 } else if (parser.checkParCount(1))
4107 s=parser.parString (ok,0);
4110 /////////////////////////////////////////////////////////////////////
4111 } else if (com=="setVymLink")
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(1))
4121 s=parser.parString (ok,0);
4122 if (ok) setVymLink(s);
4124 } else if (com=="sortChildren")
4128 parser.setError (Aborted,"Nothing selected");
4129 } else if (! selbi )
4131 parser.setError (Aborted,"Type of selection is not a branch");
4132 } else if (parser.checkParCount(0))
4135 } else if (parser.checkParCount(1))
4137 b=parser.parBool(ok,0);
4138 if (ok) sortChildren(b);
4140 /////////////////////////////////////////////////////////////////////
4141 } else if (com=="toggleFlag")
4145 parser.setError (Aborted,"Nothing selected");
4146 } else if (! selbi )
4148 parser.setError (Aborted,"Type of selection is not a branch");
4149 } else if (parser.checkParCount(1))
4151 s=parser.parString(ok,0);
4153 selbi->toggleStandardFlag(s);
4155 /////////////////////////////////////////////////////////////////////
4156 } else if (com=="unscroll")
4160 parser.setError (Aborted,"Nothing selected");
4161 } else if (! selbi )
4163 parser.setError (Aborted,"Type of selection is not a branch");
4164 } else if (parser.checkParCount(0))
4166 if (!unscrollBranch (selbi))
4167 parser.setError (Aborted,"Could not unscroll branch");
4169 /////////////////////////////////////////////////////////////////////
4170 } else if (com=="unscrollChildren")
4174 parser.setError (Aborted,"Nothing selected");
4175 } else if (! selbi )
4177 parser.setError (Aborted,"Type of selection is not a branch");
4178 } else if (parser.checkParCount(0))
4180 unscrollChildren ();
4182 /////////////////////////////////////////////////////////////////////
4183 } else if (com=="unsetFlag")
4187 parser.setError (Aborted,"Nothing selected");
4188 } else if (! selbi )
4190 parser.setError (Aborted,"Type of selection is not a branch");
4191 } else if (parser.checkParCount(1))
4193 s=parser.parString(ok,0);
4195 selbi->deactivateStandardFlag(s);
4198 parser.setError (Aborted,"Unknown command");
4201 if (parser.errorLevel()==NoError)
4209 // TODO Error handling
4210 qWarning("VymModel::parseAtom: Error!");
4212 qWarning(parser.errorMessage());
4214 errorMsg=parser.errorMessage();
4215 returnValue=errorMsg;
4220 QVariant VymModel::runScript (const QString &script)
4222 parser.setScript (script);
4227 while (parser.next() && noErr)
4229 r=parseAtom(parser.getAtom(),noErr,errMsg);
4230 if (!noErr) //FIXME-3 need dialog box here
4231 cout << "VM::runScript aborted:\n"<<errMsg.toStdString()<<endl;
4236 void VymModel::setExportMode (bool b)
4238 // should be called before and after exports
4239 // depending on the settings
4240 if (b && settings.value("/export/useHideExport","true")=="true")
4241 setHideTmpMode (TreeItem::HideExport);
4243 setHideTmpMode (TreeItem::HideNone);
4246 void VymModel::exportImage(QString fname, bool askName, QString format)
4250 fname=getMapName()+".png";
4257 QFileDialog *fd=new QFileDialog (NULL);
4258 fd->setCaption (tr("Export map as image"));
4259 fd->setDirectory (lastImageDir);
4260 fd->setFileMode(QFileDialog::AnyFile);
4261 fd->setFilters (imageIO.getFilters() );
4264 fl=fd->selectedFiles();
4266 format=imageIO.getType(fd->selectedFilter());
4270 setExportMode (true);
4271 mapEditor->getScene()->update(); // FIXME-3 check this...
4272 QImage img (mapEditor->getImage()); //FIXME-3 calls getTotalBBox, but also in ExportHTML::doExport()
4273 img.save(fname, format);
4274 setExportMode (false);
4278 void VymModel::exportXML(QString dir, bool askForName)
4282 dir=browseDirectory(NULL,tr("Export XML to directory"));
4283 if (dir =="" && !reallyWriteDirectory(dir) )
4287 // Hide stuff during export, if settings want this
4288 setExportMode (true);
4290 // Create subdirectories
4293 // write to directory //FIXME-4 check totalBBox here...
4294 QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->getTotalBBox().topLeft() ,NULL);
4297 file.setName ( dir + "/"+mapName+".xml");
4298 if ( !file.open( QIODevice::WriteOnly ) )
4300 // This should neverever happen
4301 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
4305 // Write it finally, and write in UTF8, no matter what
4306 QTextStream ts( &file );
4307 ts.setEncoding (QTextStream::UnicodeUTF8);
4311 // Now write image, too
4312 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
4314 setExportMode (false);
4317 void VymModel::exportAO (QString fname,bool askName)
4322 ex.setFile (mapName+".txt");
4328 //ex.addFilter ("TXT (*.txt)");
4329 ex.setDir(lastImageDir);
4330 //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)"));
4335 setExportMode(true);
4337 setExportMode(false);
4341 void VymModel::exportASCII(QString fname,bool askName)
4346 ex.setFile (mapName+".txt");
4352 //ex.addFilter ("TXT (*.txt)");
4353 ex.setDir(lastImageDir);
4354 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
4359 setExportMode(true);
4361 setExportMode(false);
4365 void VymModel::exportHTML (const QString &dir, bool useDialog)
4367 ExportHTML ex (this);
4369 ex.doExport(useDialog);
4372 void VymModel::exportXHTML (const QString &dir, bool askForName)
4374 ExportXHTMLDialog dia(NULL);
4375 dia.setFilePath (filePath );
4376 dia.setMapName (mapName );
4378 if (dir!="") dia.setDir (dir);
4384 if (dia.exec()!=QDialog::Accepted)
4388 QDir d (dia.getDir());
4389 // Check, if warnings should be used before overwriting
4390 // the output directory
4391 if (d.exists() && d.count()>0)
4394 warn.showCancelButton (true);
4395 warn.setText(QString(
4396 "The directory %1 is not empty.\n"
4397 "Do you risk to overwrite some of its contents?").arg(d.path() ));
4398 warn.setCaption("Warning: Directory not empty");
4399 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
4401 if (warn.exec()!=QDialog::Accepted) ok=false;
4408 exportXML (dia.getDir(),false );
4409 dia.doExport(mapName );
4410 //if (dia.hasChanged()) setChanged();
4414 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
4419 if (ex.setConfigFile(cf))
4421 setExportMode (true);
4422 ex.exportPresentation();
4423 setExportMode (false);
4430 //////////////////////////////////////////////
4432 //////////////////////////////////////////////
4434 void VymModel::registerEditor(QWidget *me)
4436 mapEditor=(MapEditor*)me;
4439 void VymModel::unregisterEditor(QWidget *)
4444 void VymModel::setMapZoomFactor (const double &d)
4449 void VymModel::setContextPos(QPointF p)
4454 void VymModel::unsetContextPos()
4456 contextPos=QPointF();
4459 void VymModel::updateNoteFlag()
4461 TreeItem *selti=getSelectedItem();
4470 if (textEditor->isEmpty())
4473 selti->setNote (textEditor->getText());
4474 emitDataHasChanged(selti);
4478 void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views...
4480 //cout << "VM::reposition blocked="<<blockReposition<<endl;
4481 if (blockReposition) return;
4483 for (int i=0;i<rootItem->branchCount(); i++)
4484 rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
4485 //emitSelectionChanged();
4489 void VymModel::setMapLinkStyle (const QString & s)
4494 case LinkableMapObj::Line :
4497 case LinkableMapObj::Parabel:
4498 snow="StyleParabel";
4500 case LinkableMapObj::PolyLine:
4501 snow="StylePolyLine";
4503 case LinkableMapObj::PolyParabel:
4504 snow="StylePolyParabel";
4507 snow="UndefinedStyle";
4512 QString("setMapLinkStyle (\"%1\")").arg(s),
4513 QString("setMapLinkStyle (\"%1\")").arg(snow),
4514 QString("Set map link style (\"%1\")").arg(s)
4518 linkstyle=LinkableMapObj::Line;
4519 else if (s=="StyleParabel")
4520 linkstyle=LinkableMapObj::Parabel;
4521 else if (s=="StylePolyLine")
4522 linkstyle=LinkableMapObj::PolyLine;
4523 else if (s=="StylePolyParabel")
4524 linkstyle=LinkableMapObj::PolyParabel;
4526 linkstyle=LinkableMapObj::UndefinedStyle;
4528 BranchItem *cur=NULL;
4529 BranchItem *prev=NULL;
4531 nextBranch (cur,prev);
4534 bo=(BranchObj*)(cur->getLMO() );
4535 bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View
4536 cur=nextBranch(cur,prev);
4541 LinkableMapObj::Style VymModel::getMapLinkStyle ()
4546 uint VymModel::getID()
4551 void VymModel::setMapDefLinkColor(QColor col)
4553 if ( !col.isValid() ) return;
4555 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
4556 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
4557 QString("Set map link color to %1").arg(col.name())
4561 BranchItem *cur=NULL;
4562 BranchItem *prev=NULL;
4564 cur=nextBranch(cur,prev);
4567 bo=(BranchObj*)(cur->getLMO() );
4569 nextBranch(cur,prev);
4574 void VymModel::setMapLinkColorHintInt()
4576 // called from setMapLinkColorHint(lch) or at end of parse
4577 BranchItem *cur=NULL;
4578 BranchItem *prev=NULL;
4580 cur=nextBranch(cur,prev);
4583 bo=(BranchObj*)(cur->getLMO() );
4585 cur=nextBranch(cur,prev);
4589 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
4592 setMapLinkColorHintInt();
4595 void VymModel::toggleMapLinkColorHint()
4597 if (linkcolorhint==LinkableMapObj::HeadingColor)
4598 linkcolorhint=LinkableMapObj::DefaultColor;
4600 linkcolorhint=LinkableMapObj::HeadingColor;
4601 BranchItem *cur=NULL;
4602 BranchItem *prev=NULL;
4604 cur=nextBranch(cur,prev);
4607 bo=(BranchObj*)(cur->getLMO() );
4609 nextBranch(cur,prev);
4613 void VymModel::selectMapBackgroundImage () // FIXME-3 for using background image: view.setCacheMode(QGraphicsView::CacheBackground); Also this belongs into ME
4615 Q3FileDialog *fd=new Q3FileDialog( NULL);
4616 fd->setMode (Q3FileDialog::ExistingFile);
4617 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
4618 ImagePreview *p =new ImagePreview (fd);
4619 fd->setContentsPreviewEnabled( TRUE );
4620 fd->setContentsPreview( p, p );
4621 fd->setPreviewMode( Q3FileDialog::Contents );
4622 fd->setCaption(vymName+" - " +tr("Load background image"));
4623 fd->setDir (lastImageDir);
4626 if ( fd->exec() == QDialog::Accepted )
4628 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4629 lastImageDir=QDir (fd->dirPath());
4630 setMapBackgroundImage (fd->selectedFile());
4634 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME
4636 QColor oldcol=mapScene->backgroundBrush().color();
4640 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4642 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4643 QString("Set background color of map to %1").arg(col.name()));
4646 brush.setTextureImage (QPixmap (fn));
4647 mapScene->setBackgroundBrush(brush);
4650 void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
4652 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4653 if ( !col.isValid() ) return;
4654 setMapBackgroundColor( col );
4658 void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
4660 QColor oldcol=mapScene->backgroundBrush().color();
4662 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4663 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4664 QString("Set background color of map to %1").arg(col.name()));
4665 mapScene->setBackgroundBrush(col);
4668 QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
4670 return mapScene->backgroundBrush().color();
4674 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
4676 return linkcolorhint;
4679 QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
4681 return defLinkColor;
4684 void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
4689 QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
4691 return defXLinkColor;
4694 void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
4699 int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
4701 return defXLinkWidth;
4704 void VymModel::move(const double &x, const double &y)
4707 MapItem *seli = (MapItem*)getSelectedItem();
4708 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4710 LinkableMapObj *lmo=seli->getLMO();
4713 QPointF ap(lmo->getAbsPos());
4717 QString ps=qpointFToString(ap);
4718 QString s=getSelectString(seli);
4721 s, "move "+qpointFToString(to),
4722 QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
4725 emitSelectionChanged();
4731 void VymModel::moveRel (const double &x, const double &y)
4734 MapItem *seli = (MapItem*)getSelectedItem();
4735 if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
4737 LinkableMapObj *lmo=seli->getLMO();
4740 QPointF rp(lmo->getRelPos());
4744 QString ps=qpointFToString (lmo->getRelPos());
4745 QString s=getSelectString(seli);
4748 s, "moveRel "+qpointFToString(to),
4749 QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
4750 ((OrnamentedObj*)lmo)->move2RelPos (x,y);
4752 lmo->updateLinkGeometry();
4753 emitSelectionChanged();
4760 void VymModel::animate()
4762 animationTimer->stop();
4765 while (i<animObjList.size() )
4767 bo=(BranchObj*)animObjList.at(i);
4772 animObjList.removeAt(i);
4779 QItemSelection sel=selModel->selection();
4780 emit (selectionChanged(sel,sel));
4783 if (!animObjList.isEmpty()) animationTimer->start();
4787 void VymModel::startAnimation(BranchObj *bo, const QPointF &v)
4791 if (bo->getUseRelPos())
4792 startAnimation (bo,bo->getRelPos(),bo->getRelPos()+v);
4794 startAnimation (bo,bo->getAbsPos(),bo->getAbsPos()+v);
4797 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4799 if (start==dest) return;
4800 if (bo && bo->getTreeItem()->depth()>=0)
4803 ap.setStart (start);
4805 ap.setTicks (animationTicks);
4806 ap.setAnimated (true);
4807 bo->setAnimation (ap);
4808 if (!animObjList.contains(bo))
4809 animObjList.append( bo );
4810 animationTimer->setSingleShot (true);
4811 animationTimer->start(animationInterval);
4815 void VymModel::stopAnimation (MapObj *mo)
4817 int i=animObjList.indexOf(mo);
4819 animObjList.removeAt (i);
4822 void VymModel::sendSelection()
4824 if (netstate!=Server) return;
4825 sendData (QString("select (\"%1\")").arg(getSelectString()) );
4828 void VymModel::newServer()
4832 tcpServer = new QTcpServer(this);
4833 if (!tcpServer->listen(QHostAddress::Any,port)) {
4834 QMessageBox::critical(NULL, "vym server",
4835 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4836 //FIXME-3 needed? we are no widget any longer... close();
4839 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4841 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4844 void VymModel::connectToServer()
4847 server="salam.suse.de";
4849 clientSocket = new QTcpSocket (this);
4850 clientSocket->abort();
4851 clientSocket->connectToHost(server ,port);
4852 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4853 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4854 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4856 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4861 void VymModel::newClient()
4863 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4864 connect(newClient, SIGNAL(disconnected()),
4865 newClient, SLOT(deleteLater()));
4867 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4869 clientList.append (newClient);
4873 void VymModel::sendData(const QString &s)
4875 if (clientList.size()==0) return;
4877 // Create bytearray to send
4879 QDataStream out(&block, QIODevice::WriteOnly);
4880 out.setVersion(QDataStream::Qt_4_0);
4882 // Reserve some space for blocksize
4885 // Write sendCounter
4886 out << sendCounter++;
4891 // Go back and write blocksize so far
4892 out.device()->seek(0);
4893 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4897 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4899 for (int i=0; i<clientList.size(); ++i)
4901 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4902 clientList.at(i)->write (block);
4906 void VymModel::readData ()
4908 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4911 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4915 QDataStream in(clientSocket);
4916 in.setVersion(QDataStream::Qt_4_0);
4924 cout << "VymModel::readData command="<<qPrintable (t)<<endl;
4927 parseAtom (t,noErr,errMsg);
4933 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4935 switch (socketError) {
4936 case QAbstractSocket::RemoteHostClosedError:
4938 case QAbstractSocket::HostNotFoundError:
4939 QMessageBox::information(NULL, vymName +" Network client",
4940 "The host was not found. Please check the "
4941 "host name and port settings.");
4943 case QAbstractSocket::ConnectionRefusedError:
4944 QMessageBox::information(NULL, vymName + " Network client",
4945 "The connection was refused by the peer. "
4946 "Make sure the fortune server is running, "
4947 "and check that the host name and port "
4948 "settings are correct.");
4951 QMessageBox::information(NULL, vymName + " Network client",
4952 QString("The following error occurred: %1.")
4953 .arg(clientSocket->errorString()));
4957 /* FIXME-3 Playing with DBUS...
4958 QDBusVariant VymModel::query (const QString &query)
4960 TreeItem *selti=getSelectedItem();
4962 return QDBusVariant (selti->getHeading());
4964 return QDBusVariant ("Nothing selected.");
4968 void VymModel::testslot() //FIXME-3 Playing with DBUS
4970 cout << "VM::testslot called\n";
4973 void VymModel::selectMapSelectionColor()
4975 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4976 setSelectionColor (col);
4979 void VymModel::setSelectionColorInt (QColor col)
4981 if ( !col.isValid() ) return;
4983 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4984 QString("setSelectionColor (%1)").arg(col.name()),
4985 QString("Set color of selection box to %1").arg(col.name())
4988 mapEditor->setSelectionColor (col);
4991 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
4993 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
4994 //FIXME-3 emitShowSelection();
4998 void VymModel::emitSelectionChanged()
5000 QItemSelection newsel=selModel->selection();
5001 emitSelectionChanged (newsel);
5004 void VymModel::setSelectionColor(QColor col)
5006 if ( !col.isValid() ) return;
5008 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
5009 QString("setSelectionColor (%1)").arg(col.name()),
5010 QString("Set color of selection box to %1").arg(col.name())
5012 setSelectionColorInt (col);
5015 QColor VymModel::getSelectionColor()
5017 return mapEditor->getSelectionColor();
5020 void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
5023 for (int i=0;i<rootItem->branchCount();i++)
5024 rootItem->getBranchNum(i)->setHideTmp (mode);
5026 if (mode==TreeItem::HideExport)
5032 //////////////////////////////////////////////
5033 // Selection related
5034 //////////////////////////////////////////////
5036 void VymModel::setSelectionModel (QItemSelectionModel *sm)
5041 QItemSelectionModel* VymModel::getSelectionModel()
5046 void VymModel::setSelectionBlocked (bool b)
5051 bool VymModel::isSelectionBlocked()
5053 return selectionBlocked;
5056 bool VymModel::select ()
5058 return select (selModel->selectedIndexes().first()); // TODO no multiselections yet
5061 bool VymModel::select (const QString &s)
5068 TreeItem *ti=findBySelectString(s);
5069 if (ti) return select (index(ti));
5073 bool VymModel::select (LinkableMapObj *lmo)
5075 QItemSelection oldsel=selModel->selection();
5078 return select (index (lmo->getTreeItem()) );
5083 bool VymModel::select (TreeItem *ti)
5085 if (ti) return select (index(ti));
5089 bool VymModel::select (TreeItem *ti, int i)
5091 if (!ti || i<0) return false;
5092 if (select (index(ti)))
5094 qDebug ()<<"VM::select with index: "<<i<<" Trying to find text in note ";
5095 QTextCursor c=textEditor->getTextCursor();
5096 c.setPosition (i-1,QTextCursor::MoveAnchor);
5097 textEditor->setTextCursor (c);
5099 qDebug ()<<"VM::select with index: "<<i<<" Giving up to find text in note ";
5103 bool VymModel::select (const QModelIndex &index)
5105 if (index.isValid() )
5107 selModel->select (index,QItemSelectionModel::ClearAndSelect );
5108 BranchItem *bi=getSelectedBranch();
5109 if (bi) bi->setLastSelectedBranch();
5115 void VymModel::unselect()
5117 if (!selModel->selectedIndexes().isEmpty())
5119 lastSelectString=getSelectString();
5120 selModel->clearSelection();
5124 bool VymModel::reselect()
5126 return select (lastSelectString);
5129 void VymModel::emitShowSelection()
5131 if (!blockReposition)
5132 emit (showSelection() );
5135 void VymModel::emitNoteHasChanged (TreeItem *ti)
5137 QModelIndex ix=index(ti);
5138 emit (noteHasChanged (ix) );
5141 void VymModel::emitDataHasChanged (TreeItem *ti)
5143 QModelIndex ix=index(ti);
5144 emit (dataChanged (ix,ix) );
5147 void VymModel::emitUpdateLayout()
5149 if (settings.value("/mainwindow/autoLayout/use","true")=="true")
5150 emit (updateLayout());
5153 bool VymModel::selectFirstBranch()
5155 TreeItem *ti=getSelectedBranch();
5158 TreeItem *par=ti->parent();
5161 TreeItem *ti2=par->getFirstBranch();
5162 if (ti2) return select(ti2);
5168 bool VymModel::selectLastBranch()
5170 TreeItem *ti=getSelectedBranch();
5173 TreeItem *par=ti->parent();
5176 TreeItem *ti2=par->getLastBranch();
5177 if (ti2) return select(ti2);
5183 bool VymModel::selectLastSelectedBranch()
5185 BranchItem *bi=getSelectedBranch();
5188 bi=bi->getLastSelectedBranch();
5189 if (bi) return select (bi);
5194 bool VymModel::selectParent()
5196 TreeItem *ti=getSelectedItem();
5207 TreeItem::Type VymModel::selectionType()
5209 QModelIndexList list=selModel->selectedIndexes();
5210 if (list.isEmpty()) return TreeItem::Undefined;
5211 TreeItem *ti = getItem (list.first() );
5212 return ti->getType();
5216 LinkableMapObj* VymModel::getSelectedLMO()
5218 QModelIndexList list=selModel->selectedIndexes();
5219 if (!list.isEmpty() )
5221 TreeItem *ti = getItem (list.first() );
5222 TreeItem::Type type=ti->getType();
5223 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
5224 return ((MapItem*)ti)->getLMO();
5229 BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
5231 TreeItem *ti = getSelectedBranch();
5233 return (BranchObj*)( ((MapItem*)ti)->getLMO());
5238 BranchItem* VymModel::getSelectedBranch()
5240 QModelIndexList list=selModel->selectedIndexes();
5241 if (!list.isEmpty() )
5243 TreeItem *ti = getItem (list.first() );
5244 TreeItem::Type type=ti->getType();
5245 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
5246 return (BranchItem*)ti;
5251 ImageItem* VymModel::getSelectedImage()
5253 QModelIndexList list=selModel->selectedIndexes();
5254 if (!list.isEmpty())
5256 TreeItem *ti=getItem (list.first());
5257 if (ti && ti->getType()==TreeItem::Image)
5258 return (ImageItem*)ti;
5263 AttributeItem* VymModel::getSelectedAttribute()
5265 QModelIndexList list=selModel->selectedIndexes();
5266 if (!list.isEmpty() )
5268 TreeItem *ti = getItem (list.first() );
5269 TreeItem::Type type=ti->getType();
5270 if (type ==TreeItem::Attribute)
5271 return (AttributeItem*)ti;
5276 TreeItem* VymModel::getSelectedItem()
5278 QModelIndexList list=selModel->selectedIndexes();
5279 if (!list.isEmpty() )
5280 return getItem (list.first() );
5285 QModelIndex VymModel::getSelectedIndex()
5287 QModelIndexList list=selModel->selectedIndexes();
5288 if (list.isEmpty() )
5289 return QModelIndex();
5291 return list.first();
5294 QString VymModel::getSelectString ()
5296 return getSelectString (getSelectedItem());
5299 QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
5301 if (!lmo) return QString();
5302 return getSelectString (lmo->getTreeItem() );
5305 QString VymModel::getSelectString (TreeItem *ti)
5309 switch (ti->getType())
5311 case TreeItem::MapCenter: s="mc:"; break;
5312 case TreeItem::Branch: s="bo:";break;
5313 case TreeItem::Image: s="fi:";break;
5314 case TreeItem::Attribute: s="ai:";break;
5315 case TreeItem::XLink: s="xl:";break;
5317 s="unknown type in VymModel::getSelectString()";
5320 s= s + QString("%1").arg(ti->num());
5322 // call myself recursively
5323 s= getSelectString(ti->parent()) +","+s;