insilmaril@650: #include insilmaril@687: #include insilmaril@650: insilmaril@721: #include "vymmodel.h" insilmaril@721: insilmaril@721: #include "editxlinkdialog.h" insilmaril@721: #include "exports.h" insilmaril@721: #include "exportxhtmldialog.h" insilmaril@721: #include "file.h" insilmaril@650: #include "geometry.h" // for addBBox insilmaril@721: #include "mainwindow.h" insilmaril@721: #include "mapcenterobj.h" insilmaril@721: #include "misc.h" insilmaril@721: #include "parser.h" insilmaril@721: #include "selection.h" insilmaril@721: insilmaril@721: insilmaril@721: #include "warningdialog.h" insilmaril@721: #include "xml-freemind.h" insilmaril@726: #include "xmlobj.h" insilmaril@721: #include "xml-vym.h" insilmaril@721: insilmaril@721: insilmaril@721: extern bool debug; insilmaril@721: extern Main *mainWindow; insilmaril@696: extern Settings settings; insilmaril@721: extern QString tmpVymDir; insilmaril@721: insilmaril@721: extern TextEditor *textEditor; insilmaril@721: insilmaril@721: extern QString clipboardDir; insilmaril@721: extern QString clipboardFile; insilmaril@721: extern bool clipboardEmpty; insilmaril@721: insilmaril@721: extern ImageIO imageIO; insilmaril@721: insilmaril@721: extern QString vymName; insilmaril@721: extern QString vymVersion; insilmaril@721: extern QDir vymBaseDir; insilmaril@721: insilmaril@721: extern QDir lastImageDir; insilmaril@721: extern QDir lastFileDir; insilmaril@721: insilmaril@721: extern FlagRowObj *standardFlagsDefault; insilmaril@721: insilmaril@721: extern Settings settings; insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: int VymModel::mapNum=0; // make instance insilmaril@696: insilmaril@650: VymModel::VymModel() insilmaril@650: { insilmaril@650: // cout << "Const VymModel\n"; insilmaril@721: init(); insilmaril@650: } insilmaril@650: insilmaril@650: insilmaril@650: VymModel::~VymModel() insilmaril@650: { insilmaril@650: // cout << "Destr VymModel\n"; insilmaril@721: autosaveTimer->stop(); insilmaril@721: fileChangedTimer->stop(); insilmaril@721: clear(); insilmaril@650: } insilmaril@650: insilmaril@650: void VymModel::clear() insilmaril@650: { insilmaril@735: selModel->clearSelection(); insilmaril@721: insilmaril@727: // Remove stuff insilmaril@727: while (!mapCenters.isEmpty()) // FIXME VM needs to be in treemodel only... insilmaril@665: delete mapCenters.takeFirst(); insilmaril@727: insilmaril@727: QModelIndex ri=index(rootItem); insilmaril@727: removeRows (0, rowCount(ri),ri); insilmaril@650: } insilmaril@650: insilmaril@650: void VymModel::init () insilmaril@650: { insilmaril@721: // We should have at least one map center to start with insilmaril@727: // addMapCenter(); FIXME VM create this in MapEditor as long as model is part of that insilmaril@727: insilmaril@727: // No MapEditor yet insilmaril@727: mapEditor=NULL; insilmaril@721: insilmaril@728: // Also no scene yet (should not be needed anyway) FIXME VM insilmaril@728: mapScene=NULL; insilmaril@728: insilmaril@721: // History insilmaril@721: mapNum++; insilmaril@721: mapChanged=false; insilmaril@721: mapDefault=true; insilmaril@721: mapUnsaved=false; insilmaril@721: insilmaril@721: curStep=0; insilmaril@721: redosAvail=0; insilmaril@721: undosAvail=0; insilmaril@721: insilmaril@721: stepsTotal=settings.readNumEntry("/history/stepsTotal",100); insilmaril@721: undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal)); insilmaril@721: mainWindow->updateHistory (undoSet); insilmaril@721: insilmaril@721: // Create tmp dirs insilmaril@721: makeTmpDirectories(); insilmaril@721: insilmaril@721: // Files insilmaril@721: zipped=true; insilmaril@721: filePath=""; insilmaril@721: fileName=tr("unnamed"); insilmaril@721: mapName=""; insilmaril@721: blockReposition=false; insilmaril@721: blockSaveState=false; insilmaril@721: insilmaril@721: autosaveTimer=new QTimer (this); insilmaril@721: connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave())); insilmaril@721: insilmaril@721: fileChangedTimer=new QTimer (this); insilmaril@721: fileChangedTimer->start(3000); insilmaril@721: connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged())); insilmaril@721: insilmaril@721: insilmaril@721: // selections insilmaril@728: selModel=NULL; insilmaril@721: insilmaril@721: // find routine insilmaril@741: findCurrent=NULL; insilmaril@741: findPrevious=NULL; insilmaril@721: EOFind=false; insilmaril@696: insilmaril@696: // animations insilmaril@696: animationUse=settings.readBoolEntry("/animation/use",false); insilmaril@696: animationTicks=settings.readNumEntry("/animation/ticks",10); insilmaril@696: animationInterval=settings.readNumEntry("/animation/interval",50); insilmaril@696: animObjList.clear(); insilmaril@696: animationTimer=new QTimer (this); insilmaril@696: connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate())); insilmaril@696: insilmaril@721: // View - map insilmaril@721: defLinkColor=QColor (0,0,255); insilmaril@721: defXLinkColor=QColor (180,180,180); insilmaril@721: linkcolorhint=LinkableMapObj::DefaultColor; insilmaril@721: linkstyle=LinkableMapObj::PolyParabel; insilmaril@721: defXLinkWidth=1; insilmaril@721: defXLinkColor=QColor (230,230,230); insilmaril@721: insilmaril@721: hidemode=HideNone; insilmaril@721: insilmaril@721: // Network insilmaril@721: netstate=Offline; insilmaril@721: insilmaril@721: // Create MapCenter insilmaril@727: // addMapCenter(); FIXME VM create this in MapEditor until BO and MCO are independent of scene insilmaril@721: insilmaril@650: } insilmaril@650: insilmaril@721: void VymModel::makeTmpDirectories() insilmaril@721: { insilmaril@721: // Create unique temporary directories insilmaril@721: tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum); insilmaril@721: histPath = tmpMapDir+"/history"; insilmaril@721: QDir d; insilmaril@721: d.mkdir (tmpMapDir); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@727: MapEditor* VymModel::getMapEditor() // FIXME VM better return favourite editor here insilmaril@650: { insilmaril@650: return mapEditor; insilmaril@650: } insilmaril@650: insilmaril@721: bool VymModel::isRepositionBlocked() insilmaril@650: { insilmaril@721: return blockReposition; insilmaril@650: } insilmaril@650: insilmaril@721: void VymModel::updateActions() // FIXME maybe don't update if blockReposition is set insilmaril@650: { insilmaril@742: cout << "VymModel::updateActions \n"; insilmaril@721: // Tell mainwindow to update states of actions insilmaril@721: mainWindow->updateActions(); insilmaril@650: } insilmaril@650: insilmaril@721: insilmaril@721: insilmaril@721: QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel) insilmaril@650: { insilmaril@721: // tmpdir temporary directory to which data will be written insilmaril@721: // prefix mapname, which will be appended to images etc. insilmaril@721: // writeflags Only write flags for "real" save of map, not undo insilmaril@721: // offset offset of bbox of whole map in scene. insilmaril@721: // Needed for XML export insilmaril@721: insilmaril@726: insilmaril@726: XMLObj xml; insilmaril@726: insilmaril@721: // Save Header insilmaril@721: QString ls; insilmaril@721: switch (linkstyle) insilmaril@721: { insilmaril@721: case LinkableMapObj::Line: insilmaril@721: ls="StyleLine"; insilmaril@721: break; insilmaril@721: case LinkableMapObj::Parabel: insilmaril@721: ls="StyleParabel"; insilmaril@721: break; insilmaril@721: case LinkableMapObj::PolyLine: insilmaril@721: ls="StylePolyLine"; insilmaril@721: break; insilmaril@721: default: insilmaril@721: ls="StylePolyParabel"; insilmaril@721: break; insilmaril@721: } insilmaril@721: insilmaril@721: QString s="\n"; insilmaril@721: QString colhint=""; insilmaril@721: if (linkcolorhint==LinkableMapObj::HeadingColor) insilmaril@726: colhint=xml.attribut("linkColorHint","HeadingColor"); insilmaril@726: insilmaril@726: QString mapAttr=xml.attribut("version",vymVersion); insilmaril@721: if (!saveSel) insilmaril@726: mapAttr+= xml.attribut("author",author) + insilmaril@726: xml.attribut("comment",comment) + insilmaril@726: xml.attribut("date",getDate()) + insilmaril@742: xml.attribut("countBranches", QString().number(countBranches())) + insilmaril@726: xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) + insilmaril@728: xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) + insilmaril@726: xml.attribut("linkStyle", ls ) + insilmaril@726: xml.attribut("linkColor", defLinkColor.name() ) + insilmaril@726: xml.attribut("defXLinkColor", defXLinkColor.name() ) + insilmaril@726: xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) + insilmaril@721: colhint; insilmaril@726: s+=xml.beginElement("vymmap",mapAttr); insilmaril@726: xml.incIndent(); insilmaril@721: insilmaril@721: // Find the used flags while traversing the tree insilmaril@721: standardFlagsDefault->resetUsedCounter(); insilmaril@721: insilmaril@721: // Reset the counters before saving insilmaril@721: // TODO constr. of FIO creates lots of objects, better do this in some other way... insilmaril@721: FloatImageObj (mapScene).resetSaveCounter(); insilmaril@721: insilmaril@721: // Build xml recursivly insilmaril@721: if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj)) insilmaril@721: // Save complete map, if saveSel not set insilmaril@721: s+=saveToDir(tmpdir,prefix,writeflags,offset); insilmaril@721: else insilmaril@721: { insilmaril@721: if ( typeid(*saveSel) == typeid(BranchObj) ) insilmaril@721: // Save Subtree insilmaril@721: s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset); insilmaril@721: else if ( typeid(*saveSel) == typeid(FloatImageObj) ) insilmaril@721: // Save image insilmaril@721: s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix); insilmaril@721: } insilmaril@721: insilmaril@721: // Save local settings insilmaril@721: s+=settings.getDataXML (destPath); insilmaril@721: insilmaril@721: // Save selection insilmaril@721: if (!selection.isEmpty() && !saveSel ) insilmaril@726: s+=xml.valueElement("select",selection.getSelectString()); insilmaril@726: insilmaril@726: xml.decIndent(); insilmaril@726: s+=xml.endElement("vymmap"); insilmaril@721: insilmaril@721: if (writeflags) insilmaril@721: standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags); insilmaril@721: return s; insilmaril@650: } insilmaril@650: insilmaril@721: void VymModel::setFilePath(QString fpath, QString destname) insilmaril@650: { insilmaril@721: if (fpath.isEmpty() || fpath=="") insilmaril@721: { insilmaril@721: filePath=""; insilmaril@721: fileName=""; insilmaril@721: destPath=""; insilmaril@721: } else insilmaril@721: { insilmaril@721: filePath=fpath; // becomes absolute path insilmaril@721: fileName=fpath; // gets stripped of path insilmaril@721: destPath=destname; // needed for vymlinks and during load to reset fileChangedTime insilmaril@721: insilmaril@721: // If fpath is not an absolute path, complete it insilmaril@721: filePath=QDir(fpath).absPath(); insilmaril@721: fileDir=filePath.left (1+filePath.findRev ("/")); insilmaril@721: insilmaril@721: // Set short name, too. Search from behind: insilmaril@721: int i=fileName.findRev("/"); insilmaril@721: if (i>=0) fileName=fileName.remove (0,i+1); insilmaril@721: insilmaril@721: // Forget the .vym (or .xml) for name of map insilmaril@721: mapName=fileName.left(fileName.findRev(".",-1,true) ); insilmaril@721: } insilmaril@650: } insilmaril@650: insilmaril@721: void VymModel::setFilePath(QString fpath) insilmaril@650: { insilmaril@721: setFilePath (fpath,fpath); insilmaril@650: } insilmaril@650: insilmaril@721: QString VymModel::getFilePath() insilmaril@650: { insilmaril@721: return filePath; insilmaril@650: } insilmaril@650: insilmaril@721: QString VymModel::getFileName() insilmaril@650: { insilmaril@721: return fileName; insilmaril@650: } insilmaril@650: insilmaril@721: QString VymModel::getMapName() insilmaril@721: { insilmaril@721: return mapName; insilmaril@721: } insilmaril@721: insilmaril@721: QString VymModel::getDestPath() insilmaril@721: { insilmaril@721: return destPath; insilmaril@721: } insilmaril@721: insilmaril@721: ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype) insilmaril@721: { insilmaril@721: ErrorCode err=success; insilmaril@721: insilmaril@721: parseBaseHandler *handler; insilmaril@721: fileType=ftype; insilmaril@721: switch (fileType) insilmaril@721: { insilmaril@721: case VymMap: handler=new parseVYMHandler; break; insilmaril@721: case FreemindMap : handler=new parseFreemindHandler; break; insilmaril@721: default: insilmaril@721: QMessageBox::critical( 0, tr( "Critical Parse Error" ), insilmaril@721: "Unknown FileType in VymModel::load()"); insilmaril@721: return aborted; insilmaril@721: } insilmaril@729: insilmaril@729: bool zipped_org=zipped; insilmaril@729: insilmaril@721: if (lmode==NewMap) insilmaril@721: { insilmaril@735: selModel->clearSelection(); insilmaril@727: // FIXME VM not needed??? model->setMapEditor(this); insilmaril@721: // (map state is set later at end of load...) insilmaril@721: } else insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (!bo) return aborted; insilmaril@721: if (lmode==ImportAdd) insilmaril@721: saveStateChangingPart( insilmaril@721: bo, insilmaril@721: bo, insilmaril@721: QString("addMapInsert (%1)").arg(fname), insilmaril@721: QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo))); insilmaril@721: else insilmaril@721: saveStateChangingPart( insilmaril@721: bo, insilmaril@721: bo, insilmaril@721: QString("addMapReplace(%1)").arg(fname), insilmaril@721: QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo))); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: // Create temporary directory for packing insilmaril@721: bool ok; insilmaril@721: QString tmpZipDir=makeTmpDir (ok,"vym-pack"); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: QMessageBox::critical( 0, tr( "Critical Load Error" ), insilmaril@721: tr("Couldn't create temporary directory before load\n")); insilmaril@721: return aborted; insilmaril@721: } insilmaril@721: insilmaril@721: // Try to unzip file insilmaril@721: err=unzipDir (tmpZipDir,fname); insilmaril@721: QString xmlfile; insilmaril@721: if (err==nozip) insilmaril@721: { insilmaril@721: xmlfile=fname; insilmaril@721: zipped=false; insilmaril@721: } else insilmaril@721: { insilmaril@721: zipped=true; insilmaril@721: insilmaril@721: // Look for mapname.xml insilmaril@721: xmlfile= fname.left(fname.findRev(".",-1,true)); insilmaril@721: xmlfile=xmlfile.section( '/', -1 ); insilmaril@721: QFile mfile( tmpZipDir + "/" + xmlfile + ".xml"); insilmaril@721: if (!mfile.exists() ) insilmaril@721: { insilmaril@721: // mapname.xml does not exist, well, insilmaril@721: // maybe someone renamed the mapname.vym file... insilmaril@721: // Try to find any .xml in the toplevel insilmaril@721: // directory of the .vym file insilmaril@721: QStringList flist=QDir (tmpZipDir).entryList("*.xml"); insilmaril@721: if (flist.count()==1) insilmaril@721: { insilmaril@721: // Only one entry, take this one insilmaril@721: xmlfile=tmpZipDir + "/"+flist.first(); insilmaril@721: } else insilmaril@721: { insilmaril@721: for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) insilmaril@721: *it=tmpZipDir + "/" + *it; insilmaril@721: // TODO Multiple entries, load all (but only the first one into this ME) insilmaril@721: //mainWindow->fileLoadFromTmp (flist); insilmaril@721: //returnCode=1; // Silently forget this attempt to load insilmaril@721: qWarning ("MainWindow::load (fn) multimap found..."); insilmaril@721: } insilmaril@721: insilmaril@721: if (flist.isEmpty() ) insilmaril@721: { insilmaril@721: QMessageBox::critical( 0, tr( "Critical Load Error" ), insilmaril@721: tr("Couldn't find a map (*.xml) in .vym archive.\n")); insilmaril@721: err=aborted; insilmaril@721: } insilmaril@721: } //file doesn't exist insilmaril@721: else insilmaril@721: xmlfile=mfile.name(); insilmaril@721: } insilmaril@721: insilmaril@721: QFile file( xmlfile); insilmaril@721: insilmaril@721: // I am paranoid: file should exist anyway insilmaril@721: // according to check in mainwindow. insilmaril@721: if (!file.exists() ) insilmaril@721: { insilmaril@721: QMessageBox::critical( 0, tr( "Critical Parse Error" ), insilmaril@721: tr(QString("Couldn't open map %1").arg(file.name()))); insilmaril@721: err=aborted; insilmaril@721: } else insilmaril@721: { insilmaril@721: bool blockSaveStateOrg=blockSaveState; insilmaril@721: blockReposition=true; insilmaril@721: blockSaveState=true; insilmaril@721: QXmlInputSource source( file); insilmaril@721: QXmlSimpleReader reader; insilmaril@721: reader.setContentHandler( handler ); insilmaril@721: reader.setErrorHandler( handler ); insilmaril@721: handler->setModel ( this); insilmaril@721: insilmaril@721: insilmaril@721: // We need to set the tmpDir in order to load files with rel. path insilmaril@721: QString tmpdir; insilmaril@721: if (zipped) insilmaril@721: tmpdir=tmpZipDir; insilmaril@721: else insilmaril@721: tmpdir=fname.left(fname.findRev("/",-1)); insilmaril@721: handler->setTmpDir (tmpdir); insilmaril@721: handler->setInputFile (file.name()); insilmaril@721: handler->setLoadMode (lmode); insilmaril@721: bool ok = reader.parse( source ); insilmaril@721: blockReposition=false; insilmaril@721: blockSaveState=blockSaveStateOrg; insilmaril@721: file.close(); insilmaril@721: if ( ok ) insilmaril@721: { insilmaril@727: reposition(); // FIXME VM reposition the view instead... insilmaril@721: selection.update(); insilmaril@721: if (lmode==NewMap) insilmaril@721: { insilmaril@721: mapDefault=false; insilmaril@721: mapChanged=false; insilmaril@721: mapUnsaved=false; insilmaril@721: autosaveTimer->stop(); insilmaril@721: } insilmaril@721: insilmaril@721: // Reset timestamp to check for later updates of file insilmaril@721: fileChangedTime=QFileInfo (destPath).lastModified(); insilmaril@721: } else insilmaril@721: { insilmaril@721: QMessageBox::critical( 0, tr( "Critical Parse Error" ), insilmaril@721: tr( handler->errorProtocol() ) ); insilmaril@721: // returnCode=1; insilmaril@721: // Still return "success": the map maybe at least insilmaril@721: // partially read by the parser insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: // Delete tmpZipDir insilmaril@721: removeDir (QDir(tmpZipDir)); insilmaril@721: insilmaril@729: // Restore original zip state insilmaril@729: zipped=zipped_org; insilmaril@729: insilmaril@721: updateActions(); insilmaril@721: return err; insilmaril@721: } insilmaril@721: insilmaril@721: ErrorCode VymModel::save (const SaveMode &savemode) insilmaril@721: { insilmaril@721: QString tmpZipDir; insilmaril@721: QString mapFileName; insilmaril@721: QString safeFilePath; insilmaril@721: insilmaril@721: ErrorCode err=success; insilmaril@721: insilmaril@721: if (zipped) insilmaril@721: // save as .xml insilmaril@721: mapFileName=mapName+".xml"; insilmaril@721: else insilmaril@721: // use name given by user, even if he chooses .doc insilmaril@721: mapFileName=fileName; insilmaril@721: insilmaril@721: // Look, if we should zip the data: insilmaril@721: if (!zipped) insilmaril@721: { insilmaril@721: QMessageBox mb( vymName, insilmaril@721: tr("The map %1\ndid not use the compressed " insilmaril@721: "vym file format.\nWriting it uncompressed will also write images \n" insilmaril@721: "and flags and thus may overwrite files in the " insilmaril@721: "given directory\n\nDo you want to write the map").arg(filePath), insilmaril@721: QMessageBox::Warning, insilmaril@721: QMessageBox::Yes | QMessageBox::Default, insilmaril@721: QMessageBox::No , insilmaril@721: QMessageBox::Cancel | QMessageBox::Escape); insilmaril@721: mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") ); insilmaril@721: mb.setButtonText( QMessageBox::No, tr("uncompressed") ); insilmaril@721: mb.setButtonText( QMessageBox::Cancel, tr("Cancel")); insilmaril@721: switch( mb.exec() ) insilmaril@721: { insilmaril@721: case QMessageBox::Yes: insilmaril@721: // save compressed (default file format) insilmaril@721: zipped=true; insilmaril@721: break; insilmaril@721: case QMessageBox::No: insilmaril@721: // save uncompressed insilmaril@721: zipped=false; insilmaril@721: break; insilmaril@721: case QMessageBox::Cancel: insilmaril@721: // do nothing insilmaril@721: return aborted; insilmaril@721: break; insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: // First backup existing file, we insilmaril@721: // don't want to add to old zip archives insilmaril@721: QFile f(destPath); insilmaril@721: if (f.exists()) insilmaril@721: { insilmaril@721: if ( settings.value ("/mapeditor/writeBackupFile").toBool()) insilmaril@721: { insilmaril@721: QString backupFileName(destPath + "~"); insilmaril@721: QFile backupFile(backupFileName); insilmaril@721: if (backupFile.exists() && !backupFile.remove()) insilmaril@721: { insilmaril@721: QMessageBox::warning(0, tr("Save Error"), insilmaril@721: tr("%1\ncould not be removed before saving").arg(backupFileName)); insilmaril@721: } insilmaril@721: else if (!f.rename(backupFileName)) insilmaril@721: { insilmaril@721: QMessageBox::warning(0, tr("Save Error"), insilmaril@721: tr("%1\ncould not be renamed before saving").arg(destPath)); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: if (zipped) insilmaril@721: { insilmaril@721: // Create temporary directory for packing insilmaril@721: bool ok; insilmaril@721: tmpZipDir=makeTmpDir (ok,"vym-zip"); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: QMessageBox::critical( 0, tr( "Critical Load Error" ), insilmaril@721: tr("Couldn't create temporary directory before save\n")); insilmaril@721: return aborted; insilmaril@721: } insilmaril@721: insilmaril@721: safeFilePath=filePath; insilmaril@721: setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath); insilmaril@721: } // zipped insilmaril@721: insilmaril@721: // Create mapName and fileDir insilmaril@721: makeSubDirs (fileDir); insilmaril@721: insilmaril@721: QString saveFile; insilmaril@721: if (savemode==CompleteMap || selection.isEmpty()) insilmaril@721: { insilmaril@721: // Save complete map insilmaril@721: saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL); insilmaril@721: mapChanged=false; insilmaril@721: mapUnsaved=false; insilmaril@721: autosaveTimer->stop(); insilmaril@721: } insilmaril@721: else insilmaril@721: { insilmaril@721: // Save part of map insilmaril@735: if (selectionType()==TreeItem::Image) insilmaril@721: saveFloatImage(); insilmaril@721: else insilmaril@735: saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch()); insilmaril@721: // TODO take care of multiselections insilmaril@721: } insilmaril@721: insilmaril@721: if (!saveStringToDisk(fileDir+mapFileName,saveFile)) insilmaril@721: { insilmaril@721: err=aborted; insilmaril@721: qWarning ("ME::saveStringToDisk failed!"); insilmaril@721: } insilmaril@721: insilmaril@721: if (zipped) insilmaril@721: { insilmaril@721: // zip insilmaril@721: if (err==success) err=zipDir (tmpZipDir,destPath); insilmaril@721: insilmaril@721: // Delete tmpDir insilmaril@721: removeDir (QDir(tmpZipDir)); insilmaril@721: insilmaril@721: // Restore original filepath outside of tmp zip dir insilmaril@721: setFilePath (safeFilePath); insilmaril@721: } insilmaril@721: insilmaril@721: updateActions(); insilmaril@721: fileChangedTime=QFileInfo (destPath).lastModified(); insilmaril@721: return err; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path) insilmaril@721: { insilmaril@721: QString pathDir=path.left(path.findRev("/")); insilmaril@721: QDir d(pathDir); insilmaril@721: QFile file (path); insilmaril@721: insilmaril@721: if (d.exists() ) insilmaril@721: { insilmaril@721: // We need to parse saved XML data insilmaril@721: parseVYMHandler handler; insilmaril@721: QXmlInputSource source( file); insilmaril@721: QXmlSimpleReader reader; insilmaril@721: reader.setContentHandler( &handler ); insilmaril@721: reader.setErrorHandler( &handler ); insilmaril@721: handler.setModel ( this); insilmaril@721: handler.setTmpDir ( pathDir ); // needed to load files with rel. path insilmaril@721: if (undoSel.isEmpty()) insilmaril@721: { insilmaril@721: unselect(); insilmaril@721: clear(); insilmaril@721: handler.setLoadMode (NewMap); insilmaril@721: } else insilmaril@721: { insilmaril@721: select (undoSel); insilmaril@721: handler.setLoadMode (ImportReplace); insilmaril@721: } insilmaril@721: blockReposition=true; insilmaril@721: bool ok = reader.parse( source ); insilmaril@721: blockReposition=false; insilmaril@721: if (! ok ) insilmaril@721: { insilmaril@721: // This should never ever happen insilmaril@721: QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), insilmaril@721: handler.errorProtocol()); insilmaril@721: } insilmaril@721: } else insilmaril@721: QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::addMapInsertInt (const QString &path, int pos) insilmaril@721: { insilmaril@735: BranchObj *sel=getSelectedBranch(); insilmaril@721: if (sel) insilmaril@721: { insilmaril@721: QString pathDir=path.left(path.findRev("/")); insilmaril@721: QDir d(pathDir); insilmaril@721: QFile file (path); insilmaril@721: insilmaril@721: if (d.exists() ) insilmaril@721: { insilmaril@721: // We need to parse saved XML data insilmaril@721: parseVYMHandler handler; insilmaril@721: QXmlInputSource source( file); insilmaril@721: QXmlSimpleReader reader; insilmaril@721: reader.setContentHandler( &handler ); insilmaril@721: reader.setErrorHandler( &handler ); insilmaril@721: handler.setModel (this); insilmaril@721: handler.setTmpDir ( pathDir ); // needed to load files with rel. path insilmaril@721: handler.setLoadMode (ImportAdd); insilmaril@721: blockReposition=true; insilmaril@721: bool ok = reader.parse( source ); insilmaril@721: blockReposition=false; insilmaril@721: if (! ok ) insilmaril@721: { insilmaril@721: // This should never ever happen insilmaril@721: QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), insilmaril@721: handler.errorProtocol()); insilmaril@721: } insilmaril@721: if (sel->getDepth()>0) insilmaril@721: sel->getLastBranch()->linkTo (sel,pos); insilmaril@721: } else insilmaril@721: QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: FloatImageObj* VymModel::loadFloatImageInt (QString fn) insilmaril@721: { insilmaril@739: TreeItem *fi=createImage(); insilmaril@739: if (fi) insilmaril@721: { insilmaril@739: FloatImageObj *fio= ((FloatImageObj*)fi->getLMO()); insilmaril@739: fio->load (fn); insilmaril@721: reposition(); insilmaril@721: return fio; insilmaril@721: } insilmaril@721: return NULL; insilmaril@740: } insilmaril@721: insilmaril@721: void VymModel::loadFloatImage () insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: insilmaril@721: Q3FileDialog *fd=new Q3FileDialog( NULL); insilmaril@721: fd->setMode (Q3FileDialog::ExistingFiles); insilmaril@721: fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); insilmaril@721: ImagePreview *p =new ImagePreview (fd); insilmaril@721: fd->setContentsPreviewEnabled( TRUE ); insilmaril@721: fd->setContentsPreview( p, p ); insilmaril@721: fd->setPreviewMode( Q3FileDialog::Contents ); insilmaril@721: fd->setCaption(vymName+" - " +tr("Load image")); insilmaril@721: fd->setDir (lastImageDir); insilmaril@721: fd->show(); insilmaril@721: insilmaril@721: if ( fd->exec() == QDialog::Accepted ) insilmaril@721: { insilmaril@721: // TODO loadFIO in QT4 use: lastImageDir=fd->directory(); insilmaril@721: lastImageDir=QDir (fd->dirPath()); insilmaril@721: QString s; insilmaril@721: FloatImageObj *fio; insilmaril@721: for (int j=0; jselectedFiles().count(); j++) insilmaril@721: { insilmaril@721: s=fd->selectedFiles().at(j); insilmaril@721: fio=loadFloatImageInt (s); insilmaril@721: if (fio) insilmaril@721: saveState( insilmaril@721: (LinkableMapObj*)fio, insilmaril@721: "delete ()", insilmaril@721: bo, insilmaril@721: QString ("loadImage (%1)").arg(s ), insilmaril@721: QString("Add image %1 to %2").arg(s).arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: else insilmaril@721: // TODO loadFIO error handling insilmaril@721: qWarning ("Failed to load "+s); insilmaril@721: } insilmaril@721: } insilmaril@721: delete (p); insilmaril@721: delete (fd); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn) insilmaril@721: { insilmaril@721: fio->save (fn,type); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::saveFloatImage () insilmaril@721: { insilmaril@721: FloatImageObj *fio=selection.getFloatImage(); insilmaril@721: if (fio) insilmaril@721: { insilmaril@721: QFileDialog *fd=new QFileDialog( NULL); insilmaril@721: fd->setFilters (imageIO.getFilters()); insilmaril@721: fd->setCaption(vymName+" - " +tr("Save image")); insilmaril@721: fd->setFileMode( QFileDialog::AnyFile ); insilmaril@721: fd->setDirectory (lastImageDir); insilmaril@721: // fd->setSelection (fio->getOriginalFilename()); insilmaril@721: fd->show(); insilmaril@721: insilmaril@721: QString fn; insilmaril@721: if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1) insilmaril@721: { insilmaril@721: fn=fd->selectedFiles().at(0); insilmaril@721: if (QFile (fn).exists() ) insilmaril@721: { insilmaril@721: QMessageBox mb( vymName, insilmaril@721: tr("The file %1 exists already.\n" insilmaril@721: "Do you want to overwrite it?").arg(fn), insilmaril@721: QMessageBox::Warning, insilmaril@721: QMessageBox::Yes | QMessageBox::Default, insilmaril@721: QMessageBox::Cancel | QMessageBox::Escape, insilmaril@721: QMessageBox::NoButton ); insilmaril@721: insilmaril@721: mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); insilmaril@721: mb.setButtonText( QMessageBox::No, tr("Cancel")); insilmaril@721: switch( mb.exec() ) insilmaril@721: { insilmaril@721: case QMessageBox::Yes: insilmaril@721: // save insilmaril@721: break; insilmaril@721: case QMessageBox::Cancel: insilmaril@721: // do nothing insilmaril@721: delete (fd); insilmaril@721: return; insilmaril@721: break; insilmaril@721: } insilmaril@721: } insilmaril@721: saveFloatImageInt (fio,fd->selectedFilter(),fn ); insilmaril@721: } insilmaril@721: delete (fd); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::importDirInt(BranchObj *dst, QDir d) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: // Traverse directories insilmaril@721: d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks ); insilmaril@721: QFileInfoList list = d.entryInfoList(); insilmaril@721: QFileInfo fi; insilmaril@721: insilmaril@721: for (int i = 0; i < list.size(); ++i) insilmaril@721: { insilmaril@721: fi=list.at(i); insilmaril@721: if (fi.fileName() != "." && fi.fileName() != ".." ) insilmaril@721: { insilmaril@721: dst->addBranch(); insilmaril@721: bo=dst->getLastBranch(); insilmaril@721: bo->setHeading (fi.fileName() ); insilmaril@721: bo->setColor (QColor("blue")); insilmaril@721: bo->toggleScroll(); insilmaril@721: if ( !d.cd(fi.fileName()) ) insilmaril@721: QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName())); insilmaril@721: else insilmaril@721: { insilmaril@721: // Recursively add subdirs insilmaril@721: importDirInt (bo,d); insilmaril@721: d.cdUp(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: // Traverse files insilmaril@721: d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks ); insilmaril@721: list = d.entryInfoList(); insilmaril@721: insilmaril@721: for (int i = 0; i < list.size(); ++i) insilmaril@721: { insilmaril@721: fi=list.at(i); insilmaril@721: dst->addBranch(); insilmaril@721: bo=dst->getLastBranch(); insilmaril@721: bo->setHeading (fi.fileName() ); insilmaril@721: bo->setColor (QColor("black")); insilmaril@721: if (fi.fileName().right(4) == ".vym" ) insilmaril@721: bo->setVymLink (fi.filePath()); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::importDirInt (const QString &s) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s)); insilmaril@721: insilmaril@721: QDir d(s); insilmaril@721: importDirInt (bo,d); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::importDir() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QStringList filters; insilmaril@721: filters <<"VYM map (*.vym)"; insilmaril@721: QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import")); insilmaril@721: fd->setMode (QFileDialog::DirectoryOnly); insilmaril@721: fd->setFilters (filters); insilmaril@721: fd->setCaption(vymName+" - " +tr("Choose directory structure to import")); insilmaril@721: fd->show(); insilmaril@721: insilmaril@721: QString fn; insilmaril@721: if ( fd->exec() == QDialog::Accepted ) insilmaril@721: { insilmaril@721: importDirInt (fd->selectedFile() ); insilmaril@721: reposition(); insilmaril@727: //FIXME VM needed? scene()->update(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::autosave() insilmaril@721: { insilmaril@742: if (filePath=="") insilmaril@742: { insilmaril@742: if (debug) insilmaril@742: cout << "VymModel::autosave rejected due to missing filePath\n"; insilmaril@742: } insilmaril@742: insilmaril@721: QDateTime now=QDateTime().currentDateTime(); insilmaril@721: insilmaril@721: // Disable autosave, while we have gone back in history insilmaril@721: int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail")); insilmaril@721: if (redosAvail>0) return; insilmaril@721: insilmaril@721: // Also disable autosave for new map without filename insilmaril@721: if (filePath.isEmpty()) return; insilmaril@721: insilmaril@721: insilmaril@742: if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() ) insilmaril@721: { insilmaril@721: if (QFileInfo(filePath).lastModified()<=fileChangedTime) insilmaril@721: mainWindow->fileSave (this); insilmaril@721: else insilmaril@721: if (debug) insilmaril@721: cout <<" ME::autosave rejected, file on disk is newer than last save.\n"; insilmaril@721: insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::fileChanged() insilmaril@721: { insilmaril@721: // Check if file on disk has changed meanwhile insilmaril@721: if (!filePath.isEmpty()) insilmaril@721: { insilmaril@721: QDateTime tmod=QFileInfo (filePath).lastModified(); insilmaril@721: if (tmod>fileChangedTime) insilmaril@721: { insilmaril@727: // FIXME VM switch to current mapeditor and finish lineedits... insilmaril@721: QMessageBox mb( vymName, insilmaril@721: tr("The file of the map on disk has changed:\n\n" insilmaril@721: " %1\n\nDo you want to reload that map with the new file?").arg(filePath), insilmaril@721: QMessageBox::Question, insilmaril@721: QMessageBox::Yes , insilmaril@721: QMessageBox::Cancel | QMessageBox::Default, insilmaril@721: QMessageBox::NoButton ); insilmaril@721: insilmaril@721: mb.setButtonText( QMessageBox::Yes, tr("Reload")); insilmaril@721: mb.setButtonText( QMessageBox::No, tr("Ignore")); insilmaril@721: switch( mb.exec() ) insilmaril@721: { insilmaril@721: case QMessageBox::Yes: insilmaril@721: // Reload map insilmaril@721: load (filePath,NewMap,fileType); insilmaril@721: case QMessageBox::Cancel: insilmaril@721: fileChangedTime=tmod; // allow autosave to overwrite newer file! insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: bool VymModel::isDefault() insilmaril@721: { insilmaril@721: return mapDefault; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::makeDefault() insilmaril@721: { insilmaril@721: mapChanged=false; insilmaril@721: mapDefault=true; insilmaril@721: } insilmaril@721: insilmaril@721: bool VymModel::hasChanged() insilmaril@721: { insilmaril@721: return mapChanged; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setChanged() insilmaril@721: { insilmaril@742: cout << "VM::setChanged()\n"; insilmaril@721: if (!mapChanged) insilmaril@742: { insilmaril@742: autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt()); insilmaril@742: cout <<" timer started with "<getHeading()); insilmaril@721: if (s=="") s="unnamed"; insilmaril@721: return QString("branch (%1)").arg(s); insilmaril@721: } insilmaril@721: if ((typeid(*lmo) == typeid(FloatImageObj) )) insilmaril@721: return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename()); insilmaril@721: return QString("Unknown type has no name!"); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::redo() insilmaril@721: { insilmaril@721: // Can we undo at all? insilmaril@721: if (redosAvail<1) return; insilmaril@721: insilmaril@721: bool blockSaveStateOrg=blockSaveState; insilmaril@721: blockSaveState=true; insilmaril@721: insilmaril@721: redosAvail--; insilmaril@721: insilmaril@721: if (undosAvailstepsTotal) curStep=1; insilmaril@721: QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep)); insilmaril@721: QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep)); insilmaril@721: QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep)); insilmaril@721: QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep)); insilmaril@721: QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep)); insilmaril@721: QString version=undoSet.readEntry ("/history/version"); insilmaril@721: insilmaril@721: /* TODO Maybe check for version, if we save the history insilmaril@721: if (!checkVersion(version)) insilmaril@721: QMessageBox::warning(0,tr("Warning"), insilmaril@721: tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion)); insilmaril@721: */ insilmaril@721: insilmaril@721: // Find out current undo directory insilmaril@721: QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep)); insilmaril@721: insilmaril@721: if (debug) insilmaril@721: { insilmaril@721: cout << "VymModel::redo() begin\n"; insilmaril@721: cout << " undosAvail="<updateHistory (undoSet); insilmaril@721: updateActions(); insilmaril@721: insilmaril@721: /* TODO remove testing insilmaril@721: cout << "ME::redo() end\n"; insilmaril@721: cout << " undosAvail="<0) insilmaril@721: return true; insilmaril@721: else insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::undo() insilmaril@721: { insilmaril@721: // Can we undo at all? insilmaril@721: if (undosAvail<1) return; insilmaril@721: insilmaril@721: mainWindow->statusMessage (tr("Autosave disabled during undo.")); insilmaril@721: insilmaril@721: bool blockSaveStateOrg=blockSaveState; insilmaril@721: blockSaveState=true; insilmaril@721: insilmaril@721: QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep)); insilmaril@721: QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep)); insilmaril@721: QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep)); insilmaril@721: QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep)); insilmaril@721: QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep)); insilmaril@721: QString version=undoSet.readEntry ("/history/version"); insilmaril@721: insilmaril@721: /* TODO Maybe check for version, if we save the history insilmaril@721: if (!checkVersion(version)) insilmaril@721: QMessageBox::warning(0,tr("Warning"), insilmaril@721: tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion)); insilmaril@721: */ insilmaril@721: insilmaril@721: // Find out current undo directory insilmaril@721: QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep)); insilmaril@721: insilmaril@721: // select object before undo insilmaril@721: if (!undoSelection.isEmpty()) insilmaril@721: select (undoSelection); insilmaril@721: insilmaril@721: if (debug) insilmaril@721: { insilmaril@721: cout << "VymModel::undo() begin\n"; insilmaril@721: cout << " undosAvail="<updateHistory (undoSet); insilmaril@721: updateActions(); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@721: insilmaril@721: bool VymModel::isUndoAvailable() insilmaril@721: { insilmaril@721: if (undoSet.readNumEntry("/history/undosAvail",0)>0) insilmaril@721: return true; insilmaril@721: else insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::gotoHistoryStep (int i) insilmaril@721: { insilmaril@721: // Restore variables insilmaril@721: int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail")); insilmaril@721: int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail")); insilmaril@721: insilmaril@721: if (i<0) i=undosAvail+redosAvail; insilmaril@721: insilmaril@721: // Clicking above current step makes us undo things insilmaril@721: if (iundosAvail) insilmaril@721: for (int j=undosAvail; jstepsTotal) curStep=1; insilmaril@721: insilmaril@721: QString backupXML=""; insilmaril@721: QString histDir=getHistoryPath(); insilmaril@721: QString bakMapPath=histDir+"/map.xml"; insilmaril@721: insilmaril@721: // Create histDir if not available insilmaril@721: QDir d(histDir); insilmaril@721: if (!d.exists()) insilmaril@721: makeSubDirs (histDir); insilmaril@721: insilmaril@721: // Save depending on how much needs to be saved insilmaril@721: if (saveSel) insilmaril@721: backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel); insilmaril@721: insilmaril@721: QString undoCommand=""; insilmaril@721: if (savemode==UndoCommand) insilmaril@721: { insilmaril@721: undoCommand=undoCom; insilmaril@721: } insilmaril@721: else if (savemode==PartOfMap ) insilmaril@721: { insilmaril@721: undoCommand=undoCom; insilmaril@721: undoCommand.replace ("PATH",bakMapPath); insilmaril@721: } insilmaril@721: insilmaril@721: if (!backupXML.isEmpty()) insilmaril@721: // Write XML Data to disk insilmaril@721: saveStringToDisk (bakMapPath,backupXML); insilmaril@721: insilmaril@721: // We would have to save all actions in a tree, to keep track of insilmaril@721: // possible redos after a action. Possible, but we are too lazy: forget about redos. insilmaril@721: redosAvail=0; insilmaril@721: insilmaril@721: // Write the current state to disk insilmaril@721: undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); insilmaril@721: undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail)); insilmaril@721: undoSet.setEntry ("/history/curStep",QString::number(curStep)); insilmaril@721: undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand); insilmaril@721: undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection); insilmaril@721: undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom); insilmaril@721: undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection); insilmaril@721: undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment); insilmaril@721: undoSet.setEntry (QString("/history/version"),vymVersion); insilmaril@721: undoSet.writeSettings(histPath); insilmaril@721: insilmaril@721: if (debug) insilmaril@721: { insilmaril@721: // TODO remove after testing insilmaril@721: //cout << " into="<< histPath.toStdString()<updateHistory (undoSet); insilmaril@721: setChanged(); insilmaril@721: updateActions(); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment) insilmaril@721: { insilmaril@721: // save the selected part of the map, Undo will replace part of map insilmaril@721: QString undoSelection=""; insilmaril@721: if (undoSel) insilmaril@721: undoSelection=getSelectString(undoSel); insilmaril@721: else insilmaril@721: qWarning ("VymModel::saveStateChangingPart no undoSel given!"); insilmaril@721: QString redoSelection=""; insilmaril@721: if (redoSel) insilmaril@721: redoSelection=getSelectString(undoSel); insilmaril@721: else insilmaril@721: qWarning ("VymModel::saveStateChangingPart no redoSel given!"); insilmaril@721: insilmaril@721: insilmaril@721: saveState (PartOfMap, insilmaril@721: undoSelection, "addMapReplace (\"PATH\")", insilmaril@721: redoSelection, rc, insilmaril@721: comment, insilmaril@721: undoSel); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment) insilmaril@721: { insilmaril@721: if (!redoSel) insilmaril@721: { insilmaril@721: qWarning ("VymModel::saveStateRemovingPart no redoSel given!"); insilmaril@721: return; insilmaril@721: } insilmaril@721: QString undoSelection=getSelectString (redoSel->getParObj()); insilmaril@721: QString redoSelection=getSelectString(redoSel); insilmaril@721: if (typeid(*redoSel) == typeid(BranchObj) ) insilmaril@721: { insilmaril@721: // save the selected branch of the map, Undo will insert part of map insilmaril@721: saveState (PartOfMap, insilmaril@721: undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()), insilmaril@721: redoSelection, "delete ()", insilmaril@721: comment, insilmaril@721: redoSel); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) insilmaril@721: { insilmaril@721: // "Normal" savestate: save commands, selections and comment insilmaril@721: // so just save commands for undo and redo insilmaril@721: // and use current selection insilmaril@721: insilmaril@721: QString redoSelection=""; insilmaril@721: if (redoSel) redoSelection=getSelectString(redoSel); insilmaril@721: QString undoSelection=""; insilmaril@721: if (undoSel) undoSelection=getSelectString(undoSel); insilmaril@721: insilmaril@721: saveState (UndoCommand, insilmaril@721: undoSelection, uc, insilmaril@721: redoSelection, rc, insilmaril@721: comment, insilmaril@721: NULL); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment) insilmaril@721: { insilmaril@721: // "Normal" savestate: save commands, selections and comment insilmaril@721: // so just save commands for undo and redo insilmaril@721: // and use current selection insilmaril@721: saveState (UndoCommand, insilmaril@721: undoSel, uc, insilmaril@721: redoSel, rc, insilmaril@721: comment, insilmaril@721: NULL); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment) insilmaril@721: { insilmaril@721: // "Normal" savestate applied to model (no selection needed): insilmaril@721: // save commands and comment insilmaril@721: saveState (UndoCommand, insilmaril@721: NULL, uc, insilmaril@721: NULL, rc, insilmaril@721: comment, insilmaril@721: NULL); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@650: QGraphicsScene* VymModel::getScene () insilmaril@650: { insilmaril@650: return mapScene; insilmaril@650: } insilmaril@650: insilmaril@650: LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO) insilmaril@650: { insilmaril@650: LinkableMapObj *lmo; insilmaril@650: insilmaril@650: for (int i=0;ifindMapObj (p,excludeLMO); insilmaril@650: if (lmo) return lmo; insilmaril@650: } insilmaril@650: return NULL; insilmaril@650: } insilmaril@650: insilmaril@650: LinkableMapObj* VymModel::findObjBySelect(const QString &s) insilmaril@650: { insilmaril@650: LinkableMapObj *lmo; insilmaril@650: if (!s.isEmpty() ) insilmaril@650: { insilmaril@650: QString part; insilmaril@650: QString typ; insilmaril@650: QString num; insilmaril@650: part=s.section(",",0,0); insilmaril@652: typ=part.left (2); insilmaril@650: num=part.right(part.length() - 3); insilmaril@650: if (typ=="mc" && num.toInt()>=0 && num.toInt() findObjBySelect(s); insilmaril@650: if (lmo) return lmo; insilmaril@650: } insilmaril@650: return NULL; insilmaril@650: } insilmaril@650: insilmaril@650: LinkableMapObj* VymModel::findID (const QString &s) insilmaril@650: { insilmaril@650: LinkableMapObj *lmo; insilmaril@650: for (int i=0; ifindID (s); insilmaril@650: if (lmo) return lmo; insilmaril@650: } insilmaril@650: return NULL; insilmaril@650: } insilmaril@650: insilmaril@650: QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) insilmaril@650: { insilmaril@650: QString s; insilmaril@650: insilmaril@650: for (int i=0; isaveToDir (tmpdir,prefix,verbose,offset); insilmaril@650: return s; insilmaril@650: } insilmaril@650: insilmaril@721: ////////////////////////////////////////////// insilmaril@721: // Interface insilmaril@721: ////////////////////////////////////////////// insilmaril@721: void VymModel::setVersion (const QString &s) insilmaril@721: { insilmaril@721: version=s; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setAuthor (const QString &s) insilmaril@721: { insilmaril@721: saveState ( insilmaril@721: QString ("setMapAuthor (\"%1\")").arg(author), insilmaril@721: QString ("setMapAuthor (\"%1\")").arg(s), insilmaril@721: QString ("Set author of map to \"%1\"").arg(s) insilmaril@721: ); insilmaril@721: insilmaril@721: author=s; insilmaril@721: } insilmaril@721: insilmaril@721: QString VymModel::getAuthor() insilmaril@721: { insilmaril@721: return author; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setComment (const QString &s) insilmaril@721: { insilmaril@721: saveState ( insilmaril@721: QString ("setMapComment (\"%1\")").arg(comment), insilmaril@721: QString ("setMapComment (\"%1\")").arg(s), insilmaril@721: QString ("Set comment of map") insilmaril@721: ); insilmaril@721: insilmaril@721: comment=s; insilmaril@721: } insilmaril@721: insilmaril@721: QString VymModel::getComment () insilmaril@721: { insilmaril@721: return comment; insilmaril@721: } insilmaril@721: insilmaril@721: QString VymModel::getDate () insilmaril@721: { insilmaril@721: return QDate::currentDate().toString ("yyyy-MM-dd"); insilmaril@721: } insilmaril@721: insilmaril@742: int VymModel::countBranches() // FIXME Optimize this: use internal counter instead of going through whole map each time... insilmaril@742: { insilmaril@742: int c=0; insilmaril@742: TreeItem *cur=NULL; insilmaril@742: TreeItem *prev=NULL; insilmaril@742: int d; insilmaril@742: next(cur,prev,d); insilmaril@742: while (cur) insilmaril@742: { insilmaril@742: c++; insilmaril@742: next(cur,prev,d); insilmaril@742: } insilmaril@742: return c; insilmaril@742: insilmaril@742: } insilmaril@742: insilmaril@721: void VymModel::setHeading(const QString &s) insilmaril@721: { insilmaril@735: BranchObj *sel=getSelectedBranch(); insilmaril@721: if (sel) insilmaril@721: { insilmaril@721: saveState( insilmaril@721: sel, insilmaril@721: "setHeading (\""+sel->getHeading()+"\")", insilmaril@721: sel, insilmaril@721: "setHeading (\""+s+"\")", insilmaril@721: QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) ); insilmaril@721: sel->setHeading(s ); insilmaril@735: /* FIXME testing only insilmaril@736: */ insilmaril@738: TreeItem *ti=getSelectedItem(); insilmaril@727: if (ti) insilmaril@726: { insilmaril@727: ti->setHeading (s); insilmaril@727: //FIXME VM ix is wrong ModelIndex below, ix2 is (hopefully) correct: insilmaril@736: //QModelIndex ix=index( ti->row(), ti->column(), index (0,0,QModelIndex()) ); insilmaril@727: //FIXME VM testing only cout <<"VM::setHeading s="<row()<<","<column()<<")"<getNote().contains(s,cs)) insilmaril@721: { insilmaril@741: select (findCurrent); insilmaril@741: /* insilmaril@735: if (getSelectedBranch()!=itFind) insilmaril@721: { insilmaril@735: select(itFind); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@741: */ insilmaril@721: if (textEditor->findText(s,flags)) insilmaril@721: { insilmaril@721: searching=false; insilmaril@721: foundNote=true; insilmaril@721: } insilmaril@721: } insilmaril@721: // Searching in Heading insilmaril@741: if (searching && findCurrent->getHeading().contains (s,cs) ) insilmaril@721: { insilmaril@741: select(findCurrent); insilmaril@721: searching=false; insilmaril@721: } insilmaril@721: } insilmaril@721: if (!foundNote) insilmaril@721: { insilmaril@741: if (!next(findCurrent,findPrevious,d) ) insilmaril@741: EOFind=true; insilmaril@721: } insilmaril@721: //cout <<"still searching... "<getHeading())<getURL(); insilmaril@721: else insilmaril@721: return ""; insilmaril@721: } insilmaril@721: insilmaril@721: QStringList VymModel::getURLs() insilmaril@721: { insilmaril@721: QStringList urls; insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bo=bo->first(); insilmaril@721: while (bo) insilmaril@721: { insilmaril@721: if (!bo->getURL().isEmpty()) urls.append( bo->getURL()); insilmaril@721: bo=bo->next(); insilmaril@721: } insilmaril@721: } insilmaril@721: return urls; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::linkFloatImageTo(const QString &dstString) insilmaril@721: { insilmaril@721: FloatImageObj *fio=selection.getFloatImage(); insilmaril@721: if (fio) insilmaril@721: { insilmaril@721: BranchObj *dst=(BranchObj*)findObjBySelect(dstString); insilmaril@721: if (dst && (typeid(*dst)==typeid (BranchObj) || insilmaril@721: typeid(*dst)==typeid (MapCenterObj))) insilmaril@721: { insilmaril@721: LinkableMapObj *dstPar=dst->getParObj(); insilmaril@721: QString parString=getSelectString(dstPar); insilmaril@721: QString fioPreSelectString=getSelectString(fio); insilmaril@721: QString fioPreParentSelectString=getSelectString (fio->getParObj()); insilmaril@721: ((BranchObj*)dst)->addFloatImage (fio); insilmaril@721: selection.unselect(); insilmaril@721: ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio); insilmaril@721: fio=((BranchObj*)dst)->getLastFloatImage(); insilmaril@721: fio->setRelPos(); insilmaril@721: fio->reposition(); insilmaril@721: selection.select(fio); insilmaril@721: saveState( insilmaril@721: getSelectString(fio), insilmaril@721: QString("linkTo (\"%1\")").arg(fioPreParentSelectString), insilmaril@721: fioPreSelectString, insilmaril@721: QString ("linkTo (\"%1\")").arg(dstString), insilmaril@721: QString ("Link floatimage to %1").arg(getObjectName(dst))); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::setFrameType(const FrameObj::FrameType &t) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QString s=bo->getFrameTypeName(); insilmaril@721: bo->setFrameType (t); insilmaril@721: saveState (bo, QString("setFrameType (\"%1\")").arg(s), insilmaril@721: bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s)); insilmaril@721: reposition(); insilmaril@721: bo->updateLink(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setFrameType(const QString &s) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()), insilmaril@721: bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s)); insilmaril@721: bo->setFrameType (s); insilmaril@721: reposition(); insilmaril@721: bo->updateLink(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setFramePenColor(const QColor &c) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ), insilmaril@721: bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() )); insilmaril@721: bo->setFramePenColor (c); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setFrameBrushColor(const QColor &c) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ), insilmaril@721: bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() )); insilmaril@721: bo->setFrameBrushColor (c); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setFramePadding (const int &i) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ), insilmaril@721: bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i)); insilmaril@721: bo->setFramePadding (i); insilmaril@721: reposition(); insilmaril@721: bo->updateLink(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setFrameBorderWidth(const int &i) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ), insilmaril@721: bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i)); insilmaril@721: bo->setFrameBorderWidth (i); insilmaril@721: reposition(); insilmaril@721: bo->updateLink(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setIncludeImagesVer(bool b) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QString u= b ? "false" : "true"; insilmaril@721: QString r=!b ? "false" : "true"; insilmaril@721: insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: QString("setIncludeImagesVertically (%1)").arg(u), insilmaril@721: bo, insilmaril@721: QString("setIncludeImagesVertically (%1)").arg(r), insilmaril@721: QString("Include images vertically in %1").arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: bo->setIncludeImagesVer(b); insilmaril@721: reposition(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setIncludeImagesHor(bool b) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QString u= b ? "false" : "true"; insilmaril@721: QString r=!b ? "false" : "true"; insilmaril@721: insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: QString("setIncludeImagesHorizontally (%1)").arg(u), insilmaril@721: bo, insilmaril@721: QString("setIncludeImagesHorizontally (%1)").arg(r), insilmaril@721: QString("Include images horizontally in %1").arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: bo->setIncludeImagesHor(b); insilmaril@721: reposition(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setHideLinkUnselected (bool b) insilmaril@721: { insilmaril@735: LinkableMapObj *sel=getSelectedLMO(); insilmaril@721: if (sel && insilmaril@735: (selectionType() == TreeItem::Branch || insilmaril@735: selectionType() == TreeItem::MapCenter || insilmaril@735: selectionType() == TreeItem::Image )) insilmaril@721: { insilmaril@721: QString u= b ? "false" : "true"; insilmaril@721: QString r=!b ? "false" : "true"; insilmaril@721: insilmaril@721: saveState( insilmaril@721: sel, insilmaril@721: QString("setHideLinkUnselected (%1)").arg(u), insilmaril@721: sel, insilmaril@721: QString("setHideLinkUnselected (%1)").arg(r), insilmaril@721: QString("Hide link of %1 if unselected").arg(getObjectName(sel)) insilmaril@721: ); insilmaril@721: sel->setHideLinkUnselected(b); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setHideExport(bool b) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bo->setHideInExport (b); insilmaril@721: QString u= b ? "false" : "true"; insilmaril@721: QString r=!b ? "false" : "true"; insilmaril@721: insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: QString ("setHideExport (%1)").arg(u), insilmaril@721: bo, insilmaril@721: QString ("setHideExport (%1)").arg(r), insilmaril@721: QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bo)).arg (r) insilmaril@721: ); insilmaril@721: updateActions(); insilmaril@721: reposition(); insilmaril@721: selection.update(); insilmaril@727: // FIXME VM needed? scene()->update(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::toggleHideExport() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: setHideExport ( !bo->hideInExport() ); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::copy() insilmaril@721: { insilmaril@735: LinkableMapObj *sel=getSelectedLMO(); insilmaril@735: if (sel && insilmaril@735: (selectionType() == TreeItem::Branch || insilmaril@735: selectionType() == TreeItem::MapCenter || insilmaril@735: selectionType() == TreeItem::Image )) insilmaril@721: { insilmaril@721: if (redosAvail == 0) insilmaril@721: { insilmaril@721: // Copy to history insilmaril@721: QString s=getSelectString(sel); insilmaril@721: saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel ); insilmaril@721: curClipboard=curStep; insilmaril@721: } insilmaril@721: insilmaril@721: // Copy also to global clipboard, because we are at last step in history insilmaril@721: QString bakMapName(QString("history-%1").arg(curStep)); insilmaril@721: QString bakMapDir(tmpMapDir +"/"+bakMapName); insilmaril@721: copyDir (bakMapDir,clipboardDir ); insilmaril@721: insilmaril@721: clipboardEmpty=false; insilmaril@721: updateActions(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::pasteNoSave(const int &n) insilmaril@721: { insilmaril@721: bool old=blockSaveState; insilmaril@721: blockSaveState=true; insilmaril@721: bool zippedOrg=zipped; insilmaril@721: if (redosAvail > 0 || n!=0) insilmaril@721: { insilmaril@721: // Use the "historical" buffer insilmaril@721: QString bakMapName(QString("history-%1").arg(n)); insilmaril@721: QString bakMapDir(tmpMapDir +"/"+bakMapName); insilmaril@721: load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap); insilmaril@721: } else insilmaril@721: // Use the global buffer insilmaril@721: load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap); insilmaril@721: zipped=zippedOrg; insilmaril@721: blockSaveState=old; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::paste() insilmaril@721: { insilmaril@735: BranchObj *sel=getSelectedBranch(); insilmaril@721: if (sel) insilmaril@721: { insilmaril@721: saveStateChangingPart( insilmaril@721: sel, insilmaril@721: sel, insilmaril@721: QString ("paste (%1)").arg(curClipboard), insilmaril@721: QString("Paste to %1").arg( getObjectName(sel)) insilmaril@721: ); insilmaril@721: pasteNoSave(0); insilmaril@721: reposition(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::cut() insilmaril@721: { insilmaril@735: LinkableMapObj *sel=getSelectedLMO(); insilmaril@735: if ( sel && (selectionType() == TreeItem::Branch || insilmaril@735: selectionType()==TreeItem::MapCenter || insilmaril@735: selectionType()==TreeItem::Image)) insilmaril@721: { insilmaril@721: /* No savestate! savestate is called in cutNoSave insilmaril@721: saveStateChangingPart( insilmaril@721: sel->getParObj(), insilmaril@721: sel, insilmaril@721: "cut ()", insilmaril@721: QString("Cut %1").arg(getObjectName(sel )) insilmaril@721: ); insilmaril@721: */ insilmaril@721: copy(); insilmaril@721: deleteSelection(); insilmaril@721: reposition(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::moveBranchUp() insilmaril@721: { insilmaril@735: BranchObj* bo=getSelectedBranch(); insilmaril@721: BranchObj* par; insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: if (!bo->canMoveBranchUp()) return; insilmaril@721: par=(BranchObj*)(bo->getParObj()); insilmaril@721: BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection insilmaril@721: saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo))); insilmaril@721: reposition(); insilmaril@727: //FIXME VM needed? scene()->update(); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::moveBranchDown() insilmaril@721: { insilmaril@735: BranchObj* bo=getSelectedBranch(); insilmaril@721: BranchObj* par; insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: if (!bo->canMoveBranchDown()) return; insilmaril@721: par=(BranchObj*)(bo->getParObj()); insilmaril@721: BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection insilmaril@721: saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo))); insilmaril@721: reposition(); insilmaril@727: //FIXME VM needed? scene()->update(); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::sortChildren() insilmaril@721: { insilmaril@735: BranchObj* bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: if(bo->countBranches()>1) insilmaril@721: { insilmaril@721: saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo))); insilmaril@721: bo->sortChildren(); insilmaril@721: reposition(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@726: void VymModel::createMapCenter() insilmaril@726: { insilmaril@726: MapCenterObj *mco=addMapCenter (QPointF (0,0) ); insilmaril@735: select (mco); insilmaril@726: } insilmaril@726: insilmaril@726: void VymModel::createBranch() insilmaril@726: { insilmaril@739: addNewBranchInt (-2); insilmaril@739: return; insilmaril@739: } insilmaril@739: insilmaril@739: TreeItem* VymModel::createImage() insilmaril@739: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@726: if (bo) insilmaril@726: { insilmaril@739: FloatImageObj *newfio=bo->addFloatImage(); // FIXME VM Old model, merge with below insilmaril@726: insilmaril@726: // Create TreeItem insilmaril@726: QList cData; insilmaril@739: cData << "VM:createImage" << "undef"<<"undef"; insilmaril@726: TreeItem *parti=bo->getTreeItem(); insilmaril@726: TreeItem *ti=new TreeItem (cData,parti); insilmaril@739: ti->setLMO (newfio); insilmaril@739: ti->setType (TreeItem::Image); insilmaril@726: parti->appendChild (ti); insilmaril@726: insilmaril@739: if (newfio) insilmaril@726: { insilmaril@739: newfio->setTreeItem (ti); insilmaril@739: select (newfio); // FIXME VM really needed here? insilmaril@739: return ti; insilmaril@726: } insilmaril@726: } insilmaril@739: return NULL; insilmaril@726: } insilmaril@726: insilmaril@721: MapCenterObj* VymModel::addMapCenter () insilmaril@721: { insilmaril@723: MapCenterObj *mco=addMapCenter (contextPos); insilmaril@728: cout <<"VM::addMCO () mapScene="<setMapEditor(mapEditor); //FIXME VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects insilmaril@721: mapCenter->move (absPos); insilmaril@721: mapCenter->setVisibility (true); insilmaril@721: mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); insilmaril@721: mapCenters.append(mapCenter); insilmaril@726: insilmaril@726: // Create TreeItem insilmaril@726: QList cData; insilmaril@726: cData << "VM:addMapCenter" << "undef"<<"undef"; insilmaril@726: TreeItem *ti=new TreeItem (cData,rootItem); insilmaril@726: ti->setLMO (mapCenter); insilmaril@726: ti->setType (TreeItem::MapCenter); insilmaril@726: mapCenter->setTreeItem (ti); insilmaril@726: rootItem->appendChild (ti); insilmaril@726: insilmaril@721: return mapCenter; insilmaril@721: } insilmaril@721: insilmaril@723: MapCenterObj* VymModel::removeMapCenter(MapCenterObj* mco) insilmaril@721: { insilmaril@721: int i=mapCenters.indexOf (mco); insilmaril@721: if (i>=0) insilmaril@721: { insilmaril@721: mapCenters.removeAt (i); insilmaril@721: delete (mco); insilmaril@721: if (i>0) return mapCenters.at(i-1); // Return previous MCO insilmaril@721: } insilmaril@721: return NULL; insilmaril@721: } insilmaril@721: insilmaril@723: MapCenterObj* VymModel::getLastMapCenter() insilmaril@723: { insilmaril@723: if (mapCenters.size()>0) insilmaril@723: return mapCenters.last(); insilmaril@723: else insilmaril@723: return NULL; insilmaril@723: insilmaril@723: } insilmaril@723: insilmaril@721: insilmaril@721: BranchObj* VymModel::addNewBranchInt(int num) insilmaril@721: { insilmaril@721: // Depending on pos: insilmaril@721: // -3 insert in children of parent above selection insilmaril@721: // -2 add branch to selection insilmaril@721: // -1 insert in children of parent below selection insilmaril@721: // 0..n insert in children of parent at pos insilmaril@721: BranchObj *newbo=NULL; insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: if (num==-2) insilmaril@721: { insilmaril@721: // save scroll state. If scrolled, automatically select insilmaril@721: // new branch in order to tmp unscroll parent... insilmaril@721: newbo=bo->addBranch(); insilmaril@739: insilmaril@739: // Create TreeItem insilmaril@739: QList cData; insilmaril@739: cData << "VM:createBranch" << "undef"<<"undef"; insilmaril@739: TreeItem *parti=bo->getTreeItem(); insilmaril@739: TreeItem *ti=new TreeItem (cData,parti); insilmaril@739: ti->setLMO (newbo); insilmaril@739: ti->setType (TreeItem::Branch); insilmaril@739: parti->appendChild (ti); insilmaril@739: insilmaril@739: if (newbo) insilmaril@739: { insilmaril@739: newbo->setTreeItem (ti); insilmaril@739: select (newbo); // FIXME VM really needed here? insilmaril@739: } insilmaril@721: insilmaril@721: }else if (num==-1) insilmaril@721: { insilmaril@721: num=bo->getNum()+1; insilmaril@721: bo=(BranchObj*)bo->getParObj(); insilmaril@721: if (bo) newbo=bo->insertBranch(num); insilmaril@721: }else if (num==-3) insilmaril@721: { insilmaril@721: num=bo->getNum(); insilmaril@721: bo=(BranchObj*)bo->getParObj(); insilmaril@721: if (bo) newbo=bo->insertBranch(num); insilmaril@721: } insilmaril@721: } insilmaril@721: return newbo; insilmaril@721: } insilmaril@721: insilmaril@721: BranchObj* VymModel::addNewBranch(int pos) insilmaril@721: { insilmaril@721: // Different meaning than num in addNewBranchInt! insilmaril@721: // -1 add above insilmaril@721: // 0 add as child insilmaril@721: // +1 add below insilmaril@735: BranchObj *bo = getSelectedBranch(); insilmaril@721: BranchObj *newbo=NULL; insilmaril@721: insilmaril@721: if (bo) insilmaril@721: { insilmaril@727: // FIXME VM do we still need this in model? setCursor (Qt::ArrowCursor); insilmaril@721: insilmaril@721: newbo=addNewBranchInt (pos-2); insilmaril@721: insilmaril@721: if (newbo) insilmaril@721: { insilmaril@721: saveState( insilmaril@721: newbo, insilmaril@721: "delete ()", insilmaril@721: bo, insilmaril@721: QString ("addBranch (%1)").arg(pos), insilmaril@721: QString ("Add new branch to %1").arg(getObjectName(bo))); insilmaril@721: insilmaril@721: reposition(); insilmaril@739: // selection.update(); FIXME insilmaril@721: latestSelectionString=getSelectString(newbo); insilmaril@721: // In Network mode, the client needs to know where the new branch is, insilmaril@721: // so we have to pass on this information via saveState. insilmaril@721: // TODO: Get rid of this positioning workaround insilmaril@721: QString ps=qpointfToString (newbo->getAbsPos()); insilmaril@721: sendData ("selectLatestAdded ()"); insilmaril@721: sendData (QString("move %1").arg(ps)); insilmaril@721: sendSelection(); insilmaril@721: } insilmaril@721: } insilmaril@721: return newbo; insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: BranchObj* VymModel::addNewBranchBefore() insilmaril@721: { insilmaril@721: BranchObj *newbo=NULL; insilmaril@735: BranchObj *bo = getSelectedBranch(); insilmaril@735: if (bo && selectionType()==TreeItem::Branch) insilmaril@721: // We accept no MapCenterObj here, so we _have_ a parent insilmaril@721: { insilmaril@721: QPointF p=bo->getRelPos(); insilmaril@721: insilmaril@721: insilmaril@721: BranchObj *parbo=(BranchObj*)(bo->getParObj()); insilmaril@721: insilmaril@721: // add below selection insilmaril@721: newbo=parbo->insertBranch(bo->getNum()+1); insilmaril@721: if (newbo) insilmaril@721: { insilmaril@721: newbo->move2RelPos (p); insilmaril@721: insilmaril@721: // Move selection to new branch insilmaril@721: bo->linkTo (newbo,-1); insilmaril@721: insilmaril@721: saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()", insilmaril@721: QString ("Add branch before %1").arg(getObjectName(bo))); insilmaril@721: insilmaril@721: reposition(); insilmaril@739: // selection.update(); FIXME insilmaril@721: } insilmaril@721: } insilmaril@721: latestSelectionString=selection.getSelectString(); insilmaril@721: return newbo; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::deleteSelection() insilmaril@721: { insilmaril@735: BranchObj *bo = getSelectedBranch(); insilmaril@728: insilmaril@735: if (bo && selectionType()==TreeItem::MapCenter) insilmaril@721: { insilmaril@721: // BranchObj* par=(BranchObj*)(bo->getParObj()); insilmaril@721: selection.unselect(); insilmaril@727: /* FIXME VM Note: does saveStateRemovingPart work for MCO? (No parent!) insilmaril@721: saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo))); insilmaril@721: */ insilmaril@721: bo=removeMapCenter ((MapCenterObj*)bo); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: selection.select (bo); insilmaril@721: ensureSelectionVisible(); insilmaril@721: selection.update(); insilmaril@721: } insilmaril@721: reposition(); insilmaril@721: return; insilmaril@721: } insilmaril@735: if (bo && selectionType()==TreeItem::Branch) insilmaril@721: { insilmaril@735: QModelIndex ix=getSelectedIndex(); insilmaril@722: insilmaril@721: BranchObj* par=(BranchObj*)bo->getParObj(); insilmaril@735: unselect(); insilmaril@721: saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo))); insilmaril@721: par->removeBranch(bo); insilmaril@735: select (par); insilmaril@721: ensureSelectionVisible(); insilmaril@721: reposition(); insilmaril@721: selection.update(); insilmaril@721: return; insilmaril@721: } insilmaril@721: FloatImageObj *fio=selection.getFloatImage(); insilmaril@721: if (fio) insilmaril@721: { insilmaril@721: BranchObj* par=(BranchObj*)fio->getParObj(); insilmaril@721: saveStateChangingPart( insilmaril@721: par, insilmaril@721: fio, insilmaril@721: "delete ()", insilmaril@721: QString("Delete %1").arg(getObjectName(fio)) insilmaril@721: ); insilmaril@735: unselect(); insilmaril@721: par->removeFloatImage(fio); insilmaril@735: select (par); insilmaril@721: reposition(); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: return; insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::deleteKeepChildren() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: BranchObj *par; insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: par=(BranchObj*)(bo->getParObj()); insilmaril@726: insilmaril@726: // Don't use this on mapcenter insilmaril@726: if (!par) return; insilmaril@726: insilmaril@726: // Check if we have childs at all to keep insilmaril@726: if (bo->countBranches()==0) insilmaril@726: { insilmaril@726: deleteSelection(); insilmaril@726: return; insilmaril@726: } insilmaril@726: insilmaril@721: QPointF p=bo->getRelPos(); insilmaril@721: saveStateChangingPart( insilmaril@721: bo->getParObj(), insilmaril@721: bo, insilmaril@721: "deleteKeepChildren ()", insilmaril@721: QString("Remove %1 and keep its children").arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: insilmaril@721: QString sel=getSelectString(bo); insilmaril@721: unselect(); insilmaril@721: par->removeBranchHere(bo); insilmaril@721: reposition(); insilmaril@721: select (sel); insilmaril@735: getSelectedBranch()->move2RelPos (p); insilmaril@721: reposition(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::deleteChildren() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveStateChangingPart( insilmaril@721: bo, insilmaril@721: bo, insilmaril@721: "deleteChildren ()", insilmaril@721: QString( "Remove children of branch %1").arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: bo->removeChildren(); insilmaril@721: reposition(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: bool VymModel::scrollBranch(BranchObj *bo) insilmaril@721: { insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: if (bo->isScrolled()) return false; insilmaril@721: if (bo->countBranches()==0) return false; insilmaril@721: if (bo->getDepth()==0) return false; insilmaril@721: QString u,r; insilmaril@721: r="scroll"; insilmaril@721: u="unscroll"; insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: QString ("%1 ()").arg(u), insilmaril@721: bo, insilmaril@721: QString ("%1 ()").arg(r), insilmaril@721: QString ("%1 %2").arg(r).arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: bo->toggleScroll(); insilmaril@721: selection.update(); insilmaril@727: // FIXME VM needed? scene()->update(); insilmaril@721: return true; insilmaril@721: } insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@721: bool VymModel::unscrollBranch(BranchObj *bo) insilmaril@721: { insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: if (!bo->isScrolled()) return false; insilmaril@721: if (bo->countBranches()==0) return false; insilmaril@721: if (bo->getDepth()==0) return false; insilmaril@721: QString u,r; insilmaril@721: u="scroll"; insilmaril@721: r="unscroll"; insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: QString ("%1 ()").arg(u), insilmaril@721: bo, insilmaril@721: QString ("%1 ()").arg(r), insilmaril@721: QString ("%1 %2").arg(r).arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: bo->toggleScroll(); insilmaril@721: selection.update(); insilmaril@727: // FIXME VM needed? scene()->update(); insilmaril@721: return true; insilmaril@721: } insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::toggleScroll() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@735: if (selectionType()==TreeItem::Branch ) insilmaril@721: { insilmaril@721: if (bo->isScrolled()) insilmaril@721: unscrollBranch (bo); insilmaril@721: else insilmaril@721: scrollBranch (bo); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::unscrollChildren() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bo->first(); insilmaril@721: while (bo) insilmaril@721: { insilmaril@721: if (bo->isScrolled()) unscrollBranch (bo); insilmaril@721: bo=bo->next(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: void VymModel::addFloatImage (const QPixmap &img) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: FloatImageObj *fio=bo->addFloatImage(); insilmaril@721: fio->load(img); insilmaril@721: fio->setOriginalFilename("No original filename (image added by dropevent)"); insilmaril@721: QString s=getSelectString(bo); insilmaril@721: saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio ); insilmaril@721: saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image"); insilmaril@721: reposition(); insilmaril@727: // FIXME VM needed? scene()->update(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::colorBranch (QColor c) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: QString ("colorBranch (\"%1\")").arg(bo->getColor().name()), insilmaril@721: bo, insilmaril@721: QString ("colorBranch (\"%1\")").arg(c.name()), insilmaril@721: QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name()) insilmaril@721: ); insilmaril@721: bo->setColor(c); // color branch insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::colorSubtree (QColor c) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveStateChangingPart( insilmaril@721: bo, insilmaril@721: bo, insilmaril@721: QString ("colorSubtree (\"%1\")").arg(c.name()), insilmaril@721: QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name()) insilmaril@721: ); insilmaril@721: bo->setColorSubtree (c); // color links, color children insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: QColor VymModel::getCurrentHeadingColor() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) return bo->getColor(); insilmaril@721: insilmaril@721: QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected"); insilmaril@721: return Qt::black; insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::editURL() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bool ok; insilmaril@721: QString text = QInputDialog::getText( insilmaril@721: "VYM", tr("Enter URL:"), QLineEdit::Normal, insilmaril@721: bo->getURL(), &ok, NULL); insilmaril@721: if ( ok) insilmaril@721: // user entered something and pressed OK insilmaril@721: setURL(text); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::editLocalURL() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QStringList filters; insilmaril@721: filters <<"All files (*)"; insilmaril@721: filters << tr("Text","Filedialog") + " (*.txt)"; insilmaril@721: filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)"; insilmaril@721: filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)"; insilmaril@721: filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"; insilmaril@721: QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file")); insilmaril@721: fd->setFilters (filters); insilmaril@721: fd->setCaption(vymName+" - " +tr("Set URL to a local file")); insilmaril@721: fd->setDirectory (lastFileDir); insilmaril@721: if (! bo->getVymLink().isEmpty() ) insilmaril@721: fd->selectFile( bo->getURL() ); insilmaril@721: fd->show(); insilmaril@721: insilmaril@721: if ( fd->exec() == QDialog::Accepted ) insilmaril@721: { insilmaril@721: lastFileDir=QDir (fd->directory().path()); insilmaril@721: setURL (fd->selectedFile() ); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::editHeading2URL() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: setURL (bo->getHeading()); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::editBugzilla2URL() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading(); insilmaril@721: setURL (url); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::editFATE2URL() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading(); insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: "setURL (\""+bo->getURL()+"\")", insilmaril@721: bo, insilmaril@721: "setURL (\""+url+"\")", insilmaril@721: QString("Use heading of %1 as link to FATE").arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: bo->setURL (url); insilmaril@721: updateActions(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::editVymLink() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QStringList filters; insilmaril@721: filters <<"VYM map (*.vym)"; insilmaril@721: QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map")); insilmaril@721: fd->setFilters (filters); insilmaril@721: fd->setCaption(vymName+" - " +tr("Link to another map")); insilmaril@721: fd->setDirectory (lastFileDir); insilmaril@721: if (! bo->getVymLink().isEmpty() ) insilmaril@721: fd->selectFile( bo->getVymLink() ); insilmaril@721: fd->show(); insilmaril@721: insilmaril@721: QString fn; insilmaril@721: if ( fd->exec() == QDialog::Accepted ) insilmaril@721: { insilmaril@721: lastFileDir=QDir (fd->directory().path()); insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: "setVymLink (\""+bo->getVymLink()+"\")", insilmaril@721: bo, insilmaril@721: "setVymLink (\""+fd->selectedFile()+"\")", insilmaril@721: QString("Set vymlink of %1 to %2").arg(getObjectName(bo)).arg(fd->selectedFile()) insilmaril@721: ); insilmaril@721: setVymLink (fd->selectedFile() ); // FIXME ok? insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setVymLink (const QString &s) insilmaril@721: { insilmaril@721: // Internal function, no saveState needed insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bo->setVymLink(s); insilmaril@721: reposition(); insilmaril@721: updateActions(); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::deleteVymLink() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: "setVymLink (\""+bo->getVymLink()+"\")", insilmaril@721: bo, insilmaril@721: "setVymLink (\"\")", insilmaril@721: QString("Unset vymlink of %1").arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: bo->setVymLink ("" ); insilmaril@721: updateActions(); insilmaril@721: reposition(); insilmaril@727: // FIXME VM needed? scene()->update(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: QString VymModel::getVymLink() insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: return bo->getVymLink(); insilmaril@721: else insilmaril@721: return ""; insilmaril@721: insilmaril@721: } insilmaril@721: insilmaril@721: QStringList VymModel::getVymLinks() insilmaril@721: { insilmaril@721: QStringList links; insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bo=bo->first(); insilmaril@721: while (bo) insilmaril@721: { insilmaril@721: if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink()); insilmaril@721: bo=bo->next(); insilmaril@721: } insilmaril@721: } insilmaril@721: return links; insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::followXLink(int i) insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bo=bo->XLinkTargetAt(i); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: selection.select(bo); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@727: void VymModel::editXLink(int i) // FIXME VM missing saveState insilmaril@721: { insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: XLinkObj *xlo=bo->XLinkAt(i); insilmaril@721: if (xlo) insilmaril@721: { insilmaril@721: EditXLinkDialog dia; insilmaril@721: dia.setXLink (xlo); insilmaril@721: dia.setSelection(bo); insilmaril@721: if (dia.exec() == QDialog::Accepted) insilmaril@721: { insilmaril@721: if (dia.useSettingsGlobal() ) insilmaril@721: { insilmaril@721: setMapDefXLinkColor (xlo->getColor() ); insilmaril@721: setMapDefXLinkWidth (xlo->getWidth() ); insilmaril@721: } insilmaril@721: if (dia.deleteXLink()) insilmaril@721: bo->deleteXLinkAt(i); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: ////////////////////////////////////////////// insilmaril@721: // Scripting insilmaril@721: ////////////////////////////////////////////// insilmaril@721: insilmaril@721: void VymModel::parseAtom(const QString &atom) insilmaril@721: { insilmaril@735: BranchObj *selb=getSelectedBranch(); insilmaril@721: QString s,t; insilmaril@721: double x,y; insilmaril@721: int n; insilmaril@721: bool b,ok; insilmaril@721: insilmaril@721: // Split string s into command and parameters insilmaril@721: parser.parseAtom (atom); insilmaril@721: QString com=parser.getCommand(); insilmaril@721: insilmaril@721: // External commands insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: if (com=="addBranch") insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else insilmaril@721: { insilmaril@721: QList pl; insilmaril@721: pl << 0 <<1; insilmaril@721: if (parser.checkParCount(pl)) insilmaril@721: { insilmaril@721: if (parser.parCount()==0) insilmaril@721: addNewBranch (0); insilmaril@721: else insilmaril@721: { insilmaril@721: n=parser.parInt (ok,0); insilmaril@721: if (ok ) addNewBranch (n); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="addBranchBefore") insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else insilmaril@721: { insilmaril@721: if (parser.parCount()==0) insilmaril@721: { insilmaril@721: addNewBranchBefore (); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com==QString("addMapCenter")) insilmaril@721: { insilmaril@721: if (parser.checkParCount(2)) insilmaril@721: { insilmaril@721: x=parser.parDouble (ok,0); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: y=parser.parDouble (ok,1); insilmaril@721: if (ok) addMapCenter (QPointF(x,y)); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com==QString("addMapReplace")) insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: //s=parser.parString (ok,0); // selection insilmaril@721: t=parser.parString (ok,0); // path to map insilmaril@721: if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); insilmaril@721: addMapReplaceInt(getSelectString(selb),t); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com==QString("addMapInsert")) insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else insilmaril@721: { insilmaril@721: if (parser.checkParCount(2)) insilmaril@721: { insilmaril@721: t=parser.parString (ok,0); // path to map insilmaril@721: n=parser.parInt(ok,1); // position insilmaril@721: if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); insilmaril@721: addMapInsertInt(t,n); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="clearFlags") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: selb->clearStandardFlags(); insilmaril@721: selb->updateFlagsToolbar(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="colorBranch") insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: QColor c=parser.parColor (ok,0); insilmaril@721: if (ok) colorBranch (c); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="colorSubtree") insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: QColor c=parser.parColor (ok,0); insilmaril@721: if (ok) colorSubtree (c); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="copy") insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: //FIXME missing action for copy insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="cut") insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@735: } else if ( selectionType()!=TreeItem::Branch && insilmaril@735: selectionType()!=TreeItem::MapCenter && insilmaril@735: selectionType()!=TreeItem::Image ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: cut(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="delete") insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } insilmaril@735: /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is wrong."); insilmaril@721: } insilmaril@721: */ insilmaril@721: else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: deleteSelection(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="deleteKeepChildren") insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: deleteKeepChildren(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="deleteChildren") insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: deleteChildren(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="exportASCII") insilmaril@721: { insilmaril@721: QString fname=""; insilmaril@721: ok=true; insilmaril@721: if (parser.parCount()>=1) insilmaril@721: // Hey, we even have a filename insilmaril@721: fname=parser.parString(ok,0); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Could not read filename"); insilmaril@721: } else insilmaril@721: { insilmaril@721: exportASCII (fname,false); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="exportImage") insilmaril@721: { insilmaril@721: QString fname=""; insilmaril@721: ok=true; insilmaril@721: if (parser.parCount()>=2) insilmaril@721: // Hey, we even have a filename insilmaril@721: fname=parser.parString(ok,0); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Could not read filename"); insilmaril@721: } else insilmaril@721: { insilmaril@721: QString format="PNG"; insilmaril@721: if (parser.parCount()>=2) insilmaril@721: { insilmaril@721: format=parser.parString(ok,1); insilmaril@721: } insilmaril@721: exportImage (fname,false,format); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="exportXHTML") insilmaril@721: { insilmaril@721: QString fname=""; insilmaril@721: ok=true; insilmaril@721: if (parser.parCount()>=2) insilmaril@721: // Hey, we even have a filename insilmaril@721: fname=parser.parString(ok,1); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Could not read filename"); insilmaril@721: } else insilmaril@721: { insilmaril@721: exportXHTML (fname,false); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="exportXML") insilmaril@721: { insilmaril@721: QString fname=""; insilmaril@721: ok=true; insilmaril@721: if (parser.parCount()>=2) insilmaril@721: // Hey, we even have a filename insilmaril@721: fname=parser.parString(ok,1); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Could not read filename"); insilmaril@721: } else insilmaril@721: { insilmaril@721: exportXML (fname,false); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="importDir") insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) importDirInt(s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="linkTo") insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if ( selb) insilmaril@721: { insilmaril@721: if (parser.checkParCount(4)) insilmaril@721: { insilmaril@721: // 0 selectstring of parent insilmaril@721: // 1 num in parent (for branches) insilmaril@721: // 2,3 x,y of mainbranch or mapcenter insilmaril@721: s=parser.parString(ok,0); insilmaril@721: LinkableMapObj *dst=findObjBySelect (s); insilmaril@721: if (dst) insilmaril@721: { insilmaril@721: if (typeid(*dst) == typeid(BranchObj) ) insilmaril@721: { insilmaril@721: // Get number in parent insilmaril@721: n=parser.parInt (ok,1); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: selb->linkTo ((BranchObj*)(dst),n); insilmaril@721: selection.update(); insilmaril@721: } insilmaril@721: } else if (typeid(*dst) == typeid(MapCenterObj) ) insilmaril@721: { insilmaril@721: selb->linkTo ((BranchObj*)(dst),-1); insilmaril@721: // Get coordinates of mainbranch insilmaril@721: x=parser.parDouble(ok,2); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: y=parser.parDouble(ok,3); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: selb->move (x,y); insilmaril@721: selection.update(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@735: } else if ( selectionType() == TreeItem::Image) insilmaril@721: { insilmaril@721: if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: // 0 selectstring of parent insilmaril@721: s=parser.parString(ok,0); insilmaril@721: LinkableMapObj *dst=findObjBySelect (s); insilmaril@721: if (dst) insilmaril@721: { insilmaril@721: if (typeid(*dst) == typeid(BranchObj) || insilmaril@721: typeid(*dst) == typeid(MapCenterObj)) insilmaril@721: linkFloatImageTo (getSelectString(dst)); insilmaril@721: } else insilmaril@721: parser.setError (Aborted,"Destination is not a branch"); insilmaril@721: } insilmaril@721: } else insilmaril@721: parser.setError (Aborted,"Type of selection is not a floatimage or branch"); insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="loadImage") insilmaril@721: { insilmaril@721: if (selection.isEmpty()) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) loadFloatImageInt (s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="moveBranchUp") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: moveBranchUp(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="moveBranchDown") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: moveBranchDown(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="move") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@735: } else if ( selectionType()!=TreeItem::Branch && insilmaril@735: selectionType()!=TreeItem::MapCenter && insilmaril@735: selectionType()!=TreeItem::Image ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@721: } else if (parser.checkParCount(2)) insilmaril@721: { insilmaril@721: x=parser.parDouble (ok,0); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: y=parser.parDouble (ok,1); insilmaril@721: if (ok) move (x,y); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="moveRel") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@735: } else if ( selectionType()!=TreeItem::Branch && insilmaril@735: selectionType()!=TreeItem::MapCenter && insilmaril@735: selectionType()!=TreeItem::Image ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@721: } else if (parser.checkParCount(2)) insilmaril@721: { insilmaril@721: x=parser.parDouble (ok,0); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: y=parser.parDouble (ok,1); insilmaril@721: if (ok) moveRel (x,y); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="nop") insilmaril@721: { insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="paste") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: n=parser.parInt (ok,0); insilmaril@721: if (ok) pasteNoSave(n); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="qa") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(4)) insilmaril@721: { insilmaril@721: QString c,u; insilmaril@721: c=parser.parString (ok,0); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"No comment given"); insilmaril@721: } else insilmaril@721: { insilmaril@721: s=parser.parString (ok,1); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"First parameter is not a string"); insilmaril@721: } else insilmaril@721: { insilmaril@721: t=parser.parString (ok,2); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Condition is not a string"); insilmaril@721: } else insilmaril@721: { insilmaril@721: u=parser.parString (ok,3); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Third parameter is not a string"); insilmaril@721: } else insilmaril@721: { insilmaril@721: if (s!="heading") insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Unknown type: "+s); insilmaril@721: } else insilmaril@721: { insilmaril@721: if (! (t=="eq") ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Unknown operator: "+t); insilmaril@721: } else insilmaril@721: { insilmaril@721: if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else insilmaril@721: { insilmaril@721: if (selb->getHeading() == u) insilmaril@721: { insilmaril@721: cout << "PASSED: " << qPrintable (c) << endl; insilmaril@721: } else insilmaril@721: { insilmaril@721: cout << "FAILED: " << qPrintable (c) << endl; insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="saveImage") insilmaril@721: { insilmaril@721: FloatImageObj *fio=selection.getFloatImage(); insilmaril@721: if (!fio) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not an image"); insilmaril@721: } else if (parser.checkParCount(2)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: t=parser.parString(ok,1); insilmaril@721: if (ok) saveFloatImageInt (fio,t,s); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="scroll") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: if (!scrollBranch (selb)) insilmaril@721: parser.setError (Aborted,"Could not scroll branch"); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="select") insilmaril@721: { insilmaril@721: if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) select (s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="selectLastBranch") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: BranchObj *bo=selb->getLastBranch(); insilmaril@721: if (!bo) insilmaril@721: parser.setError (Aborted,"Could not select last branch"); insilmaril@721: selectInt (bo); insilmaril@721: insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="selectLastImage") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: FloatImageObj *fio=selb->getLastFloatImage(); insilmaril@721: if (!fio) insilmaril@721: parser.setError (Aborted,"Could not select last image"); insilmaril@721: selectInt (fio); insilmaril@721: insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="selectLatestAdded") insilmaril@721: { insilmaril@721: if (latestSelectionString.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"No latest added object"); insilmaril@721: } else insilmaril@721: { insilmaril@721: if (!select (latestSelectionString)) insilmaril@721: parser.setError (Aborted,"Could not select latest added object "+latestSelectionString); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setFrameType") insilmaril@721: { insilmaril@735: if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection does not allow setting frame type"); insilmaril@721: } insilmaril@721: else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) setFrameType (s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setFramePenColor") insilmaril@721: { insilmaril@735: if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection does not allow setting of pen color"); insilmaril@721: } insilmaril@721: else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: QColor c=parser.parColor(ok,0); insilmaril@721: if (ok) setFramePenColor (c); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setFrameBrushColor") insilmaril@721: { insilmaril@735: if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection does not allow setting brush color"); insilmaril@721: } insilmaril@721: else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: QColor c=parser.parColor(ok,0); insilmaril@721: if (ok) setFrameBrushColor (c); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setFramePadding") insilmaril@721: { insilmaril@735: if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection does not allow setting frame padding"); insilmaril@721: } insilmaril@721: else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: n=parser.parInt(ok,0); insilmaril@721: if (ok) setFramePadding(n); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setFrameBorderWidth") insilmaril@721: { insilmaril@735: if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection does not allow setting frame border width"); insilmaril@721: } insilmaril@721: else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: n=parser.parInt(ok,0); insilmaril@721: if (ok) setFrameBorderWidth (n); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setMapAuthor") insilmaril@721: { insilmaril@721: if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) setAuthor (s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setMapComment") insilmaril@721: { insilmaril@721: if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) setComment(s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setMapBackgroundColor") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@735: } else if (! getSelectedBranch() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: QColor c=parser.parColor (ok,0); insilmaril@721: if (ok) setMapBackgroundColor (c); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setMapDefLinkColor") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: QColor c=parser.parColor (ok,0); insilmaril@721: if (ok) setMapDefLinkColor (c); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setMapLinkStyle") insilmaril@721: { insilmaril@721: if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString (ok,0); insilmaril@721: if (ok) setMapLinkStyle(s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setHeading") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString (ok,0); insilmaril@721: if (ok) insilmaril@721: setHeading (s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setHideExport") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@735: } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: b=parser.parBool(ok,0); insilmaril@721: if (ok) setHideExport (b); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setIncludeImagesHorizontally") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: b=parser.parBool(ok,0); insilmaril@721: if (ok) setIncludeImagesHor(b); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setIncludeImagesVertically") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: b=parser.parBool(ok,0); insilmaril@721: if (ok) setIncludeImagesVer(b); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setHideLinkUnselected") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@735: } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection does not allow hiding the link"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: b=parser.parBool(ok,0); insilmaril@721: if (ok) setHideLinkUnselected(b); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setSelectionColor") insilmaril@721: { insilmaril@721: if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: QColor c=parser.parColor (ok,0); insilmaril@721: if (ok) setSelectionColorInt (c); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setURL") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString (ok,0); insilmaril@721: if (ok) setURL(s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setVymLink") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString (ok,0); insilmaril@721: if (ok) setVymLink(s); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: else if (com=="setFlag") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: selb->activateStandardFlag(s); insilmaril@721: selb->updateFlagsToolbar(); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setFrameType") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) insilmaril@721: setFrameType (s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="sortChildren") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: sortChildren(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="toggleFlag") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: selb->toggleStandardFlag(s); insilmaril@721: selb->updateFlagsToolbar(); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="unscroll") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: if (!unscrollBranch (selb)) insilmaril@721: parser.setError (Aborted,"Could not unscroll branch"); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="unscrollChildren") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@721: unscrollChildren (); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="unsetFlag") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: selb->deactivateStandardFlag(s); insilmaril@721: selb->updateFlagsToolbar(); insilmaril@721: } insilmaril@721: } insilmaril@721: } else insilmaril@721: parser.setError (Aborted,"Unknown command"); insilmaril@721: insilmaril@721: // Any errors? insilmaril@721: if (parser.errorLevel()==NoError) insilmaril@721: { insilmaril@721: // setChanged(); FIXME should not be called e.g. for export?! insilmaril@721: reposition(); insilmaril@721: } insilmaril@721: else insilmaril@721: { insilmaril@721: // TODO Error handling insilmaril@721: qWarning("VymModel::parseAtom: Error!"); insilmaril@721: qWarning(parser.errorMessage()); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::runScript (QString script) insilmaril@721: { insilmaril@721: parser.setScript (script); insilmaril@721: parser.runScript(); insilmaril@721: while (parser.next() ) insilmaril@721: parseAtom(parser.getAtom()); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setExportMode (bool b) insilmaril@721: { insilmaril@721: // should be called before and after exports insilmaril@721: // depending on the settings insilmaril@721: if (b && settings.value("/export/useHideExport","true")=="true") insilmaril@721: setHideTmpMode (HideExport); insilmaril@721: else insilmaril@721: setHideTmpMode (HideNone); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::exportImage(QString fname, bool askName, QString format) insilmaril@721: { insilmaril@721: if (fname=="") insilmaril@721: { insilmaril@721: fname=getMapName()+".png"; insilmaril@721: format="PNG"; insilmaril@721: } insilmaril@721: insilmaril@721: if (askName) insilmaril@721: { insilmaril@721: QStringList fl; insilmaril@721: QFileDialog *fd=new QFileDialog (NULL); insilmaril@721: fd->setCaption (tr("Export map as image")); insilmaril@721: fd->setDirectory (lastImageDir); insilmaril@721: fd->setFileMode(QFileDialog::AnyFile); insilmaril@721: fd->setFilters (imageIO.getFilters() ); insilmaril@721: if (fd->exec()) insilmaril@721: { insilmaril@721: fl=fd->selectedFiles(); insilmaril@721: fname=fl.first(); insilmaril@721: format=imageIO.getType(fd->selectedFilter()); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: setExportMode (true); insilmaril@721: QPixmap pix (getPixmap()); insilmaril@721: pix.save(fname, format); insilmaril@721: setExportMode (false); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::exportXML(QString dir, bool askForName) insilmaril@721: { insilmaril@721: if (askForName) insilmaril@721: { insilmaril@721: dir=browseDirectory(NULL,tr("Export XML to directory")); insilmaril@721: if (dir =="" && !reallyWriteDirectory(dir) ) insilmaril@721: return; insilmaril@721: } insilmaril@721: insilmaril@721: // Hide stuff during export, if settings want this insilmaril@721: setExportMode (true); insilmaril@721: insilmaril@721: // Create subdirectories insilmaril@721: makeSubDirs (dir); insilmaril@721: insilmaril@721: // write to directory insilmaril@721: QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL); insilmaril@721: QFile file; insilmaril@721: insilmaril@721: file.setName ( dir + "/"+mapName+".xml"); insilmaril@721: if ( !file.open( QIODevice::WriteOnly ) ) insilmaril@721: { insilmaril@721: // This should neverever happen insilmaril@721: QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name())); insilmaril@721: return; insilmaril@721: } insilmaril@721: insilmaril@721: // Write it finally, and write in UTF8, no matter what insilmaril@721: QTextStream ts( &file ); insilmaril@721: ts.setEncoding (QTextStream::UnicodeUTF8); insilmaril@721: ts << saveFile; insilmaril@721: file.close(); insilmaril@721: insilmaril@721: // Now write image, too insilmaril@721: exportImage (dir+"/images/"+mapName+".png",false,"PNG"); insilmaril@721: insilmaril@721: setExportMode (false); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::exportASCII(QString fname,bool askName) insilmaril@721: { insilmaril@721: ExportASCII ex; insilmaril@721: ex.setModel (this); insilmaril@721: if (fname=="") insilmaril@721: ex.setFile (mapName+".txt"); insilmaril@721: else insilmaril@721: ex.setFile (fname); insilmaril@721: insilmaril@721: if (askName) insilmaril@721: { insilmaril@721: //ex.addFilter ("TXT (*.txt)"); insilmaril@721: ex.setDir(lastImageDir); insilmaril@721: //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)")); insilmaril@721: ex.execDialog() ; insilmaril@721: } insilmaril@721: if (!ex.canceled()) insilmaril@721: { insilmaril@721: setExportMode(true); insilmaril@721: ex.doExport(); insilmaril@721: setExportMode(false); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::exportXHTML (const QString &dir, bool askForName) insilmaril@721: { insilmaril@721: ExportXHTMLDialog dia(NULL); insilmaril@721: dia.setFilePath (filePath ); insilmaril@721: dia.setMapName (mapName ); insilmaril@721: dia.readSettings(); insilmaril@721: if (dir!="") dia.setDir (dir); insilmaril@721: insilmaril@721: bool ok=true; insilmaril@721: insilmaril@721: if (askForName) insilmaril@721: { insilmaril@721: if (dia.exec()!=QDialog::Accepted) insilmaril@721: ok=false; insilmaril@721: else insilmaril@721: { insilmaril@721: QDir d (dia.getDir()); insilmaril@721: // Check, if warnings should be used before overwriting insilmaril@721: // the output directory insilmaril@721: if (d.exists() && d.count()>0) insilmaril@721: { insilmaril@721: WarningDialog warn; insilmaril@721: warn.showCancelButton (true); insilmaril@721: warn.setText(QString( insilmaril@721: "The directory %1 is not empty.\n" insilmaril@721: "Do you risk to overwrite some of its contents?").arg(d.path() )); insilmaril@721: warn.setCaption("Warning: Directory not empty"); insilmaril@721: warn.setShowAgainName("mainwindow/overwrite-dir-xhtml"); insilmaril@721: insilmaril@721: if (warn.exec()!=QDialog::Accepted) ok=false; insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: exportXML (dia.getDir(),false ); insilmaril@721: dia.doExport(mapName ); insilmaril@721: //if (dia.hasChanged()) setChanged(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::exportOOPresentation(const QString &fn, const QString &cf) insilmaril@721: { insilmaril@721: ExportOO ex; insilmaril@721: ex.setFile (fn); insilmaril@721: ex.setModel (this); insilmaril@721: if (ex.setConfigFile(cf)) insilmaril@721: { insilmaril@721: setExportMode (true); insilmaril@721: ex.exportPresentation(); insilmaril@721: setExportMode (false); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@650: insilmaril@652: ////////////////////////////////////////////// insilmaril@652: // View related insilmaril@652: ////////////////////////////////////////////// insilmaril@652: insilmaril@723: void VymModel::registerEditor(QWidget *me) insilmaril@721: { insilmaril@723: mapEditor=(MapEditor*)me; insilmaril@723: for (int i=0; isetMapEditor(mapEditor); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::unregisterEditor(QWidget *) insilmaril@721: { insilmaril@723: mapEditor=NULL; insilmaril@723: } insilmaril@723: insilmaril@723: void VymModel::setContextPos(QPointF p) insilmaril@723: { insilmaril@723: contextPos=p; insilmaril@723: } insilmaril@723: insilmaril@723: void VymModel::unsetContextPos() insilmaril@723: { insilmaril@723: contextPos=QPointF(); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::updateNoteFlag() insilmaril@721: { insilmaril@721: setChanged(); insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bo->updateNoteFlag(); insilmaril@721: mainWindow->updateActions(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@652: void VymModel::updateRelPositions() insilmaril@652: { insilmaril@652: for (int i=0; iupdateRelPositions(); insilmaril@652: } insilmaril@652: insilmaril@652: void VymModel::reposition() insilmaril@652: { insilmaril@652: for (int i=0;ireposition(); // for positioning heading insilmaril@652: } insilmaril@652: insilmaril@665: QPolygonF VymModel::shape(BranchObj *bo) insilmaril@665: { insilmaril@665: // Creating (arbitrary) shapes insilmaril@665: insilmaril@665: QPolygonF p; insilmaril@665: QRectF rb=bo->getBBox(); insilmaril@665: if (bo->getDepth()==0) insilmaril@665: { insilmaril@665: // Just take BBox of this mapCenter insilmaril@665: p<getTotalBBox(); insilmaril@665: if (bo->getOrientation()==LinkableMapObj::LeftOfCenter) insilmaril@665: p <" insilmaril@665: <<"="<getHeading() )<<")" insilmaril@665: <<" with ("<< qPrintable (boB->getHeading() ) insilmaril@665: <<") willIntersect" insilmaril@665: <getLMO() ); insilmaril@721: bo->setLinkStyle(bo->getDefLinkStyle()); insilmaril@741: cur=next(cur,prev,d); insilmaril@721: } insilmaril@721: reposition(); insilmaril@721: } insilmaril@721: insilmaril@721: LinkableMapObj::Style VymModel::getMapLinkStyle () insilmaril@721: { insilmaril@721: return linkstyle; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setMapDefLinkColor(QColor col) insilmaril@721: { insilmaril@721: if ( !col.isValid() ) return; insilmaril@721: saveState ( insilmaril@721: QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()), insilmaril@721: QString("setMapDefLinkColor (\"%1\")").arg(col.name()), insilmaril@721: QString("Set map link color to %1").arg(col.name()) insilmaril@721: ); insilmaril@721: insilmaril@721: defLinkColor=col; insilmaril@741: TreeItem *cur=NULL; insilmaril@741: TreeItem *prev=NULL; insilmaril@741: int d=0; insilmaril@721: BranchObj *bo; insilmaril@741: cur=next(cur,prev,d); insilmaril@741: while (cur) insilmaril@721: { insilmaril@741: bo=(BranchObj*)(cur->getLMO() ); insilmaril@721: bo->setLinkColor(); insilmaril@741: next(cur,prev,d); insilmaril@721: } insilmaril@721: updateActions(); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setMapLinkColorHintInt() insilmaril@721: { insilmaril@721: // called from setMapLinkColorHint(lch) or at end of parse insilmaril@741: TreeItem *cur=NULL; insilmaril@741: TreeItem *prev=NULL; insilmaril@741: int d=0; insilmaril@721: BranchObj *bo; insilmaril@741: cur=next(cur,prev,d); insilmaril@741: while (cur) insilmaril@721: { insilmaril@741: bo=(BranchObj*)(cur->getLMO() ); insilmaril@721: bo->setLinkColor(); insilmaril@741: cur=next(cur,prev,d); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch) insilmaril@721: { insilmaril@721: linkcolorhint=lch; insilmaril@721: setMapLinkColorHintInt(); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::toggleMapLinkColorHint() insilmaril@721: { insilmaril@721: if (linkcolorhint==LinkableMapObj::HeadingColor) insilmaril@721: linkcolorhint=LinkableMapObj::DefaultColor; insilmaril@721: else insilmaril@721: linkcolorhint=LinkableMapObj::HeadingColor; insilmaril@741: TreeItem *cur=NULL; insilmaril@741: TreeItem *prev=NULL; insilmaril@741: int d=0; insilmaril@721: BranchObj *bo; insilmaril@741: cur=next(cur,prev,d); insilmaril@741: while (cur) insilmaril@721: { insilmaril@741: bo=(BranchObj*)(cur->getLMO() ); insilmaril@721: bo->setLinkColor(); insilmaril@741: next(cur,prev,d); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@738: void VymModel::selectMapBackgroundImage () // FIXME move to ME insilmaril@721: { insilmaril@721: Q3FileDialog *fd=new Q3FileDialog( NULL); insilmaril@721: fd->setMode (Q3FileDialog::ExistingFile); insilmaril@721: fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); insilmaril@721: ImagePreview *p =new ImagePreview (fd); insilmaril@721: fd->setContentsPreviewEnabled( TRUE ); insilmaril@721: fd->setContentsPreview( p, p ); insilmaril@721: fd->setPreviewMode( Q3FileDialog::Contents ); insilmaril@721: fd->setCaption(vymName+" - " +tr("Load background image")); insilmaril@721: fd->setDir (lastImageDir); insilmaril@721: fd->show(); insilmaril@721: insilmaril@721: if ( fd->exec() == QDialog::Accepted ) insilmaril@721: { insilmaril@721: // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory(); insilmaril@721: lastImageDir=QDir (fd->dirPath()); insilmaril@721: setMapBackgroundImage (fd->selectedFile()); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setMapBackgroundImage (const QString &fn) //FIXME missing savestate insilmaril@721: { insilmaril@721: QColor oldcol=mapScene->backgroundBrush().color(); insilmaril@721: /* insilmaril@721: saveState( insilmaril@721: selection, insilmaril@721: QString ("setMapBackgroundImage (%1)").arg(oldcol.name()), insilmaril@721: selection, insilmaril@721: QString ("setMapBackgroundImage (%1)").arg(col.name()), insilmaril@721: QString("Set background color of map to %1").arg(col.name())); insilmaril@721: */ insilmaril@721: QBrush brush; insilmaril@721: brush.setTextureImage (QPixmap (fn)); insilmaril@721: mapScene->setBackgroundBrush(brush); insilmaril@721: } insilmaril@721: insilmaril@738: void VymModel::selectMapBackgroundColor() // FIXME move to ME insilmaril@721: { insilmaril@721: QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL); insilmaril@721: if ( !col.isValid() ) return; insilmaril@721: setMapBackgroundColor( col ); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@738: void VymModel::setMapBackgroundColor(QColor col) // FIXME move to ME insilmaril@721: { insilmaril@721: QColor oldcol=mapScene->backgroundBrush().color(); insilmaril@721: saveState( insilmaril@721: QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()), insilmaril@721: QString ("setMapBackgroundColor (\"%1\")").arg(col.name()), insilmaril@721: QString("Set background color of map to %1").arg(col.name())); insilmaril@721: mapScene->setBackgroundBrush(col); insilmaril@721: } insilmaril@721: insilmaril@738: QColor VymModel::getMapBackgroundColor() // FIXME move to ME insilmaril@721: { insilmaril@721: return mapScene->backgroundBrush().color(); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@738: LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME move to ME insilmaril@721: { insilmaril@721: return linkcolorhint; insilmaril@721: } insilmaril@721: insilmaril@738: QColor VymModel::getMapDefLinkColor() // FIXME move to ME insilmaril@721: { insilmaril@721: return defLinkColor; insilmaril@721: } insilmaril@721: insilmaril@738: void VymModel::setMapDefXLinkColor(QColor col) // FIXME move to ME insilmaril@721: { insilmaril@721: defXLinkColor=col; insilmaril@721: } insilmaril@721: insilmaril@738: QColor VymModel::getMapDefXLinkColor() // FIXME move to ME insilmaril@721: { insilmaril@721: return defXLinkColor; insilmaril@721: } insilmaril@721: insilmaril@738: void VymModel::setMapDefXLinkWidth (int w) // FIXME move to ME insilmaril@721: { insilmaril@721: defXLinkWidth=w; insilmaril@721: } insilmaril@721: insilmaril@738: int VymModel::getMapDefXLinkWidth() // FIXME move to ME insilmaril@721: { insilmaril@721: return defXLinkWidth; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::move(const double &x, const double &y) insilmaril@721: { insilmaril@735: BranchObj *bo = getSelectedBranch(); insilmaril@735: if (bo && insilmaril@735: (selectionType()==TreeItem::Branch || insilmaril@735: selectionType()==TreeItem::MapCenter || insilmaril@735: selectionType()==TreeItem::Image insilmaril@735: )) insilmaril@721: { insilmaril@735: QPointF ap(bo->getAbsPos()); insilmaril@721: QPointF to(x, y); insilmaril@721: if (ap != to) insilmaril@721: { insilmaril@721: QString ps=qpointfToString(ap); insilmaril@735: QString s=getSelectString(); insilmaril@721: saveState( insilmaril@721: s, "move "+ps, insilmaril@721: s, "move "+qpointfToString(to), insilmaril@735: QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps)); insilmaril@735: bo->move(x,y); insilmaril@721: reposition(); insilmaril@721: selection.update(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::moveRel (const double &x, const double &y) insilmaril@721: { insilmaril@735: BranchObj *bo = getSelectedBranch(); insilmaril@735: if (bo && insilmaril@735: (selectionType()==TreeItem::Branch || insilmaril@735: selectionType()==TreeItem::MapCenter || insilmaril@735: selectionType()==TreeItem::Image insilmaril@735: )) insilmaril@735: if (bo) insilmaril@721: { insilmaril@735: QPointF rp(bo->getRelPos()); insilmaril@721: QPointF to(x, y); insilmaril@721: if (rp != to) insilmaril@721: { insilmaril@735: QString ps=qpointfToString (bo->getRelPos()); insilmaril@735: QString s=getSelectString(bo); insilmaril@721: saveState( insilmaril@721: s, "moveRel "+ps, insilmaril@721: s, "moveRel "+qpointfToString(to), insilmaril@735: QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps)); insilmaril@735: ((OrnamentedObj*)bo)->move2RelPos (x,y); insilmaril@721: reposition(); insilmaril@735: bo->updateLink(); insilmaril@721: selection.update(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@696: void VymModel::animate() insilmaril@696: { insilmaril@696: animationTimer->stop(); insilmaril@696: BranchObj *bo; insilmaril@696: int i=0; insilmaril@696: while (ianimate()) insilmaril@696: { insilmaril@721: if (i>=0) insilmaril@721: { insilmaril@721: animObjList.removeAt(i); insilmaril@721: i--; insilmaril@721: } insilmaril@696: } insilmaril@696: bo->reposition(); insilmaril@696: i++; insilmaril@696: } insilmaril@735: QItemSelection sel=selModel->selection(); insilmaril@735: emit (selectionChanged(sel,sel)); insilmaril@735: insilmaril@696: mapScene->update(); insilmaril@723: if (!animObjList.isEmpty()) animationTimer->start(); insilmaril@696: } insilmaril@696: insilmaril@696: insilmaril@723: void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest) insilmaril@696: { insilmaril@696: if (bo && bo->getDepth()>0) insilmaril@696: { insilmaril@696: AnimPoint ap; insilmaril@696: ap.setStart (start); insilmaril@696: ap.setDest (dest); insilmaril@696: ap.setTicks (animationTicks); insilmaril@696: ap.setAnimated (true); insilmaril@696: bo->setAnimation (ap); insilmaril@696: animObjList.append( bo ); insilmaril@696: animationTimer->setSingleShot (true); insilmaril@696: animationTimer->start(animationInterval); insilmaril@696: } insilmaril@696: } insilmaril@696: insilmaril@722: void VymModel::stopAnimation (MapObj *mo) insilmaril@722: { insilmaril@722: int i=animObjList.indexOf(mo); insilmaril@722: if (i>=0) insilmaril@722: animObjList.removeAt (i); insilmaril@722: } insilmaril@722: insilmaril@721: void VymModel::sendSelection() insilmaril@721: { insilmaril@721: if (netstate!=Server) return; insilmaril@721: sendData (QString("select (\"%1\")").arg(selection.getSelectString()) ); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::newServer() insilmaril@721: { insilmaril@721: port=54321; insilmaril@721: sendCounter=0; insilmaril@721: tcpServer = new QTcpServer(this); insilmaril@721: if (!tcpServer->listen(QHostAddress::Any,port)) { insilmaril@721: QMessageBox::critical(NULL, "vym server", insilmaril@721: QString("Unable to start the server: %1.").arg(tcpServer->errorString())); insilmaril@721: //FIXME needed? we are no widget any longer... close(); insilmaril@721: return; insilmaril@721: } insilmaril@721: connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient())); insilmaril@721: netstate=Server; insilmaril@721: cout<<"Server is running on port "<serverPort()<abort(); insilmaril@721: clientSocket->connectToHost(server ,port); insilmaril@721: connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData())); insilmaril@721: connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)), insilmaril@721: this, SLOT(displayNetworkError(QAbstractSocket::SocketError))); insilmaril@721: netstate=Client; insilmaril@721: cout<<"connected to "<nextPendingConnection(); insilmaril@721: connect(newClient, SIGNAL(disconnected()), insilmaril@721: newClient, SLOT(deleteLater())); insilmaril@721: insilmaril@721: cout <<"ME::newClient at "<peerAddress().toString() )<seek(0); insilmaril@721: quint16 bs=(quint16)(block.size() - 2*sizeof(quint16)); insilmaril@721: out << bs; insilmaril@721: insilmaril@721: if (debug) insilmaril@721: cout << "ME::sendData bs="<peerAddress().toString())<write (block); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::readData () insilmaril@721: { insilmaril@721: while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) ) insilmaril@721: { insilmaril@721: if (debug) insilmaril@721: cout <<"readData bytesAvail="<bytesAvailable(); insilmaril@721: quint16 recCounter; insilmaril@721: quint16 blockSize; insilmaril@721: insilmaril@721: QDataStream in(clientSocket); insilmaril@721: in.setVersion(QDataStream::Qt_4_0); insilmaril@721: insilmaril@721: in >> blockSize; insilmaril@721: in >> recCounter; insilmaril@721: insilmaril@721: QString t; insilmaril@721: in >>t; insilmaril@721: if (debug) insilmaril@721: cout << " t="<errorString())); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::selectMapSelectionColor() insilmaril@721: { insilmaril@721: QColor col = QColorDialog::getColor( defLinkColor, NULL); insilmaril@721: setSelectionColor (col); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setSelectionColorInt (QColor col) insilmaril@721: { insilmaril@721: if ( !col.isValid() ) return; insilmaril@721: saveState ( insilmaril@728: QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()), insilmaril@721: QString("setSelectionColor (%1)").arg(col.name()), insilmaril@721: QString("Set color of selection box to %1").arg(col.name()) insilmaril@721: ); insilmaril@721: insilmaril@728: mapEditor->setSelectionColor (col); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::updateSelection() insilmaril@721: { insilmaril@735: QItemSelection newsel=selModel->selection(); insilmaril@735: updateSelection (newsel); insilmaril@735: } insilmaril@735: insilmaril@742: void VymModel::updateSelection(const QItemSelection &newsel) insilmaril@735: { insilmaril@742: emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor insilmaril@735: ensureSelectionVisible(); insilmaril@735: sendSelection(); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setSelectionColor(QColor col) insilmaril@721: { insilmaril@721: if ( !col.isValid() ) return; insilmaril@721: saveState ( insilmaril@728: QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()), insilmaril@721: QString("setSelectionColor (%1)").arg(col.name()), insilmaril@721: QString("Set color of selection box to %1").arg(col.name()) insilmaril@721: ); insilmaril@721: setSelectionColorInt (col); insilmaril@721: } insilmaril@721: insilmaril@721: QColor VymModel::getSelectionColor() insilmaril@721: { insilmaril@728: return mapEditor->getSelectionColor(); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setHideTmpMode (HideTmpMode mode) insilmaril@721: { insilmaril@721: hidemode=mode; insilmaril@721: for (int i=0;isetHideTmp (mode); insilmaril@721: reposition(); insilmaril@721: // FIXME needed? scene()->update(); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: QRectF VymModel::getTotalBBox() insilmaril@721: { insilmaril@721: QRectF r; insilmaril@721: for (int i=0;igetTotalBBox(), r); insilmaril@721: return r; insilmaril@721: } insilmaril@652: insilmaril@652: ////////////////////////////////////////////// insilmaril@652: // Selection related insilmaril@652: ////////////////////////////////////////////// insilmaril@652: insilmaril@727: void VymModel::setSelectionModel (QItemSelectionModel *sm) insilmaril@727: { insilmaril@727: selModel=sm; insilmaril@728: cout << "VM::setSelModel selModel="<selectedIndexes().first(); // TODO no multiselections yet insilmaril@727: insilmaril@727: TreeItem *item = static_cast(index.internalPointer()); insilmaril@727: return select (item->getLMO() ); insilmaril@727: } insilmaril@727: insilmaril@721: bool VymModel::select (const QString &s) insilmaril@721: { insilmaril@735: LinkableMapObj *lmo=findObjBySelect(s); insilmaril@735: insilmaril@735: // Finally select the found object insilmaril@735: if (lmo) insilmaril@721: { insilmaril@735: unselect(); insilmaril@735: select (lmo); insilmaril@721: return true; insilmaril@735: } insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@721: bool VymModel::select (LinkableMapObj *lmo) insilmaril@721: { insilmaril@735: QItemSelection oldsel=selModel->selection(); insilmaril@735: insilmaril@735: if (lmo) insilmaril@738: return select (lmo->getTreeItem() ); insilmaril@738: else insilmaril@738: return false; insilmaril@738: } insilmaril@738: insilmaril@738: bool VymModel::select (TreeItem *ti) insilmaril@738: { insilmaril@738: if (ti) insilmaril@721: { insilmaril@735: QModelIndex ix=index(ti); insilmaril@735: selModel->select (ix,QItemSelectionModel::ClearAndSelect ); insilmaril@738: ti->setLastSelectedBranch(); insilmaril@737: //updateSelection(oldsel); //FIXME needed? insilmaril@721: return true; insilmaril@721: } insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::unselect() insilmaril@721: { insilmaril@735: selModel->clearSelection(); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::reselect() insilmaril@721: { insilmaril@721: selection.reselect(); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::ensureSelectionVisible() insilmaril@721: { insilmaril@735: LinkableMapObj *lmo=getSelectedLMO(); insilmaril@721: if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() ); insilmaril@721: insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::selectInt (LinkableMapObj *lmo) insilmaril@721: { insilmaril@721: if (selection.select(lmo)) insilmaril@721: { insilmaril@729: //selection.update(); insilmaril@729: sendSelection (); // FIXME VM use signal insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::selectNextBranchInt() insilmaril@721: { insilmaril@721: // Increase number of branch insilmaril@735: LinkableMapObj *sel=getSelectedBranch(); insilmaril@721: if (sel) insilmaril@721: { insilmaril@735: QString s=getSelectString(); insilmaril@721: QString part; insilmaril@721: QString typ; insilmaril@721: QString num; insilmaril@721: insilmaril@721: // Where am I? insilmaril@721: part=s.section(",",-1); insilmaril@721: typ=part.left (3); insilmaril@721: num=part.right(part.length() - 3); insilmaril@721: insilmaril@721: s=s.left (s.length() -num.length()); insilmaril@721: insilmaril@721: // Go to next lmo insilmaril@721: num=QString ("%1").arg(num.toUInt()+1); insilmaril@721: insilmaril@721: s=s+num; insilmaril@721: insilmaril@721: // Try to select this one insilmaril@721: if (select (s)) return; insilmaril@721: insilmaril@721: // We have no direct successor, insilmaril@721: // try to increase the parental number in order to insilmaril@721: // find a successor with same depth insilmaril@721: insilmaril@735: int d=getSelectedLMO()->getDepth(); insilmaril@721: int oldDepth=d; insilmaril@721: int i; insilmaril@721: bool found=false; insilmaril@721: bool b; insilmaril@721: while (!found && d>0) insilmaril@721: { insilmaril@721: s=s.section (",",0,d-1); insilmaril@721: // replace substring of current depth in s with "1" insilmaril@721: part=s.section(",",-1); insilmaril@721: typ=part.left (3); insilmaril@721: num=part.right(part.length() - 3); insilmaril@721: insilmaril@721: if (d>1) insilmaril@721: { insilmaril@721: // increase number of parent insilmaril@721: num=QString ("%1").arg(num.toUInt()+1); insilmaril@721: s=s.section (",",0,d-2) + ","+ typ+num; insilmaril@721: } else insilmaril@721: { insilmaril@721: // Special case, look at orientation insilmaril@735: if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@721: num=QString ("%1").arg(num.toUInt()+1); insilmaril@721: else insilmaril@721: num=QString ("%1").arg(num.toUInt()-1); insilmaril@721: s=typ+num; insilmaril@721: } insilmaril@721: insilmaril@721: if (select (s)) insilmaril@721: // pad to oldDepth, select the first branch for each depth insilmaril@721: for (i=d;icountBranches()>0) insilmaril@721: s+=",bo:0"; insilmaril@721: else insilmaril@721: break; insilmaril@721: } else insilmaril@721: break; insilmaril@721: } insilmaril@721: insilmaril@721: // try to select the freshly built string insilmaril@721: found=select(s); insilmaril@721: d--; insilmaril@721: } insilmaril@721: return; insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::selectPrevBranchInt() insilmaril@721: { insilmaril@721: // Decrease number of branch insilmaril@738: if (selectionType()==TreeItem::Branch) insilmaril@721: { insilmaril@738: QString s=getSelectString(); insilmaril@721: QString part; insilmaril@721: QString typ; insilmaril@721: QString num; insilmaril@721: insilmaril@721: // Where am I? insilmaril@721: part=s.section(",",-1); insilmaril@721: typ=part.left (3); insilmaril@721: num=part.right(part.length() - 3); insilmaril@721: insilmaril@721: s=s.left (s.length() -num.length()); insilmaril@721: insilmaril@721: int n=num.toInt()-1; insilmaril@721: insilmaril@721: // Go to next lmo insilmaril@721: num=QString ("%1").arg(n); insilmaril@721: s=s+num; insilmaril@721: insilmaril@721: // Try to select this one insilmaril@721: if (n>=0 && select (s)) return; insilmaril@721: insilmaril@721: // We have no direct precessor, insilmaril@721: // try to decrease the parental number in order to insilmaril@721: // find a precessor with same depth insilmaril@721: insilmaril@735: int d=getSelectedLMO()->getDepth(); insilmaril@721: int oldDepth=d; insilmaril@721: int i; insilmaril@721: bool found=false; insilmaril@721: bool b; insilmaril@721: while (!found && d>0) insilmaril@721: { insilmaril@721: s=s.section (",",0,d-1); insilmaril@721: // replace substring of current depth in s with "1" insilmaril@721: part=s.section(",",-1); insilmaril@721: typ=part.left (3); insilmaril@721: num=part.right(part.length() - 3); insilmaril@721: insilmaril@721: if (d>1) insilmaril@721: { insilmaril@721: // decrease number of parent insilmaril@721: num=QString ("%1").arg(num.toInt()-1); insilmaril@721: s=s.section (",",0,d-2) + ","+ typ+num; insilmaril@721: } else insilmaril@721: { insilmaril@721: // Special case, look at orientation insilmaril@735: if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@721: num=QString ("%1").arg(num.toInt()-1); insilmaril@721: else insilmaril@721: num=QString ("%1").arg(num.toInt()+1); insilmaril@721: s=typ+num; insilmaril@721: } insilmaril@721: insilmaril@721: if (select(s)) insilmaril@721: // pad to oldDepth, select the last branch for each depth insilmaril@721: for (i=d;icountBranches()>0) insilmaril@735: s+=",bo:"+ QString ("%1").arg( getSelectedBranch()->countBranches()-1 ); insilmaril@721: else insilmaril@721: break; insilmaril@721: else insilmaril@721: break; insilmaril@721: } insilmaril@721: insilmaril@721: // try to select the freshly built string insilmaril@721: found=select(s); insilmaril@721: d--; insilmaril@721: } insilmaril@721: return; insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::selectUpperBranch() insilmaril@721: { insilmaril@721: if (selection.isBlocked() ) return; insilmaril@721: insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@735: if (bo && selectionType()==TreeItem::Branch) insilmaril@721: { insilmaril@721: if (bo->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@721: selectPrevBranchInt(); insilmaril@721: else insilmaril@721: if (bo->getDepth()==1) insilmaril@721: selectNextBranchInt(); insilmaril@721: else insilmaril@721: selectPrevBranchInt(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::selectLowerBranch() insilmaril@721: { insilmaril@721: if (selection.isBlocked() ) return; insilmaril@721: insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@735: if (bo && selectionType()==TreeItem::Branch) insilmaril@721: { insilmaril@721: if (bo->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@721: selectNextBranchInt(); insilmaril@721: else insilmaril@721: if (bo->getDepth()==1) insilmaril@721: selectPrevBranchInt(); insilmaril@721: else insilmaril@721: selectNextBranchInt(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::selectLeftBranch() insilmaril@721: { insilmaril@721: if (selection.isBlocked() ) return; insilmaril@721: insilmaril@735: QItemSelection oldsel=selModel->selection(); insilmaril@735: insilmaril@721: BranchObj* par; insilmaril@735: LinkableMapObj *sel=getSelectedBranch(); insilmaril@721: if (sel) insilmaril@721: { insilmaril@735: if (selectionType()== TreeItem::MapCenter) insilmaril@721: { insilmaril@735: QModelIndex ix=getSelectedIndex(); insilmaril@735: selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect ); insilmaril@721: } else insilmaril@721: { insilmaril@721: par=(BranchObj*)(sel->getParObj()); insilmaril@721: if (sel->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@721: { insilmaril@735: // right of center insilmaril@735: if (selectionType() == TreeItem::Branch || insilmaril@735: selectionType() == TreeItem::Image) insilmaril@721: { insilmaril@735: QModelIndex ix=getSelectedIndex(); insilmaril@735: ix=parent(ix); insilmaril@735: selModel->select (ix,QItemSelectionModel::ClearAndSelect ); insilmaril@721: } insilmaril@721: } else insilmaril@721: { insilmaril@735: // left of center insilmaril@735: if (selectionType() == TreeItem::Branch ) insilmaril@721: { insilmaril@735: selectLastSelectedBranch(); insilmaril@735: return; insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@735: updateSelection (oldsel); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::selectRightBranch() insilmaril@721: { insilmaril@721: if (selection.isBlocked() ) return; insilmaril@721: insilmaril@735: QItemSelection oldsel=selModel->selection(); insilmaril@735: insilmaril@721: BranchObj* par; insilmaril@735: LinkableMapObj *sel=getSelectedBranch(); insilmaril@721: if (sel) insilmaril@721: { insilmaril@737: if (selectionType()== TreeItem::MapCenter) insilmaril@721: { insilmaril@737: QModelIndex ix=getSelectedIndex(); insilmaril@737: selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect ); insilmaril@721: } else insilmaril@721: { insilmaril@737: par=(BranchObj*)(sel->getParObj()); insilmaril@737: if (sel->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@721: { insilmaril@737: // right of center insilmaril@737: if (selectionType() == TreeItem::Branch ) insilmaril@737: { insilmaril@737: selectLastSelectedBranch(); insilmaril@737: return; insilmaril@737: } insilmaril@737: } else insilmaril@737: { insilmaril@737: // left of center insilmaril@735: if (selectionType() == TreeItem::Branch || insilmaril@735: selectionType() == TreeItem::Image) insilmaril@721: { insilmaril@735: QModelIndex ix=getSelectedIndex(); insilmaril@735: ix=parent(ix); insilmaril@735: selModel->select (ix,QItemSelectionModel::ClearAndSelect ); insilmaril@721: } insilmaril@721: } insilmaril@737: } insilmaril@737: updateSelection (oldsel); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::selectFirstBranch() insilmaril@721: { insilmaril@738: TreeItem *ti=getSelectedBranchItem(); insilmaril@738: if (ti) insilmaril@721: { insilmaril@738: TreeItem *par=ti->parent(); insilmaril@721: if (!par) return; insilmaril@738: TreeItem *ti2=par->getFirstBranch(); insilmaril@738: if (ti2) { insilmaril@738: select(ti2); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: sendSelection(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::selectLastBranch() insilmaril@721: { insilmaril@738: TreeItem *ti=getSelectedBranchItem(); insilmaril@738: if (ti) insilmaril@721: { insilmaril@738: TreeItem *par=ti->parent(); insilmaril@721: if (!par) return; insilmaril@738: TreeItem *ti2=par->getLastBranch(); insilmaril@738: if (ti2) { insilmaril@738: select(ti2); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: sendSelection(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@735: void VymModel::selectLastSelectedBranch() insilmaril@735: { insilmaril@738: TreeItem *ti=getSelectedBranchItem(); insilmaril@738: if (ti) insilmaril@735: { insilmaril@738: ti=ti->getLastSelectedBranch(); insilmaril@738: if (ti) select (ti); insilmaril@735: } insilmaril@735: } insilmaril@735: insilmaril@726: void VymModel::selectParent() insilmaril@726: { insilmaril@738: TreeItem *ti=getSelectedItem(); insilmaril@738: TreeItem *par; insilmaril@738: if (ti) insilmaril@726: { insilmaril@738: par=ti->parent(); insilmaril@726: if (!par) return; insilmaril@735: select(par); insilmaril@726: selection.update(); insilmaril@726: ensureSelectionVisible(); insilmaril@726: sendSelection(); insilmaril@726: } insilmaril@726: } insilmaril@726: insilmaril@735: TreeItem::Type VymModel::selectionType() insilmaril@721: { insilmaril@735: QModelIndexList list=selModel->selectedIndexes(); insilmaril@735: if (list.isEmpty()) return TreeItem::Undefined; insilmaril@735: TreeItem *ti = static_cast(list.first().internalPointer()); insilmaril@735: return ti->getType(); insilmaril@735: insilmaril@721: } insilmaril@721: insilmaril@735: LinkableMapObj* VymModel::getSelectedLMO() insilmaril@652: { insilmaril@735: QModelIndexList list=selModel->selectedIndexes(); insilmaril@735: if (!list.isEmpty() ) insilmaril@735: { insilmaril@735: TreeItem *ti = static_cast(list.first().internalPointer()); insilmaril@735: TreeItem::Type type=ti->getType(); insilmaril@735: if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image) insilmaril@735: { insilmaril@735: return ti->getLMO(); insilmaril@735: } insilmaril@735: } insilmaril@735: return NULL; insilmaril@652: } insilmaril@735: insilmaril@652: BranchObj* VymModel::getSelectedBranch() insilmaril@652: { insilmaril@738: TreeItem *ti = getSelectedBranchItem(); insilmaril@738: if (ti) insilmaril@738: return (BranchObj*)ti->getLMO(); insilmaril@738: else insilmaril@738: return NULL; insilmaril@738: } insilmaril@738: insilmaril@738: TreeItem* VymModel::getSelectedBranchItem() insilmaril@738: { insilmaril@735: QModelIndexList list=selModel->selectedIndexes(); insilmaril@735: if (!list.isEmpty() ) insilmaril@735: { insilmaril@735: TreeItem *ti = static_cast(list.first().internalPointer()); insilmaril@735: TreeItem::Type type=ti->getType(); insilmaril@735: if (type ==TreeItem::Branch || type==TreeItem::MapCenter) insilmaril@738: return ti; insilmaril@735: } insilmaril@735: return NULL; insilmaril@735: } insilmaril@735: insilmaril@738: TreeItem* VymModel::getSelectedItem() insilmaril@735: { insilmaril@735: // FIXME this may not only be branch, but also float etc... insilmaril@735: BranchObj* bo=getSelectedBranch(); insilmaril@735: if (bo) return bo->getTreeItem(); // FIXME VM get directly from treemodl insilmaril@735: return NULL; insilmaril@735: } insilmaril@735: insilmaril@735: QModelIndex VymModel::getSelectedIndex() insilmaril@735: { insilmaril@735: QModelIndexList list=selModel->selectedIndexes(); insilmaril@735: if (list.isEmpty() ) insilmaril@735: return QModelIndex(); insilmaril@735: else insilmaril@735: return list.first(); insilmaril@652: } insilmaril@652: insilmaril@721: FloatImageObj* VymModel::getSelectedFloatImage() insilmaril@652: { insilmaril@721: return selection.getFloatImage(); insilmaril@721: } insilmaril@721: insilmaril@721: QString VymModel::getSelectString () insilmaril@721: { insilmaril@738: LinkableMapObj *lmo=getSelectedLMO(); insilmaril@738: if (lmo) insilmaril@738: return getSelectString(lmo); insilmaril@738: else insilmaril@738: return QString(); insilmaril@652: } insilmaril@652: insilmaril@729: QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME VM needs to use TreeModel insilmaril@652: { insilmaril@652: QString s; insilmaril@652: if (!lmo) return s; insilmaril@652: if (typeid(*lmo)==typeid(BranchObj) || insilmaril@652: typeid(*lmo)==typeid(MapCenterObj) ) insilmaril@652: { insilmaril@652: LinkableMapObj *par=lmo->getParObj(); insilmaril@652: if (par) insilmaril@652: { insilmaril@652: if (lmo->getDepth() ==1) insilmaril@652: // Mainbranch, return insilmaril@652: s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum()); insilmaril@652: else insilmaril@652: // Branch, call myself recursively insilmaril@652: s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum()); insilmaril@652: } else insilmaril@652: { insilmaril@652: // MapCenter insilmaril@652: int i=mapCenters.indexOf ((MapCenterObj*)lmo); insilmaril@652: if (i>=0) s=QString("mc:%1").arg(i); insilmaril@652: } insilmaril@652: } insilmaril@652: return s; insilmaril@652: } insilmaril@652: