insilmaril@650: #include insilmaril@687: #include insilmaril@650: insilmaril@721: #include "vymmodel.h" insilmaril@721: insilmaril@786: #include "attributeitem.h" insilmaril@753: #include "treeitem.h" insilmaril@749: #include "branchitem.h" 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 "misc.h" insilmaril@721: #include "parser.h" insilmaril@721: insilmaril@721: #include "warningdialog.h" insilmaril@790: #include "xlinkitem.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@781: extern QDBusConnection dbusConnection; insilmaril@781: insilmaril@696: extern Settings settings; insilmaril@721: extern QString tmpVymDir; insilmaril@721: insilmaril@721: extern TextEditor *textEditor; insilmaril@772: extern FlagRow *standardFlagsMaster; 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 Settings settings; insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: int VymModel::mapNum=0; // make instance insilmaril@696: insilmaril@784: VymModel::VymModel() insilmaril@650: { insilmaril@807: //cout << "Const VymModel\n"; insilmaril@721: init(); insilmaril@746: rootItem->setModel (this); insilmaril@650: } insilmaril@650: insilmaril@650: insilmaril@650: VymModel::~VymModel() insilmaril@650: { insilmaril@807: //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@804: while (rootItem->childCount() >0) insilmaril@804: deleteItem (rootItem->getChildNum(0) ); insilmaril@650: } insilmaril@650: insilmaril@650: void VymModel::init () insilmaril@650: { insilmaril@727: // No MapEditor yet insilmaril@727: mapEditor=NULL; insilmaril@721: insilmaril@746: // Also no scene yet (should not be needed anyway) FIXME-3 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@773: selectionBlocked=false; insilmaril@721: insilmaril@721: // find routine insilmaril@811: findReset(); insilmaril@696: insilmaril@786: // animations // FIXME-3 switch to new animation system insilmaril@786: animationUse=settings.readBoolEntry("/animation/use",false); // FIXME-3 add options to control _what_ is animated 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@753: hidemode=TreeItem::HideNone; insilmaril@721: insilmaril@721: // Network insilmaril@721: netstate=Offline; insilmaril@721: insilmaril@721: // Create MapCenter insilmaril@746: // addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene insilmaril@721: insilmaril@804: //Initialize DBUS object insilmaril@784: adaptorModel=new AdaptorModel(this); // Created and not deleted as documented in Qt insilmaril@804: if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapNum),this)) insilmaril@804: qWarning ("VymModel: Couldn't register DBUS object!"); 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@784: MapEditor* VymModel::getMapEditor() // FIXME-3 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@746: void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set insilmaril@650: { insilmaril@756: //cout << "VM::updateActions \n"; insilmaril@721: // Tell mainwindow to update states of actions insilmaril@721: mainWindow->updateActions(); insilmaril@650: } insilmaril@650: insilmaril@721: insilmaril@721: insilmaril@753: QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *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@749: xml.attribut("branchCount", QString().number(branchCount())) + 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@790: // Find the used flags while traversing the tree // FIXME-3 this can be done local to vymmodel maybe... insilmaril@772: standardFlagsMaster->resetUsedCounter(); insilmaril@721: insilmaril@721: // Build xml recursivly insilmaril@788: if (!saveSel) insilmaril@745: // Save all mapcenters as complete map, if saveSel not set insilmaril@745: s+=saveTreeToDir(tmpdir,prefix,writeflags,offset); insilmaril@721: else insilmaril@721: { insilmaril@788: switch (saveSel->getType()) insilmaril@788: { insilmaril@788: case TreeItem::Branch: insilmaril@788: // Save Subtree insilmaril@788: s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset); insilmaril@788: break; insilmaril@788: case TreeItem::MapCenter: insilmaril@788: // Save Subtree insilmaril@788: s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset); insilmaril@788: break; insilmaril@788: case TreeItem::Image: insilmaril@788: // Save Image insilmaril@788: s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix); insilmaril@788: break; insilmaril@790: default: insilmaril@790: // other types shouldn't be safed directly... insilmaril@788: break; insilmaril@788: } insilmaril@721: } insilmaril@721: insilmaril@721: // Save local settings insilmaril@721: s+=settings.getDataXML (destPath); insilmaril@721: insilmaril@721: // Save selection insilmaril@759: if (getSelectedItem() && !saveSel ) insilmaril@759: s+=xml.valueElement("select",getSelectString()); insilmaril@726: insilmaril@726: xml.decIndent(); insilmaril@726: s+=xml.endElement("vymmap"); insilmaril@721: insilmaril@776: //cout << s.toStdString() << endl; insilmaril@776: insilmaril@772: if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags); insilmaril@721: return s; insilmaril@650: } insilmaril@650: insilmaril@754: QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons) insilmaril@745: { insilmaril@745: QString s; insilmaril@745: insilmaril@757: for (int i=0; ibranchCount(); i++) insilmaril@773: s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset); insilmaril@745: return s; insilmaril@745: } insilmaril@745: 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@746: // FIXME-2 VM not needed??? model->setMapEditor(this); insilmaril@721: // (map state is set later at end of load...) insilmaril@721: } else insilmaril@721: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@753: if (!bi) return aborted; insilmaril@721: if (lmode==ImportAdd) insilmaril@721: saveStateChangingPart( insilmaril@753: bi, insilmaril@753: bi, insilmaril@721: QString("addMapInsert (%1)").arg(fname), insilmaril@753: QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi))); insilmaril@721: else insilmaril@721: saveStateChangingPart( insilmaril@753: bi, insilmaril@753: bi, insilmaril@721: QString("addMapReplace(%1)").arg(fname), insilmaril@753: QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi))); 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@762: mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate); 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@762: mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate); insilmaril@721: file.close(); insilmaril@721: if ( ok ) insilmaril@721: { insilmaril@746: reposition(); // FIXME-2 VM reposition the view instead... insilmaril@775: emitSelectionChanged(); 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@773: if (savemode==CompleteMap || selModel->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@787: 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@795: 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@788: bool VymModel::addMapInsertInt (const QString &path) insilmaril@788: { insilmaril@788: QString pathDir=path.left(path.findRev("/")); insilmaril@788: QDir d(pathDir); insilmaril@788: QFile file (path); insilmaril@788: insilmaril@788: if (d.exists() ) insilmaril@721: { insilmaril@788: // We need to parse saved XML data insilmaril@788: parseVYMHandler handler; insilmaril@788: QXmlInputSource source( file); insilmaril@788: QXmlSimpleReader reader; insilmaril@788: reader.setContentHandler( &handler ); insilmaril@788: reader.setErrorHandler( &handler ); insilmaril@788: handler.setModel (this); insilmaril@788: handler.setTmpDir ( pathDir ); // needed to load files with rel. path insilmaril@788: handler.setLoadMode (ImportAdd); insilmaril@788: blockReposition=true; insilmaril@788: bool ok = reader.parse( source ); insilmaril@788: blockReposition=false; insilmaril@788: if ( ok ) return true; insilmaril@788: { insilmaril@788: // This should never ever happen insilmaril@788: QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), insilmaril@788: handler.errorProtocol()); insilmaril@788: } insilmaril@788: } else insilmaril@788: QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); insilmaril@788: return false; insilmaril@788: } insilmaril@788: insilmaril@788: bool VymModel::addMapInsertInt (const QString &path, int pos) insilmaril@788: { insilmaril@788: BranchItem *selbi=getSelectedBranch(); insilmaril@788: if (selbi) insilmaril@788: { insilmaril@788: if (addMapInsertInt (path)) insilmaril@721: { insilmaril@788: if (selbi->depth()>0) insilmaril@788: relinkBranch (selbi->getLastBranch(), selbi,pos); insilmaril@788: return true; insilmaril@788: } else insilmaril@788: { insilmaril@721: QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); insilmaril@788: return false; insilmaril@788: } insilmaril@721: } insilmaril@788: qWarning ("ME::addMapInsertInt nothing selected"); insilmaril@788: return false; insilmaril@721: } insilmaril@721: insilmaril@776: ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn) insilmaril@776: { insilmaril@776: ImageItem *ii=createImage(dst); insilmaril@776: if (ii) insilmaril@721: { insilmaril@776: ii->load (fn); insilmaril@721: reposition(); insilmaril@776: return ii; insilmaril@721: } insilmaril@721: return NULL; insilmaril@740: } insilmaril@721: insilmaril@775: void VymModel::loadFloatImage () insilmaril@775: { insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@775: if (selbi) insilmaril@721: { insilmaril@721: insilmaril@775: Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog 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@776: ImageItem *ii; insilmaril@721: for (int j=0; jselectedFiles().count(); j++) insilmaril@721: { insilmaril@721: s=fd->selectedFiles().at(j); insilmaril@776: ii=loadFloatImageInt (selbi,s); insilmaril@776: //FIXME-3 check savestate for loadImage insilmaril@776: if (ii) insilmaril@721: saveState( insilmaril@776: (TreeItem*)ii, insilmaril@721: "delete ()", insilmaril@775: selbi, insilmaril@721: QString ("loadImage (%1)").arg(s ), insilmaril@775: QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi)) 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@776: void VymModel::saveFloatImageInt (ImageItem *ii, const QString &type, const QString &fn) insilmaril@776: { insilmaril@776: ii->save (fn,type); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::saveFloatImage () insilmaril@721: { insilmaril@787: ImageItem *ii=getSelectedImage(); insilmaril@776: if (ii) 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@776: saveFloatImageInt (ii,fd->selectedFilter(),fn ); insilmaril@721: } insilmaril@721: delete (fd); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@791: void VymModel::importDirInt(BranchItem *dst, QDir d) insilmaril@791: { insilmaril@791: BranchItem *selbi=getSelectedBranch(); insilmaril@791: BranchItem *bi; insilmaril@791: if (selbi) 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@791: bi=addNewBranchInt(dst,-2); insilmaril@749: bi->setHeading (fi.fileName() ); // FIXME-3 check this insilmaril@791: bi->setHeadingColor (QColor("blue")); insilmaril@749: bi->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@791: importDirInt (bi,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@791: bi=addNewBranchInt (dst,-2); insilmaril@791: bi->setHeading (fi.fileName() ); insilmaril@791: bi->setHeadingColor (QColor("black")); insilmaril@721: if (fi.fileName().right(4) == ".vym" ) insilmaril@791: bi->setVymLink (fi.filePath()); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@791: void VymModel::importDirInt (const QString &s) insilmaril@791: { insilmaril@791: BranchItem *selbi=getSelectedBranch(); insilmaril@791: if (selbi) insilmaril@721: { insilmaril@791: saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s)); insilmaril@721: insilmaril@721: QDir d(s); insilmaril@791: importDirInt (selbi,d); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@791: void VymModel::importDir() //FIXME-3 check me... (not tested yet) insilmaril@791: { insilmaril@791: BranchItem *selbi=getSelectedBranch(); insilmaril@791: if (selbi) 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@746: //FIXME-3 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@746: // FIXME-2 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@721: if (!mapChanged) insilmaril@742: autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt()); insilmaril@721: mapChanged=true; insilmaril@721: mapDefault=false; insilmaril@721: mapUnsaved=true; insilmaril@761: latestAddedItem=NULL; insilmaril@721: findReset(); insilmaril@721: } insilmaril@721: insilmaril@776: QString VymModel::getObjectName (LinkableMapObj *lmo) // FIXME-3 should be obsolete insilmaril@776: { insilmaril@776: if (!lmo || !lmo->getTreeItem() ) return QString(); insilmaril@776: return getObjectName (lmo->getTreeItem() ); insilmaril@721: } insilmaril@721: insilmaril@753: insilmaril@776: QString VymModel::getObjectName (TreeItem *ti) insilmaril@753: { insilmaril@753: QString s; insilmaril@753: if (!ti) return QString("Error: NULL has no name!"); insilmaril@776: s=ti->getHeading(); insilmaril@776: if (s=="") s="unnamed"; insilmaril@776: insilmaril@788: return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s); insilmaril@753: } insilmaril@753: 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@794: if (!select (undoSelection)) insilmaril@794: { insilmaril@794: qWarning ("VymModel::undo() Could not select object for undo"); insilmaril@794: return; insilmaril@794: } insilmaril@721: insilmaril@811: insilmaril@721: if (debug) insilmaril@721: { insilmaril@721: cout << "VymModel::undo() begin\n"; insilmaril@721: cout << " undosAvail="<updateHistory (undoSet); insilmaril@721: updateActions(); insilmaril@795: //emitSelectionChanged(); 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@760: 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@753: void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* 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@760: void VymModel::saveStateRemovingPart(TreeItem* 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@788: QString undoSelection; insilmaril@721: QString redoSelection=getSelectString(redoSel); insilmaril@753: if (redoSel->getType()==TreeItem::Branch) insilmaril@721: { insilmaril@788: undoSelection=getSelectString (redoSel->parent()); insilmaril@721: // save the selected branch of the map, Undo will insert part of map insilmaril@721: saveState (PartOfMap, insilmaril@753: undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()), insilmaril@721: redoSelection, "delete ()", insilmaril@721: comment, insilmaril@721: redoSel); insilmaril@721: } insilmaril@788: if (redoSel->getType()==TreeItem::MapCenter) insilmaril@788: { insilmaril@788: // save the selected branch of the map, Undo will insert part of map insilmaril@788: saveState (PartOfMap, insilmaril@788: undoSelection, QString("addMapInsert (\"PATH\")"), insilmaril@788: redoSelection, "delete ()", insilmaril@788: comment, insilmaril@788: redoSel); insilmaril@788: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@753: void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *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@761: TreeItem* VymModel::findBySelectString(QString s) insilmaril@761: { insilmaril@761: if (s.isEmpty() ) return NULL; insilmaril@761: insilmaril@761: // Old maps don't have multiple mapcenters and don't save full path insilmaril@761: if (s.left(2) !="mc") insilmaril@761: s="mc:0,"+s; insilmaril@761: insilmaril@761: QStringList parts=s.split (","); insilmaril@761: QString typ; insilmaril@761: int n; insilmaril@761: TreeItem *ti=rootItem; insilmaril@761: insilmaril@761: while (!parts.isEmpty() ) insilmaril@650: { insilmaril@761: typ=parts.first().left(2); insilmaril@761: n=parts.first().right(parts.first().length() - 3).toInt(); insilmaril@761: parts.removeFirst(); insilmaril@761: if (typ=="mc" || typ=="bo") insilmaril@761: ti=ti->getBranchNum (n); insilmaril@794: else if (typ=="fi") insilmaril@794: ti=ti->getImageNum (n); insilmaril@794: else if (typ=="ai") insilmaril@794: ti=ti->getAttributeNum (n); insilmaril@794: else if (typ=="xl") insilmaril@794: ti=ti->getXLinkNum (n); insilmaril@791: if(!ti) return NULL; insilmaril@761: } insilmaril@761: return ti; insilmaril@650: } insilmaril@650: insilmaril@795: TreeItem* VymModel::findID (const QString &s) //FIXME-4 Search also other types... insilmaril@754: { insilmaril@790: BranchItem *cur=NULL; insilmaril@790: BranchItem *prev=NULL; insilmaril@804: nextBranch(cur,prev); insilmaril@790: while (cur) insilmaril@650: { insilmaril@790: if (s==cur->getID() ) return cur; insilmaril@804: nextBranch(cur,prev); insilmaril@790: } insilmaril@650: return NULL; 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: 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: 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@776: int VymModel::branchCount() // FIXME-4 Optimize this: use internal counter instead of going through whole map each time... insilmaril@742: { insilmaril@742: int c=0; insilmaril@750: BranchItem *cur=NULL; insilmaril@750: BranchItem *prev=NULL; insilmaril@804: nextBranch(cur,prev); insilmaril@742: while (cur) insilmaril@742: { insilmaril@742: c++; insilmaril@804: nextBranch(cur,prev); insilmaril@742: } insilmaril@742: return c; insilmaril@742: } insilmaril@742: insilmaril@800: void VymModel::setSortFilter (const QString &s) insilmaril@800: { insilmaril@800: sortFilter=s; insilmaril@800: emit (sortFilterChanged (sortFilter)); insilmaril@800: } insilmaril@800: insilmaril@800: QString VymModel::getSortFilter () insilmaril@800: { insilmaril@800: return sortFilter; insilmaril@800: } insilmaril@800: insilmaril@721: void VymModel::setHeading(const QString &s) insilmaril@721: { insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@753: if (selbi) insilmaril@721: { insilmaril@721: saveState( insilmaril@753: selbi, insilmaril@753: "setHeading (\""+selbi->getHeading()+"\")", insilmaril@753: selbi, insilmaril@721: "setHeading (\""+s+"\")", insilmaril@753: QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) ); insilmaril@753: selbi->setHeading(s ); insilmaril@767: emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem? insilmaril@721: reposition(); insilmaril@775: emitSelectionChanged(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@784: QString VymModel::getHeading() insilmaril@784: { insilmaril@784: TreeItem *selti=getSelectedItem(); insilmaril@784: if (selti) insilmaril@784: return selti->getHeading(); insilmaril@784: else insilmaril@784: return QString(); insilmaril@784: } insilmaril@784: insilmaril@804: void VymModel::setNote(const QString &s) //FIXME-2 savestate missing // FIXME-2 call to VM::updateNoteFlag missing (fix signal handling here) insilmaril@804: { insilmaril@804: TreeItem *selti=getSelectedItem(); insilmaril@804: if (selti) insilmaril@804: { insilmaril@804: selti->setNote(s); insilmaril@804: emitNoteHasChanged(selti); insilmaril@804: } insilmaril@804: } insilmaril@804: insilmaril@804: QString VymModel::getNote() insilmaril@804: { insilmaril@804: TreeItem *selti=getSelectedItem(); insilmaril@804: if (selti) insilmaril@804: return selti->getNote(); insilmaril@804: else insilmaril@804: return QString(); insilmaril@804: } insilmaril@804: insilmaril@753: BranchItem* VymModel::findText (QString s, bool cs) insilmaril@721: { insilmaril@811: if (!s.isEmpty() && s!=findString) insilmaril@811: { insilmaril@811: findReset(); insilmaril@811: findString=s; insilmaril@811: } insilmaril@811: insilmaril@721: QTextDocument::FindFlags flags=0; insilmaril@721: if (cs) flags=QTextDocument::FindCaseSensitively; insilmaril@721: insilmaril@741: if (!findCurrent) insilmaril@721: { // Nothing found or new find process insilmaril@721: if (EOFind) insilmaril@721: // nothing found, start again insilmaril@721: EOFind=false; insilmaril@741: findCurrent=NULL; insilmaril@741: findPrevious=NULL; insilmaril@804: nextBranch (findCurrent,findPrevious); insilmaril@721: } insilmaril@721: bool searching=true; insilmaril@721: bool foundNote=false; insilmaril@721: while (searching && !EOFind) insilmaril@721: { insilmaril@741: if (findCurrent) insilmaril@721: { insilmaril@721: // Searching in Note insilmaril@811: if (findCurrent->getNote().contains(findString,cs)) insilmaril@721: { insilmaril@741: select (findCurrent); insilmaril@741: /* insilmaril@735: if (getSelectedBranch()!=itFind) insilmaril@721: { insilmaril@735: select(itFind); insilmaril@763: emitShowSelection(); insilmaril@721: } insilmaril@741: */ insilmaril@811: if (textEditor->findText(findString,flags)) insilmaril@721: { insilmaril@721: searching=false; insilmaril@721: foundNote=true; insilmaril@721: } insilmaril@721: } insilmaril@721: // Searching in Heading insilmaril@811: if (searching && findCurrent->getHeading().contains (findString,cs) ) insilmaril@721: { insilmaril@741: select(findCurrent); insilmaril@721: searching=false; insilmaril@721: } insilmaril@721: } insilmaril@721: if (!foundNote) insilmaril@721: { insilmaril@804: if (!nextBranch(findCurrent,findPrevious) ) insilmaril@741: EOFind=true; insilmaril@721: } insilmaril@721: //cout <<"still searching... "<getHeading())<getURL(); insilmaril@767: selti->setURL (url); insilmaril@721: saveState ( insilmaril@767: selti, insilmaril@721: QString ("setURL (\"%1\")").arg(oldurl), insilmaril@767: selti, insilmaril@721: QString ("setURL (\"%1\")").arg(url), insilmaril@767: QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url) insilmaril@721: ); insilmaril@721: reposition(); insilmaril@767: emitDataHasChanged (selti); insilmaril@763: emitShowSelection(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@767: QString VymModel::getURL() insilmaril@767: { insilmaril@767: TreeItem *selti=getSelectedItem(); insilmaril@767: if (selti) insilmaril@767: return selti->getURL(); insilmaril@767: else insilmaril@767: return QString(); insilmaril@721: } insilmaril@721: insilmaril@771: QStringList VymModel::getURLs() insilmaril@771: { insilmaril@721: QStringList urls; insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@773: BranchItem *cur=selbi; insilmaril@771: BranchItem *prev=NULL; insilmaril@771: while (cur) insilmaril@771: { insilmaril@771: if (!cur->getURL().isEmpty()) urls.append( cur->getURL()); insilmaril@804: cur=nextBranch (cur,prev,true,selbi); insilmaril@721: } insilmaril@721: return urls; insilmaril@721: } insilmaril@721: insilmaril@777: insilmaril@777: void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-4 not saved if there is no LMO insilmaril@777: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@777: if (bi) insilmaril@721: { insilmaril@777: BranchObj *bo=(BranchObj*)(bi->getLMO()); insilmaril@777: if (bo) insilmaril@777: { insilmaril@777: QString s=bo->getFrameTypeName(); insilmaril@777: bo->setFrameType (t); insilmaril@777: saveState (bi, QString("setFrameType (\"%1\")").arg(s), insilmaril@777: bi, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s)); insilmaril@777: reposition(); insilmaril@779: bo->updateLinkGeometry(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@777: void VymModel::setFrameType(const QString &s) //FIXME-4 not saved if there is no LMO insilmaril@777: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@777: if (bi) insilmaril@777: { insilmaril@777: BranchObj *bo=(BranchObj*)(bi->getLMO()); insilmaril@777: if (bo) insilmaril@777: { insilmaril@777: saveState (bi, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()), insilmaril@777: bi, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s)); insilmaril@777: bo->setFrameType (s); insilmaril@777: reposition(); insilmaril@779: bo->updateLinkGeometry(); insilmaril@777: } insilmaril@777: } insilmaril@777: } insilmaril@777: insilmaril@777: void VymModel::setFramePenColor(const QColor &c) //FIXME-4 not saved if there is no LMO insilmaril@777: insilmaril@777: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@777: if (bi) insilmaril@777: { insilmaril@777: BranchObj *bo=(BranchObj*)(bi->getLMO()); insilmaril@777: if (bo) insilmaril@777: { insilmaril@777: saveState (bi, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ), insilmaril@777: bi, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() )); insilmaril@777: bo->setFramePenColor (c); insilmaril@777: } insilmaril@777: } insilmaril@777: } insilmaril@777: insilmaril@777: void VymModel::setFrameBrushColor(const QColor &c) //FIXME-4 not saved if there is no LMO insilmaril@777: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@777: if (bi) insilmaril@777: { insilmaril@777: BranchObj *bo=(BranchObj*)(bi->getLMO()); insilmaril@777: if (bo) insilmaril@777: { insilmaril@777: saveState (bi, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ), insilmaril@777: bi, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() )); insilmaril@777: bo->setFrameBrushColor (c); insilmaril@777: } insilmaril@777: } insilmaril@777: } insilmaril@777: insilmaril@777: void VymModel::setFramePadding (const int &i) //FIXME-4 not saved if there is no LMO insilmaril@777: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@777: if (bi) insilmaril@777: { insilmaril@777: BranchObj *bo=(BranchObj*)(bi->getLMO()); insilmaril@777: if (bo) insilmaril@777: { insilmaril@777: saveState (bi, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ), insilmaril@777: bi, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i)); insilmaril@777: bo->setFramePadding (i); insilmaril@777: reposition(); insilmaril@779: bo->updateLinkGeometry(); insilmaril@777: } insilmaril@777: } insilmaril@777: } insilmaril@777: insilmaril@777: void VymModel::setFrameBorderWidth(const int &i) //FIXME-4 not saved if there is no LMO insilmaril@777: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@777: if (bi) insilmaril@777: { insilmaril@777: BranchObj *bo=(BranchObj*)(bi->getLMO()); insilmaril@777: if (bo) insilmaril@777: { insilmaril@777: saveState (bi, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ), insilmaril@777: bi, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i)); insilmaril@777: bo->setFrameBorderWidth (i); insilmaril@777: reposition(); insilmaril@779: bo->updateLinkGeometry(); insilmaril@777: } insilmaril@777: } insilmaril@777: } insilmaril@777: insilmaril@785: void VymModel::setIncludeImagesVer(bool b) insilmaril@785: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@785: if (bi) insilmaril@721: { insilmaril@785: QString u= b ? "false" : "true"; insilmaril@785: QString r=!b ? "false" : "true"; insilmaril@785: insilmaril@785: saveState( insilmaril@785: bi, insilmaril@785: QString("setIncludeImagesVertically (%1)").arg(u), insilmaril@785: bi, insilmaril@785: QString("setIncludeImagesVertically (%1)").arg(r), insilmaril@785: QString("Include images vertically in %1").arg(getObjectName(bi)) insilmaril@785: ); insilmaril@785: bi->setIncludeImagesVer(b); insilmaril@785: emitDataHasChanged ( bi); insilmaril@785: reposition(); insilmaril@721: } insilmaril@785: } insilmaril@785: insilmaril@785: void VymModel::setIncludeImagesHor(bool b) insilmaril@785: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@785: if (bi) insilmaril@721: { insilmaril@785: QString u= b ? "false" : "true"; insilmaril@785: QString r=!b ? "false" : "true"; insilmaril@785: insilmaril@785: saveState( insilmaril@785: bi, insilmaril@785: QString("setIncludeImagesHorizontally (%1)").arg(u), insilmaril@785: bi, insilmaril@785: QString("setIncludeImagesHorizontally (%1)").arg(r), insilmaril@785: QString("Include images horizontally in %1").arg(getObjectName(bi)) insilmaril@785: ); insilmaril@785: bi->setIncludeImagesHor(b); insilmaril@785: emitDataHasChanged ( bi); insilmaril@785: reposition(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::setHideLinkUnselected (bool b)//FIXME-2 insilmaril@753: { insilmaril@779: TreeItem *ti=getSelectedItem(); insilmaril@779: if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType())) insilmaril@721: { insilmaril@721: QString u= b ? "false" : "true"; insilmaril@721: QString r=!b ? "false" : "true"; insilmaril@721: insilmaril@721: saveState( insilmaril@779: ti, insilmaril@721: QString("setHideLinkUnselected (%1)").arg(u), insilmaril@779: ti, insilmaril@721: QString("setHideLinkUnselected (%1)").arg(r), insilmaril@779: QString("Hide link of %1 if unselected").arg(getObjectName(ti)) insilmaril@721: ); insilmaril@779: ((MapItem*)ti)->setHideLinkUnselected(b); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setHideExport(bool b) insilmaril@721: { insilmaril@777: TreeItem *ti=getSelectedItem(); insilmaril@777: if (ti && insilmaril@777: (ti->getType()==TreeItem::Image ||ti->isBranchLikeType())) insilmaril@721: { insilmaril@777: ti->setHideInExport (b); insilmaril@721: QString u= b ? "false" : "true"; insilmaril@721: QString r=!b ? "false" : "true"; insilmaril@721: insilmaril@721: saveState( insilmaril@777: ti, insilmaril@721: QString ("setHideExport (%1)").arg(u), insilmaril@777: ti, insilmaril@721: QString ("setHideExport (%1)").arg(r), insilmaril@777: QString ("Set HideExport flag of %1 to %2").arg(getObjectName(ti)).arg (r) insilmaril@721: ); insilmaril@777: emitDataHasChanged(ti); insilmaril@776: emitSelectionChanged(); insilmaril@721: updateActions(); insilmaril@721: reposition(); insilmaril@775: // emitSelectionChanged(); insilmaril@746: // FIXME-3 VM needed? scene()->update(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::toggleHideExport() insilmaril@721: { insilmaril@776: TreeItem *selti=getSelectedItem(); insilmaril@776: if (selti) insilmaril@776: setHideExport ( !selti->hideInExport() ); insilmaril@721: } insilmaril@721: insilmaril@804: void VymModel::addTimestamp() //FIXME-3 new function, localize insilmaril@804: { insilmaril@804: BranchItem *selbi=addNewBranch(); insilmaril@804: if (selbi) insilmaril@804: { insilmaril@804: QDate today=QDate::currentDate(); insilmaril@804: QChar c='0'; insilmaril@804: selbi->setHeading (QString ("%1-%2-%3") insilmaril@804: .arg(today.year(),4,10,c) insilmaril@804: .arg(today.month(),2,10,c) insilmaril@804: .arg(today.day(),2,10,c)); insilmaril@804: emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem? insilmaril@804: reposition(); insilmaril@804: select (selbi); insilmaril@804: } insilmaril@804: } insilmaril@804: insilmaril@721: insilmaril@767: void VymModel::copy() insilmaril@767: { insilmaril@767: TreeItem *selti=getSelectedItem(); insilmaril@767: if (selti && insilmaril@767: (selti->getType() == TreeItem::Branch || insilmaril@767: selti->getType() == TreeItem::MapCenter || insilmaril@767: selti->getType() == TreeItem::Image )) insilmaril@721: { insilmaril@721: if (redosAvail == 0) insilmaril@721: { insilmaril@721: // Copy to history insilmaril@767: QString s=getSelectString(selti); insilmaril@767: saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",selti ); 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@767: void VymModel::pasteNoSave(const int &n) insilmaril@767: { 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@767: void VymModel::paste() insilmaril@721: { insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@767: if (selbi) insilmaril@721: { insilmaril@721: saveStateChangingPart( insilmaril@767: selbi, insilmaril@767: selbi, insilmaril@721: QString ("paste (%1)").arg(curClipboard), insilmaril@767: QString("Paste to %1").arg( getObjectName(selbi)) insilmaril@721: ); insilmaril@721: pasteNoSave(0); insilmaril@721: reposition(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@767: void VymModel::cut() insilmaril@767: { insilmaril@767: TreeItem *selti=getSelectedItem(); insilmaril@767: if ( selti && (selti->isBranchLikeType() ||selti->getType()==TreeItem::Image)) insilmaril@721: { insilmaril@721: copy(); insilmaril@721: deleteSelection(); insilmaril@721: reposition(); insilmaril@721: } insilmaril@767: } insilmaril@767: insilmaril@795: bool VymModel::moveUp(BranchItem *bi) //FIXME-2 crashes if trying to move MCO insilmaril@795: { insilmaril@795: if (bi && bi->canMoveUp()) insilmaril@795: return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1); insilmaril@795: else insilmaril@795: return false; insilmaril@795: } insilmaril@795: insilmaril@795: void VymModel::moveUp() insilmaril@767: { insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@767: if (selbi) insilmaril@721: { insilmaril@767: QString oldsel=getSelectString(); insilmaril@795: if (moveUp (selbi)) insilmaril@795: saveState ( insilmaril@795: getSelectString(),"moveDown ()", insilmaril@795: oldsel,"moveUp ()", insilmaril@795: QString("Move up %1").arg(getObjectName(selbi))); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@795: bool VymModel::moveDown(BranchItem *bi) insilmaril@795: { insilmaril@795: if (bi && bi->canMoveDown()) insilmaril@795: return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1); insilmaril@795: else insilmaril@795: return false; insilmaril@795: } insilmaril@795: insilmaril@767: void VymModel::moveDown() insilmaril@767: { insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@767: if (selbi) insilmaril@721: { insilmaril@767: QString oldsel=getSelectString(); insilmaril@795: if ( moveDown(selbi)) insilmaril@795: saveState ( insilmaril@795: getSelectString(),"moveUp ()", insilmaril@795: oldsel,"moveDown ()", insilmaril@795: QString("Move down %1").arg(getObjectName(selbi))); insilmaril@767: } insilmaril@721: } insilmaril@721: insilmaril@795: void VymModel::detach() insilmaril@795: { insilmaril@795: BranchItem *selbi=getSelectedBranch(); insilmaril@795: if (selbi && selbi->depth()>0) insilmaril@721: { insilmaril@798: // if no relPos have been set before, try to use current rel positions insilmaril@798: if (selbi->getLMO()) insilmaril@798: for (int i=0; ibranchCount();++i) insilmaril@798: selbi->getBranchNum(i)->getBranchObj()->setRelPos(); insilmaril@798: insilmaril@795: //QString oldsel=getSelectString(); insilmaril@795: if ( relinkBranch (selbi,rootItem,-1) ) insilmaril@795: saveState ( insilmaril@798: selbi,QString("relink()"), //FIXME-1 add paramters when detaching insilmaril@795: selbi,"detach ()", insilmaril@795: QString("Detach %1").arg(getObjectName(selbi)) insilmaril@795: ); insilmaril@795: } insilmaril@795: } insilmaril@795: insilmaril@795: void VymModel::sortChildren() insilmaril@795: { insilmaril@795: BranchItem* selbi=getSelectedBranch(); insilmaril@795: if (selbi) insilmaril@795: { insilmaril@795: if(selbi->branchCount()>1) insilmaril@721: { insilmaril@795: saveStateChangingPart( insilmaril@795: selbi,selbi, "sortChildren ()", insilmaril@795: QString("Sort children of %1").arg(getObjectName(selbi))); insilmaril@795: selbi->sortChildren(); insilmaril@721: reposition(); insilmaril@763: emitShowSelection(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@773: BranchItem* VymModel::createMapCenter() insilmaril@773: { insilmaril@773: BranchItem *newbi=addMapCenter (QPointF (0,0) ); insilmaril@773: return newbi; insilmaril@726: } insilmaril@726: insilmaril@775: BranchItem* VymModel::createBranch(BranchItem *dst) insilmaril@775: { insilmaril@775: if (dst) insilmaril@775: return addNewBranchInt (dst,-2); insilmaril@771: else insilmaril@771: return NULL; insilmaril@739: } insilmaril@739: insilmaril@776: ImageItem* VymModel::createImage(BranchItem *dst) insilmaril@776: { insilmaril@775: if (dst) insilmaril@726: { insilmaril@776: QModelIndex parix; insilmaril@776: int n; insilmaril@777: insilmaril@726: QList cData; insilmaril@790: cData << "new" << "undef"; insilmaril@777: insilmaril@777: ImageItem *newii=new ImageItem(cData) ; insilmaril@777: //newii->setHeading (QApplication::translate("Heading of new image in map", "new image")); insilmaril@776: insilmaril@776: emit (layoutAboutToBeChanged() ); insilmaril@776: insilmaril@776: parix=index(dst); insilmaril@791: if (!parix.isValid()) cout << "VM::createII invalid index\n"; insilmaril@776: n=dst->getRowNumAppend(newii); insilmaril@791: beginInsertRows (parix,n,n); insilmaril@776: dst->appendChild (newii); insilmaril@776: endInsertRows (); insilmaril@776: insilmaril@776: emit (layoutChanged() ); insilmaril@776: insilmaril@776: // save scroll state. If scrolled, automatically select insilmaril@776: // new branch in order to tmp unscroll parent... insilmaril@776: newii->createMapObj(mapScene); insilmaril@776: reposition(); insilmaril@776: return newii; insilmaril@776: } insilmaril@776: return NULL; insilmaril@726: } insilmaril@726: insilmaril@790: XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO) insilmaril@790: { insilmaril@790: if (bi) insilmaril@790: { insilmaril@790: QModelIndex parix; insilmaril@790: int n; insilmaril@790: insilmaril@790: QList cData; insilmaril@790: cData << "new xLink"<<"undef"; insilmaril@790: insilmaril@790: XLinkItem *newxli=new XLinkItem(cData) ; insilmaril@791: newxli->setBegin (bi); insilmaril@790: insilmaril@790: emit (layoutAboutToBeChanged() ); insilmaril@790: insilmaril@790: parix=index(bi); insilmaril@790: n=bi->getRowNumAppend(newxli); insilmaril@791: beginInsertRows (parix,n,n); insilmaril@790: bi->appendChild (newxli); insilmaril@790: endInsertRows (); insilmaril@790: insilmaril@790: emit (layoutChanged() ); insilmaril@790: insilmaril@790: // save scroll state. If scrolled, automatically select insilmaril@790: // new branch in order to tmp unscroll parent... insilmaril@790: if (createMO) insilmaril@790: { insilmaril@790: newxli->createMapObj(mapScene); insilmaril@790: reposition(); insilmaril@790: } insilmaril@790: return newxli; insilmaril@790: } insilmaril@790: return NULL; insilmaril@790: } insilmaril@790: insilmaril@788: AttributeItem* VymModel::addAttribute() // FIXME-2 savestate missing insilmaril@788: { insilmaril@788: BranchItem *selbi=getSelectedBranch(); insilmaril@788: if (selbi) insilmaril@786: { insilmaril@786: QList cData; insilmaril@790: cData << "new attribute" << "undef"; insilmaril@786: AttributeItem *a=new AttributeItem (cData); insilmaril@786: insilmaril@786: emit (layoutAboutToBeChanged() ); insilmaril@786: insilmaril@788: QModelIndex parix=index(selbi); insilmaril@788: int n=selbi->getRowNumAppend (a); insilmaril@791: beginInsertRows (parix,n,n); insilmaril@788: selbi->appendChild (a); insilmaril@786: endInsertRows (); insilmaril@786: insilmaril@786: emit (layoutChanged() ); insilmaril@786: insilmaril@786: reposition(); insilmaril@786: return a; insilmaril@786: } insilmaril@786: return NULL; insilmaril@786: } insilmaril@786: insilmaril@773: BranchItem* VymModel::addMapCenter () insilmaril@773: { insilmaril@773: BranchItem *bi=addMapCenter (contextPos); insilmaril@721: updateActions(); insilmaril@763: emitShowSelection(); insilmaril@721: saveState ( insilmaril@773: bi, insilmaril@721: "delete()", insilmaril@721: NULL, insilmaril@723: QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()), insilmaril@723: QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y()) insilmaril@721: ); insilmaril@773: return bi; insilmaril@721: } insilmaril@721: insilmaril@791: BranchItem* VymModel::addMapCenter(QPointF absPos) insilmaril@775: // createMapCenter could then probably be merged with createBranch insilmaril@721: { insilmaril@749: insilmaril@749: // Create TreeItem insilmaril@749: QModelIndex parix=index(rootItem); insilmaril@749: insilmaril@749: QList cData; insilmaril@790: cData << "VM:addMapCenter" << "undef"; insilmaril@788: BranchItem *newbi=new BranchItem (cData,rootItem); insilmaril@773: newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); insilmaril@791: int n=rootItem->getRowNumAppend (newbi); insilmaril@791: insilmaril@791: emit (layoutAboutToBeChanged() ); insilmaril@791: beginInsertRows (parix,n,n); insilmaril@791: insilmaril@773: rootItem->appendChild (newbi); insilmaril@749: insilmaril@749: endInsertRows(); insilmaril@749: emit (layoutChanged() ); insilmaril@749: insilmaril@749: // Create MapObj insilmaril@775: newbi->setPositionMode (MapItem::Absolute); insilmaril@791: BranchObj *bo=newbi->createMapObj(mapScene); insilmaril@791: if (bo) bo->move (absPos); insilmaril@760: insilmaril@773: return newbi; insilmaril@721: } insilmaril@721: insilmaril@791: BranchItem* VymModel::addNewBranchInt(BranchItem *dst,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@771: insilmaril@771: // Create TreeItem insilmaril@771: QList cData; insilmaril@803: cData << "" << "undef"; insilmaril@771: insilmaril@771: BranchItem *parbi; insilmaril@771: QModelIndex parix; insilmaril@771: int n; insilmaril@771: BranchItem *newbi=new BranchItem (cData); insilmaril@803: //newbi->setHeading (QApplication::translate("Heading of new branch in map", "new")); insilmaril@771: insilmaril@771: emit (layoutAboutToBeChanged() ); insilmaril@771: insilmaril@771: if (num==-2) insilmaril@721: { insilmaril@771: parbi=dst; insilmaril@771: parix=index(parbi); insilmaril@776: n=parbi->getRowNumAppend (newbi); insilmaril@791: beginInsertRows (parix,n,n); insilmaril@771: parbi->appendChild (newbi); insilmaril@771: endInsertRows (); insilmaril@772: }else if (num==-1 || num==-3) insilmaril@771: { insilmaril@771: // insert below selection insilmaril@771: parbi=(BranchItem*)dst->parent(); insilmaril@776: parix=index(parbi); insilmaril@776: insilmaril@776: n=dst->childNumber() + (3+num)/2; //-1 |-> 1;-3 |-> 0 insilmaril@771: beginInsertRows (parix,n,n); insilmaril@771: parbi->insertBranch(n,newbi); insilmaril@771: endInsertRows (); insilmaril@772: } insilmaril@771: emit (layoutChanged() ); insilmaril@771: insilmaril@803: // Set color of heading to that of parent insilmaril@803: newbi->setHeadingColor (parbi->getHeadingColor()); insilmaril@803: insilmaril@771: // save scroll state. If scrolled, automatically select insilmaril@771: // new branch in order to tmp unscroll parent... insilmaril@771: newbi->createMapObj(mapScene); insilmaril@772: reposition(); insilmaril@771: return newbi; insilmaril@721: } insilmaril@721: insilmaril@755: BranchItem* 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@755: BranchItem *newbi=NULL; insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@755: insilmaril@755: if (selbi) insilmaril@721: { insilmaril@771: // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed? insilmaril@771: insilmaril@771: newbi=addNewBranchInt (selbi,pos-2); insilmaril@755: insilmaril@755: if (newbi) insilmaril@721: { insilmaril@721: saveState( insilmaril@755: newbi, insilmaril@721: "delete ()", insilmaril@755: selbi, insilmaril@721: QString ("addBranch (%1)").arg(pos), insilmaril@755: QString ("Add new branch to %1").arg(getObjectName(selbi))); insilmaril@721: insilmaril@721: reposition(); insilmaril@775: // emitSelectionChanged(); FIXME-3 insilmaril@761: latestAddedItem=newbi; 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@755: /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos()); insilmaril@721: sendData ("selectLatestAdded ()"); insilmaril@721: sendData (QString("move %1").arg(ps)); insilmaril@721: sendSelection(); insilmaril@755: */ insilmaril@721: } insilmaril@721: } insilmaril@755: return newbi; insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@772: BranchItem* VymModel::addNewBranchBefore() insilmaril@771: { insilmaril@771: BranchItem *newbi=NULL; insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@771: if (selbi && selbi->getType()==TreeItem::Branch) insilmaril@771: // We accept no MapCenter here, so we _have_ a parent insilmaril@721: { insilmaril@771: //QPointF p=bo->getRelPos(); insilmaril@771: insilmaril@721: insilmaril@721: // add below selection insilmaril@771: newbi=addNewBranchInt (selbi,-1); insilmaril@771: insilmaril@771: if (newbi) insilmaril@721: { insilmaril@771: //newbi->move2RelPos (p); insilmaril@721: insilmaril@721: // Move selection to new branch insilmaril@771: relinkBranch (selbi,newbi,0); insilmaril@771: insilmaril@771: saveState (newbi, "deleteKeepChildren ()", newbi, "addBranchBefore ()", insilmaril@771: QString ("Add branch before %1").arg(getObjectName(selbi))); insilmaril@771: insilmaril@771: // FIXME-3 needed? reposition(); insilmaril@775: // emitSelectionChanged(); FIXME-3 insilmaril@721: } insilmaril@721: } insilmaril@771: return newbi; insilmaril@721: } insilmaril@721: insilmaril@767: bool VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos) insilmaril@755: { insilmaril@755: if (branch && dst) insilmaril@755: { insilmaril@804: unselect(); insilmaril@804: insilmaril@756: emit (layoutAboutToBeChanged() ); insilmaril@755: BranchItem *branchpi=(BranchItem*)branch->parent(); insilmaril@756: // Remove at current position insilmaril@756: int n=branch->childNum(); insilmaril@756: beginRemoveRows (index(branchpi),n,n); insilmaril@756: branchpi->removeChild (n); insilmaril@756: endRemoveRows(); insilmaril@756: insilmaril@756: if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount(); insilmaril@756: insilmaril@756: // Append as last branch to dst insilmaril@756: if (dst->branchCount()==0) insilmaril@756: n=0; insilmaril@756: else insilmaril@756: n=dst->getFirstBranch()->childNumber(); insilmaril@756: beginInsertRows (index(dst),n+pos,n+pos); insilmaril@756: dst->insertBranch (pos,branch); insilmaril@756: endInsertRows(); insilmaril@756: insilmaril@788: // Correct type if necessesary insilmaril@788: if (branch->getType()==TreeItem::MapCenter) insilmaril@788: branch->setType(TreeItem::Branch); insilmaril@788: insilmaril@773: // reset parObj, fonts, frame, etc in related LMO or other view-objects insilmaril@773: branch->updateStyles(); insilmaril@773: insilmaril@756: emit (layoutChanged() ); insilmaril@767: reposition(); // both for moveUp/Down and relinking insilmaril@781: if (dst->isScrolled() ) insilmaril@781: { insilmaril@781: select (dst); insilmaril@781: branch->updateVisibility(); insilmaril@781: } insilmaril@781: else insilmaril@781: select (branch); insilmaril@767: return true; insilmaril@755: } insilmaril@767: return false; insilmaril@755: } insilmaril@755: insilmaril@777: bool VymModel::relinkImage (ImageItem *image, BranchItem *dst) insilmaril@777: { insilmaril@777: if (image && dst) insilmaril@777: { insilmaril@777: emit (layoutAboutToBeChanged() ); insilmaril@777: insilmaril@777: BranchItem *pi=(BranchItem*)(image->parent()); insilmaril@777: QString oldParString=getSelectString (pi); insilmaril@777: // Remove at current position insilmaril@777: int n=image->childNum(); insilmaril@777: beginRemoveRows (index(pi),n,n); insilmaril@777: pi->removeChild (n); insilmaril@777: endRemoveRows(); insilmaril@777: insilmaril@777: // Add at dst insilmaril@777: QModelIndex dstix=index(dst); insilmaril@777: n=dst->getRowNumAppend (image); insilmaril@777: beginInsertRows (dstix,n,n+1); insilmaril@777: dst->appendChild (image); insilmaril@777: endInsertRows (); insilmaril@777: insilmaril@777: // Set new parent also for lmo insilmaril@777: if (image->getLMO() && dst->getLMO() ) insilmaril@777: image->getLMO()->setParObj (dst->getLMO() ); insilmaril@777: insilmaril@777: emit (layoutChanged() ); insilmaril@777: saveState( insilmaril@777: image, insilmaril@777: QString("relinkTo (\"%1\")").arg(oldParString), insilmaril@777: image, insilmaril@777: QString ("relinkTo (\"%1\")").arg(getSelectString (dst)), insilmaril@777: QString ("Relink floatimage to %1").arg(getObjectName(dst))); insilmaril@777: return true; insilmaril@777: } insilmaril@777: return false; insilmaril@777: } insilmaril@777: insilmaril@788: void VymModel::deleteSelection() insilmaril@721: { insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@753: insilmaril@788: if (selbi) insilmaril@804: { // Delete branch insilmaril@735: unselect(); insilmaril@760: saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi))); insilmaril@745: insilmaril@776: TreeItem *pi=deleteItem (selbi); insilmaril@776: if (pi) insilmaril@776: { insilmaril@776: select (pi); insilmaril@776: emitShowSelection(); insilmaril@776: } insilmaril@721: return; insilmaril@721: } insilmaril@788: TreeItem *ti=getSelectedItem(); insilmaril@790: if (ti) insilmaril@804: { // Delete other item insilmaril@787: TreeItem *pi=ti->parent(); insilmaril@790: if (!pi) return; insilmaril@790: if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute) insilmaril@790: { insilmaril@790: saveStateChangingPart( insilmaril@790: pi, insilmaril@790: ti, insilmaril@790: "delete ()", insilmaril@790: QString("Delete %1").arg(getObjectName(ti)) insilmaril@790: ); insilmaril@792: unselect(); insilmaril@792: deleteItem (ti); insilmaril@792: emitDataHasChanged (pi); insilmaril@792: select (pi); insilmaril@792: reposition(); insilmaril@792: emitShowSelection(); insilmaril@794: } else if (ti->getType()==TreeItem::XLink) insilmaril@794: { insilmaril@794: //FIXME-2 savestate missing insilmaril@794: deleteItem (ti); insilmaril@794: } else insilmaril@794: qWarning ("VymmModel::deleteSelection() unknown type?!"); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@787: void VymModel::deleteKeepChildren() //FIXME-3 does not work yet for mapcenters insilmaril@787: insilmaril@787: { insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@775: BranchItem *pi; insilmaril@775: if (selbi) insilmaril@721: { insilmaril@726: // Don't use this on mapcenter insilmaril@775: if (selbi->depth()<2) return; insilmaril@775: insilmaril@775: pi=(BranchItem*)(selbi->parent()); insilmaril@726: // Check if we have childs at all to keep insilmaril@775: if (selbi->branchCount()==0) insilmaril@726: { insilmaril@726: deleteSelection(); insilmaril@726: return; insilmaril@726: } insilmaril@726: insilmaril@775: QPointF p; insilmaril@775: if (selbi->getLMO()) p=selbi->getLMO()->getRelPos(); insilmaril@721: saveStateChangingPart( insilmaril@775: pi, insilmaril@775: selbi, insilmaril@721: "deleteKeepChildren ()", insilmaril@775: QString("Remove %1 and keep its children").arg(getObjectName(selbi)) insilmaril@721: ); insilmaril@721: insilmaril@775: QString sel=getSelectString(selbi); insilmaril@721: unselect(); insilmaril@776: int pos=selbi->num(); insilmaril@776: BranchItem *bi=selbi->getFirstBranch(); insilmaril@776: while (bi) insilmaril@776: { insilmaril@776: relinkBranch (bi,pi,pos); insilmaril@776: bi=selbi->getFirstBranch(); insilmaril@776: pos++; insilmaril@776: } insilmaril@776: deleteItem (selbi); insilmaril@721: reposition(); insilmaril@721: select (sel); insilmaril@775: BranchObj *bo=getSelectedBranchObj(); insilmaril@775: if (bo) insilmaril@775: { insilmaril@775: bo->move2RelPos (p); insilmaril@775: reposition(); insilmaril@775: } insilmaril@721: } insilmaril@775: } insilmaril@753: insilmaril@772: void VymModel::deleteChildren() insilmaril@772: insilmaril@772: { insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@772: if (selbi) insilmaril@721: { insilmaril@721: saveStateChangingPart( insilmaril@772: selbi, insilmaril@772: selbi, insilmaril@721: "deleteChildren ()", insilmaril@772: QString( "Remove children of branch %1").arg(getObjectName(selbi)) insilmaril@721: ); insilmaril@772: emit (layoutAboutToBeChanged() ); insilmaril@772: insilmaril@772: QModelIndex ix=index (selbi); insilmaril@772: int n=selbi->branchCount()-1; insilmaril@772: beginRemoveRows (ix,0,n); insilmaril@772: removeRows (0,n+1,ix); insilmaril@772: endRemoveRows(); insilmaril@781: if (selbi->isScrolled()) selbi->unScroll(); insilmaril@772: emit (layoutChanged() ); insilmaril@721: reposition(); insilmaril@721: } insilmaril@772: } insilmaril@721: insilmaril@776: TreeItem* VymModel::deleteItem (TreeItem *ti) insilmaril@776: { insilmaril@776: if (ti) insilmaril@776: { insilmaril@776: TreeItem *pi=ti->parent(); insilmaril@776: QModelIndex parentIndex=index(pi); insilmaril@776: insilmaril@776: emit (layoutAboutToBeChanged() ); insilmaril@776: insilmaril@776: int n=ti->childNum(); insilmaril@776: beginRemoveRows (parentIndex,n,n); insilmaril@776: removeRows (n,1,parentIndex); insilmaril@776: endRemoveRows(); insilmaril@776: reposition(); insilmaril@776: insilmaril@776: emit (layoutChanged() ); insilmaril@788: if (pi->depth()>=0) return pi; insilmaril@776: } insilmaril@776: return NULL; insilmaril@776: } insilmaril@776: insilmaril@795: void VymModel::clearItem (TreeItem *ti) insilmaril@795: { insilmaril@795: if (ti) insilmaril@795: { insilmaril@795: QModelIndex parentIndex=index(ti); insilmaril@795: if (!parentIndex.isValid()) return; insilmaril@795: insilmaril@795: int n=ti->childCount(); insilmaril@795: if (n==0) return; insilmaril@795: insilmaril@795: emit (layoutAboutToBeChanged() ); insilmaril@795: insilmaril@795: beginRemoveRows (parentIndex,0,n-1); insilmaril@795: removeRows (0,n,parentIndex); insilmaril@795: endRemoveRows(); insilmaril@795: reposition(); insilmaril@795: insilmaril@795: emit (layoutChanged() ); insilmaril@795: insilmaril@795: } insilmaril@795: return ; insilmaril@795: } insilmaril@795: insilmaril@749: bool VymModel::scrollBranch(BranchItem *bi) insilmaril@749: { insilmaril@749: if (bi) insilmaril@721: { insilmaril@749: if (bi->isScrolled()) return false; insilmaril@749: if (bi->branchCount()==0) return false; insilmaril@749: if (bi->depth()==0) return false; insilmaril@767: if (bi->toggleScroll()) insilmaril@767: { insilmaril@798: reposition(); insilmaril@767: QString u,r; insilmaril@767: r="scroll"; insilmaril@767: u="unscroll"; insilmaril@767: saveState( insilmaril@767: bi, insilmaril@767: QString ("%1 ()").arg(u), insilmaril@767: bi, insilmaril@767: QString ("%1 ()").arg(r), insilmaril@767: QString ("%1 %2").arg(r).arg(getObjectName(bi)) insilmaril@767: ); insilmaril@767: emitDataHasChanged(bi); insilmaril@775: emitSelectionChanged(); insilmaril@795: mapScene->update(); //Needed for _quick_ update, even in 1.13.x insilmaril@767: return true; insilmaril@767: } insilmaril@721: } insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@749: bool VymModel::unscrollBranch(BranchItem *bi) insilmaril@749: { insilmaril@749: if (bi) insilmaril@721: { insilmaril@763: if (!bi->isScrolled()) return false; insilmaril@749: if (bi->branchCount()==0) return false; insilmaril@749: if (bi->depth()==0) return false; insilmaril@795: if (bi->toggleScroll()) insilmaril@795: { insilmaril@795: reposition(); insilmaril@798: QString u,r; insilmaril@798: u="scroll"; insilmaril@798: r="unscroll"; insilmaril@798: saveState( insilmaril@798: bi, insilmaril@798: QString ("%1 ()").arg(u), insilmaril@798: bi, insilmaril@798: QString ("%1 ()").arg(r), insilmaril@798: QString ("%1 %2").arg(r).arg(getObjectName(bi)) insilmaril@798: ); insilmaril@798: emitDataHasChanged(bi); insilmaril@798: emitSelectionChanged(); insilmaril@795: mapScene->update(); //Needed for _quick_ update, even in 1.13.x insilmaril@798: return true; insilmaril@798: } insilmaril@795: } insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@767: void VymModel::toggleScroll() insilmaril@721: { insilmaril@787: BranchItem *bi=(BranchItem*)getSelectedBranch(); insilmaril@767: if (bi && bi->isBranchLikeType() ) insilmaril@721: { insilmaril@749: if (bi->isScrolled()) insilmaril@749: unscrollBranch (bi); insilmaril@721: else insilmaril@749: scrollBranch (bi); insilmaril@721: } insilmaril@795: // saveState & reposition are called in above functions insilmaril@721: } insilmaril@721: insilmaril@795: void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault insilmaril@795: { insilmaril@795: BranchItem *selbi=getSelectedBranch(); insilmaril@795: BranchItem *prev=NULL; insilmaril@795: BranchItem *cur=selbi; insilmaril@795: if (selbi) insilmaril@721: { insilmaril@795: saveStateChangingPart( insilmaril@795: selbi, insilmaril@795: selbi, insilmaril@795: QString ("unscrollChildren ()"), insilmaril@795: QString ("unscroll all children of %1").arg(getObjectName(selbi)) insilmaril@795: ); insilmaril@795: while (cur) insilmaril@721: { insilmaril@795: if (cur->isScrolled()) insilmaril@795: { insilmaril@795: cur->toggleScroll(); insilmaril@795: emitDataHasChanged (cur); insilmaril@721: } insilmaril@804: cur=nextBranch (cur,prev,true,selbi); insilmaril@795: } insilmaril@795: updateActions(); insilmaril@795: reposition(); insilmaril@721: } insilmaril@721: } insilmaril@746: insilmaril@804: void VymModel::emitExpandAll() insilmaril@763: { insilmaril@763: emit (expandAll() ); insilmaril@763: } insilmaril@763: insilmaril@804: void VymModel::emitExpandOneLevel() insilmaril@804: { insilmaril@804: emit (expandOneLevel () ); insilmaril@804: } insilmaril@804: insilmaril@804: void VymModel::emitCollapseOneLevel() insilmaril@804: { insilmaril@804: emit (collapseOneLevel () ); insilmaril@804: } insilmaril@804: insilmaril@767: void VymModel::toggleStandardFlag (const QString &name, FlagRow *master) insilmaril@767: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@766: if (bi) insilmaril@766: { insilmaril@766: QString u,r; insilmaril@766: if (bi->isActiveStandardFlag(name)) insilmaril@766: { insilmaril@766: r="unsetFlag"; insilmaril@766: u="setFlag"; insilmaril@766: } insilmaril@766: else insilmaril@766: { insilmaril@766: u="unsetFlag"; insilmaril@766: r="setFlag"; insilmaril@766: } insilmaril@766: saveState( insilmaril@766: bi, insilmaril@766: QString("%1 (\"%2\")").arg(u).arg(name), insilmaril@766: bi, insilmaril@766: QString("%1 (\"%2\")").arg(r).arg(name), insilmaril@766: QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi))); insilmaril@767: bi->toggleStandardFlag (name, master); insilmaril@767: reposition(); insilmaril@775: emitSelectionChanged(); insilmaril@766: } insilmaril@766: } insilmaril@766: insilmaril@791: void VymModel::addFloatImage (const QPixmap &img) insilmaril@791: { insilmaril@791: BranchItem *selbi=getSelectedBranch(); insilmaril@791: if (selbi) insilmaril@791: { insilmaril@791: ImageItem *ii=createImage (selbi); insilmaril@791: ii->load(img); insilmaril@791: ii->setOriginalFilename("No original filename (image added by dropevent)"); insilmaril@791: QString s=getSelectString(selbi); insilmaril@791: saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii ); insilmaril@791: saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image"); insilmaril@791: reposition(); insilmaril@791: // FIXME-3 VM needed? scene()->update(); insilmaril@791: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@773: void VymModel::colorBranch (QColor c) insilmaril@773: { insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@773: if (selbi) insilmaril@721: { insilmaril@721: saveState( insilmaril@773: selbi, insilmaril@773: QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()), insilmaril@773: selbi, insilmaril@721: QString ("colorBranch (\"%1\")").arg(c.name()), insilmaril@773: QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name()) insilmaril@721: ); insilmaril@773: selbi->setHeadingColor(c); // color branch insilmaril@795: mapScene->update(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@773: void VymModel::colorSubtree (QColor c) insilmaril@773: { insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@773: if (selbi) insilmaril@721: { insilmaril@721: saveStateChangingPart( insilmaril@773: selbi, insilmaril@773: selbi, insilmaril@721: QString ("colorSubtree (\"%1\")").arg(c.name()), insilmaril@773: QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name()) insilmaril@721: ); insilmaril@773: BranchItem *prev=NULL; insilmaril@773: BranchItem *cur=selbi; insilmaril@773: while (cur) insilmaril@773: { insilmaril@773: cur->setHeadingColor(c); // color links, color children insilmaril@804: cur=nextBranch (cur,prev,true,selbi); insilmaril@773: } insilmaril@795: mapScene->update(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@773: QColor VymModel::getCurrentHeadingColor() insilmaril@773: { insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@773: if (selbi) return selbi->getHeadingColor(); insilmaril@773: 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@767: void VymModel::editURL() insilmaril@767: { insilmaril@767: TreeItem *selti=getSelectedItem(); insilmaril@767: if (selti) insilmaril@721: { insilmaril@721: bool ok; insilmaril@721: QString text = QInputDialog::getText( insilmaril@721: "VYM", tr("Enter URL:"), QLineEdit::Normal, insilmaril@767: selti->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@767: void VymModel::editLocalURL() insilmaril@767: { insilmaril@767: TreeItem *selti=getSelectedItem(); insilmaril@767: if (selti) 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@767: if (! selti->getVymLink().isEmpty() ) insilmaril@767: fd->selectFile( selti->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@767: void VymModel::editHeading2URL() insilmaril@767: { insilmaril@767: TreeItem *selti=getSelectedItem(); insilmaril@767: if (selti) insilmaril@767: setURL (selti->getHeading()); insilmaril@721: } insilmaril@721: insilmaril@767: void VymModel::editBugzilla2URL() insilmaril@767: { insilmaril@767: TreeItem *selti=getSelectedItem(); insilmaril@767: if (selti) insilmaril@721: { insilmaril@803: QString h=selti->getHeading(); insilmaril@803: QRegExp rx("^(\\d+)"); insilmaril@803: if (rx.indexIn(h) !=-1) insilmaril@803: setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+rx.cap(1) ); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@767: void VymModel::editFATE2URL() insilmaril@767: { insilmaril@767: TreeItem *selti=getSelectedItem(); insilmaril@767: if (selti) insilmaril@721: { insilmaril@767: QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+selti->getHeading(); insilmaril@721: saveState( insilmaril@767: selti, insilmaril@767: "setURL (\""+selti->getURL()+"\")", insilmaril@767: selti, insilmaril@721: "setURL (\""+url+"\")", insilmaril@767: QString("Use heading of %1 as link to FATE").arg(getObjectName(selti)) insilmaril@721: ); insilmaril@767: selti->setURL (url); insilmaril@767: // FIXME-4 updateActions(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::editVymLink() insilmaril@721: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@753: if (bi) 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@753: if (! bi->getVymLink().isEmpty() ) insilmaril@753: fd->selectFile( bi->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@753: bi, insilmaril@753: "setVymLink (\""+bi->getVymLink()+"\")", insilmaril@753: bi, insilmaril@721: "setVymLink (\""+fd->selectedFile()+"\")", insilmaril@753: QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile()) insilmaril@721: ); insilmaril@746: setVymLink (fd->selectedFile() ); // FIXME-2 ok? insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate? insilmaril@721: { insilmaril@721: // Internal function, no saveState needed insilmaril@780: TreeItem *selti=getSelectedItem(); insilmaril@780: if (selti) insilmaril@721: { insilmaril@780: selti->setVymLink(s); insilmaril@721: reposition(); insilmaril@780: emitDataHasChanged (selti); insilmaril@780: emitShowSelection(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::deleteVymLink() insilmaril@721: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@753: if (bi) insilmaril@721: { insilmaril@721: saveState( insilmaril@753: bi, insilmaril@767: "setVymLink (\""+bi->getVymLink()+"\")", insilmaril@753: bi, insilmaril@721: "setVymLink (\"\")", insilmaril@753: QString("Unset vymlink of %1").arg(getObjectName(bi)) insilmaril@721: ); insilmaril@767: bi->setVymLink ("" ); insilmaril@721: updateActions(); insilmaril@721: reposition(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: QString VymModel::getVymLink() insilmaril@721: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@753: if (bi) insilmaril@767: return bi->getVymLink(); insilmaril@721: else insilmaril@721: return ""; insilmaril@721: insilmaril@721: } insilmaril@721: insilmaril@771: QStringList VymModel::getVymLinks() insilmaril@771: { insilmaril@721: QStringList links; insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@773: BranchItem *cur=selbi; insilmaril@771: BranchItem *prev=NULL; insilmaril@771: while (cur) insilmaril@771: { insilmaril@771: if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink()); insilmaril@804: cur=nextBranch (cur,prev,true,selbi); insilmaril@721: } insilmaril@721: return links; insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@790: void VymModel::followXLink(int i) insilmaril@753: { insilmaril@753: i=0; insilmaril@790: BranchItem *selbi=getSelectedBranch(); insilmaril@790: if (selbi) insilmaril@721: { insilmaril@790: selbi=selbi->getXLinkNum(i)->getPartnerBranch(); insilmaril@790: if (selbi) select (selbi); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@790: void VymModel::editXLink(int i) insilmaril@753: { insilmaril@753: i=0; insilmaril@790: BranchItem *selbi=getSelectedBranch(); insilmaril@790: if (selbi) insilmaril@721: { insilmaril@790: XLinkItem *xli=selbi->getXLinkNum(i); insilmaril@790: if (xli) insilmaril@721: { insilmaril@721: EditXLinkDialog dia; insilmaril@790: dia.setXLink (xli); insilmaril@790: dia.setSelection(selbi); insilmaril@721: if (dia.exec() == QDialog::Accepted) insilmaril@721: { insilmaril@721: if (dia.useSettingsGlobal() ) insilmaril@721: { insilmaril@790: setMapDefXLinkColor (xli->getColor() ); insilmaril@790: setMapDefXLinkWidth (xli->getWidth() ); insilmaril@721: } insilmaril@790: if (dia.deleteXLink()) deleteItem (xli); 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@804: QVariant VymModel::parseAtom(const QString &atom, bool &noErr, QString &errorMsg) insilmaril@721: { insilmaril@750: TreeItem* selti=getSelectedItem(); insilmaril@787: BranchItem *selbi=getSelectedBranch(); insilmaril@721: QString s,t; insilmaril@721: double x,y; insilmaril@721: int n; insilmaril@721: bool b,ok; insilmaril@804: QVariant returnValue; 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@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@753: addMapReplaceInt(getSelectString(selbi),t); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com==QString("addMapInsert")) insilmaril@721: { insilmaril@788: if (parser.parCount()==2) insilmaril@721: { insilmaril@788: insilmaril@788: if (!selti) insilmaril@721: { insilmaril@788: parser.setError (Aborted,"Nothing selected"); insilmaril@788: } else if (! selbi ) insilmaril@788: { insilmaril@788: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@788: } else insilmaril@788: { 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@788: } else if (parser.parCount()==1) insilmaril@788: { insilmaril@788: t=parser.parString (ok,0); // path to map insilmaril@788: if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); insilmaril@788: addMapInsertInt(t); insilmaril@788: } else insilmaril@788: parser.setError (Aborted,"Wrong number of parameters"); insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@794: } else if (com==QString("addXLink")) insilmaril@794: { insilmaril@794: if (parser.parCount()>1) insilmaril@794: { insilmaril@794: s=parser.parString (ok,0); // begin insilmaril@794: t=parser.parString (ok,1); // end insilmaril@794: BranchItem *begin=(BranchItem*)findBySelectString(s); insilmaril@794: BranchItem *end=(BranchItem*)findBySelectString(t); insilmaril@794: if (begin && end) insilmaril@794: { insilmaril@794: if (begin->isBranchLikeType() && end->isBranchLikeType()) insilmaril@794: { insilmaril@794: XLinkItem *xl=createXLink (begin,true); insilmaril@794: if (xl) insilmaril@794: { insilmaril@794: xl->setEnd (end); insilmaril@794: xl->activate(); insilmaril@794: } else insilmaril@794: parser.setError (Aborted,"Failed to create xLink"); insilmaril@794: } insilmaril@794: else insilmaril@794: parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter"); insilmaril@794: insilmaril@794: } else insilmaril@794: parser.setError (Aborted,"Couldn't select begin or end of xLink"); insilmaril@794: } else insilmaril@794: parser.setError (Aborted,"Need at least 2 parameters for begin and end"); insilmaril@794: ///////////////////////////////////////////////////////////////////// insilmaril@767: } else if (com=="clearFlags") insilmaril@721: { insilmaril@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@767: selbi->deactivateAllStandardFlags(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@767: } else if (com=="colorBranch") insilmaril@721: { insilmaril@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@771: } else if ( selectionType()!=TreeItem::Branch && insilmaril@771: selectionType()!=TreeItem::MapCenter && insilmaril@771: selectionType()!=TreeItem::Image ) insilmaril@721: { insilmaril@771: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@771: copy(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="cut") insilmaril@721: { insilmaril@750: if (!selti) 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@750: if (!selti) 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@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi) 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@807: } else if (com=="exportAO") insilmaril@807: { insilmaril@807: QString fname=""; insilmaril@807: ok=true; insilmaril@807: if (parser.parCount()>=1) insilmaril@807: // Hey, we even have a filename insilmaril@807: fname=parser.parString(ok,0); insilmaril@807: if (!ok) insilmaril@807: { insilmaril@807: parser.setError (Aborted,"Could not read filename"); insilmaril@807: } else insilmaril@807: { insilmaril@807: exportAO (fname,false); insilmaril@807: } insilmaril@807: ///////////////////////////////////////////////////////////////////// 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@804: } else if (com=="getHeading") insilmaril@804: { insilmaril@804: if (!selti) insilmaril@804: { insilmaril@804: parser.setError (Aborted,"Nothing selected"); insilmaril@804: } else if (parser.checkParCount(0)) insilmaril@804: returnValue=selti->getHeading(); insilmaril@804: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="importDir") insilmaril@721: { insilmaril@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@776: } else if (com=="relinkTo") insilmaril@721: { insilmaril@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if ( selbi) 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@776: TreeItem *dst=findBySelectString (s); insilmaril@721: if (dst) insilmaril@721: { insilmaril@776: if (dst->getType()==TreeItem::Branch) insilmaril@721: { insilmaril@721: // Get number in parent insilmaril@721: n=parser.parInt (ok,1); insilmaril@721: if (ok) insilmaril@721: { insilmaril@776: relinkBranch (selbi,(BranchItem*)dst,n); insilmaril@775: emitSelectionChanged(); insilmaril@721: } insilmaril@776: } else if (dst->getType()==TreeItem::MapCenter) insilmaril@721: { insilmaril@776: relinkBranch (selbi,(BranchItem*)dst); 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@776: if (selbi->getLMO()) selbi->getLMO()->move (x,y); insilmaril@775: emitSelectionChanged(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@776: } else if ( selti->getType() == 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@776: TreeItem *dst=findBySelectString (s); insilmaril@721: if (dst) insilmaril@721: { insilmaril@776: if (dst->isBranchLikeType()) insilmaril@777: relinkImage ( ((ImageItem*)selti),(BranchItem*)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@776: } else if (com=="loadImage") insilmaril@721: { insilmaril@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@775: if (ok) loadFloatImageInt (selbi,s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@767: } else if (com=="moveUp") insilmaril@721: { insilmaril@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@767: moveUp(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@767: } else if (com=="moveDown") insilmaril@721: { insilmaril@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@767: moveDown(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="move") insilmaril@721: { insilmaril@750: if (!selti ) 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@750: if (!selti ) 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@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@753: if (! selbi ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else insilmaril@721: { insilmaril@753: if (selbi->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@787: ImageItem *ii=getSelectedImage(); insilmaril@776: if (!ii ) insilmaril@721: { insilmaril@776: parser.setError (Aborted,"No image selected"); 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@776: if (ok) saveFloatImageInt (ii,t,s); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="scroll") insilmaril@721: { insilmaril@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@750: } else if (! selbi ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@750: if (!scrollBranch (selbi)) 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@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@750: BranchItem *bi=selbi->getLastBranch(); insilmaril@750: if (!bi) insilmaril@721: parser.setError (Aborted,"Could not select last branch"); insilmaril@750: select (bi); // FIXME-3 was selectInt insilmaril@721: insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@753: } else /* FIXME-2 if (com=="selectLastImage") insilmaril@721: { insilmaril@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@750: select (fio); // FIXME-3 was selectInt insilmaril@721: insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@753: } else */ if (com=="selectLatestAdded") insilmaril@721: { insilmaril@761: if (!latestAddedItem) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"No latest added object"); insilmaril@721: } else insilmaril@721: { insilmaril@761: if (!select (latestAddedItem)) insilmaril@761: parser.setError (Aborted,"Could not select latest added object "); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@804: } else if (com=="setFlag") insilmaril@804: { insilmaril@804: if (!selti ) insilmaril@804: { insilmaril@804: parser.setError (Aborted,"Nothing selected"); insilmaril@804: } else if (! selbi ) insilmaril@804: { insilmaril@804: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@804: } else if (parser.checkParCount(1)) insilmaril@804: { insilmaril@804: s=parser.parString(ok,0); insilmaril@804: if (ok) insilmaril@804: selbi->activateStandardFlag(s); insilmaril@804: } insilmaril@804: ///////////////////////////////////////////////////////////////////// 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@804: /* FIXME-2 else if (com=="setFrameType") insilmaril@721: { insilmaril@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@804: } 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@804: s=parser.parString(ok,0); insilmaril@804: if (ok) insilmaril@804: setFrameType (s); insilmaril@804: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@804: } else*/ insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setHeading") insilmaril@721: { insilmaril@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@750: if (!selti ) 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@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi) 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@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi) 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@750: if (!selti ) 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@804: } else if (com=="setMapAuthor") insilmaril@804: { insilmaril@804: if (parser.checkParCount(1)) insilmaril@804: { insilmaril@804: s=parser.parString(ok,0); insilmaril@804: if (ok) setAuthor (s); insilmaril@804: } insilmaril@804: ///////////////////////////////////////////////////////////////////// insilmaril@804: } else if (com=="setMapComment") insilmaril@804: { insilmaril@804: if (parser.checkParCount(1)) insilmaril@804: { insilmaril@804: s=parser.parString(ok,0); insilmaril@804: if (ok) setComment(s); insilmaril@804: } insilmaril@804: ///////////////////////////////////////////////////////////////////// insilmaril@804: } else if (com=="setMapBackgroundColor") insilmaril@804: { insilmaril@804: if (!selti ) insilmaril@804: { insilmaril@804: parser.setError (Aborted,"Nothing selected"); insilmaril@804: } else if (! selbi ) insilmaril@804: { insilmaril@804: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@804: } else if (parser.checkParCount(1)) insilmaril@804: { insilmaril@804: QColor c=parser.parColor (ok,0); insilmaril@804: if (ok) setMapBackgroundColor (c); insilmaril@804: } insilmaril@804: ///////////////////////////////////////////////////////////////////// insilmaril@804: } else if (com=="setMapDefLinkColor") insilmaril@804: { insilmaril@804: if (!selti ) insilmaril@804: { insilmaril@804: parser.setError (Aborted,"Nothing selected"); insilmaril@804: } else if (! selbi ) insilmaril@804: { insilmaril@804: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@804: } else if (parser.checkParCount(1)) insilmaril@804: { insilmaril@804: QColor c=parser.parColor (ok,0); insilmaril@804: if (ok) setMapDefLinkColor (c); insilmaril@804: } insilmaril@804: ///////////////////////////////////////////////////////////////////// insilmaril@804: } else if (com=="setMapLinkStyle") insilmaril@804: { insilmaril@804: if (parser.checkParCount(1)) insilmaril@804: { insilmaril@804: s=parser.parString (ok,0); insilmaril@804: if (ok) setMapLinkStyle(s); insilmaril@804: } insilmaril@804: ///////////////////////////////////////////////////////////////////// insilmaril@804: } else if (com=="setNote") insilmaril@804: { insilmaril@804: if (!selti ) insilmaril@804: { insilmaril@804: parser.setError (Aborted,"Nothing selected"); insilmaril@804: } else if (! selbi ) insilmaril@804: { insilmaril@804: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@804: } else if (parser.checkParCount(1)) insilmaril@804: { insilmaril@804: s=parser.parString (ok,0); insilmaril@804: if (ok) insilmaril@804: setNote (s); insilmaril@804: } insilmaril@804: ///////////////////////////////////////////////////////////////////// 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@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@804: } else if (com=="sortChildren") insilmaril@721: { insilmaril@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@767: } else if (com=="toggleFlag") insilmaril@721: { insilmaril@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@753: selbi->toggleStandardFlag(s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@767: } else if (com=="unscroll") insilmaril@721: { insilmaril@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(0)) insilmaril@721: { insilmaril@750: if (!unscrollBranch (selbi)) insilmaril@721: parser.setError (Aborted,"Could not unscroll branch"); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="unscrollChildren") insilmaril@721: { insilmaril@750: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@767: } else if (com=="unsetFlag") insilmaril@721: { insilmaril@767: if (!selti) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@753: } else if (! selbi ) 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@767: selbi->deactivateStandardFlag(s); insilmaril@721: } insilmaril@767: } else insilmaril@721: parser.setError (Aborted,"Unknown command"); insilmaril@721: insilmaril@721: // Any errors? insilmaril@721: if (parser.errorLevel()==NoError) insilmaril@721: { insilmaril@746: // setChanged(); FIXME-2 should not be called e.g. for export?! insilmaril@721: reposition(); insilmaril@804: errorMsg.clear(); insilmaril@804: noErr=true; insilmaril@721: } insilmaril@721: else insilmaril@721: { insilmaril@721: // TODO Error handling insilmaril@721: qWarning("VymModel::parseAtom: Error!"); insilmaril@804: insilmaril@721: qWarning(parser.errorMessage()); insilmaril@804: noErr=false; insilmaril@804: errorMsg=parser.errorMessage(); insilmaril@721: } insilmaril@804: return returnValue; insilmaril@721: } insilmaril@721: insilmaril@807: QVariant VymModel::runScript (const QString &script) insilmaril@721: { insilmaril@721: parser.setScript (script); insilmaril@721: parser.runScript(); insilmaril@804: QVariant r; insilmaril@804: bool noErr=true; insilmaril@804: QString errMsg; insilmaril@804: while (parser.next() && noErr) insilmaril@804: { insilmaril@804: r=parseAtom(parser.getAtom(),noErr,errMsg); insilmaril@804: if (!noErr) //FIXME-3 need dialog box here insilmaril@804: cout << "VM::runScript aborted:\n"<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@784: QPixmap pix (mapEditor->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@784: // write to directory //FIXME-4 check totalBBox here... insilmaril@784: QString saveFile=saveToDir (dir,mapName+"-",true,mapEditor->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@807: void VymModel::exportAO (QString fname,bool askName) insilmaril@807: { insilmaril@807: ExportAO ex; insilmaril@807: ex.setModel (this); insilmaril@807: if (fname=="") insilmaril@807: ex.setFile (mapName+".txt"); insilmaril@807: else insilmaril@807: ex.setFile (fname); insilmaril@807: insilmaril@807: if (askName) insilmaril@807: { insilmaril@807: //ex.addFilter ("TXT (*.txt)"); insilmaril@807: ex.setDir(lastImageDir); insilmaril@807: //ex.setCaption(vymName+ " -" +tr("Export as A&O report")+" "+tr("(still experimental)")); insilmaril@807: ex.execDialog() ; insilmaril@807: } insilmaril@807: if (!ex.canceled()) insilmaril@807: { insilmaril@807: setExportMode(true); insilmaril@807: ex.doExport(); insilmaril@807: setExportMode(false); insilmaril@807: } insilmaril@807: } insilmaril@807: 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@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@767: TreeItem *selti=getSelectedItem(); insilmaril@767: if (selti) insilmaril@721: { insilmaril@767: if (textEditor->isEmpty()) insilmaril@767: selti->clearNote(); insilmaril@767: else insilmaril@767: selti->setNote (textEditor->getText()); insilmaril@767: emitDataHasChanged(selti); insilmaril@775: emitSelectionChanged(); insilmaril@767: insilmaril@767: } insilmaril@721: } insilmaril@721: insilmaril@795: void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views... insilmaril@761: { insilmaril@761: //cout << "VM::reposition blocked="<branchCount(); i++) insilmaril@754: rootItem->getBranchObjNum(i)->reposition(); // for positioning heading insilmaril@795: //emitSelectionChanged(); insilmaril@652: } insilmaril@652: insilmaril@721: insilmaril@721: void VymModel::setMapLinkStyle (const QString & s) insilmaril@721: { insilmaril@721: QString snow; insilmaril@727: switch (linkstyle) insilmaril@727: { insilmaril@727: case LinkableMapObj::Line : insilmaril@727: snow="StyleLine"; insilmaril@727: break; insilmaril@727: case LinkableMapObj::Parabel: insilmaril@727: snow="StyleParabel"; insilmaril@727: break; insilmaril@727: case LinkableMapObj::PolyLine: insilmaril@727: snow="StylePolyLine"; insilmaril@727: break; insilmaril@727: case LinkableMapObj::PolyParabel: insilmaril@727: snow="StylePolyParabel"; insilmaril@727: break; insilmaril@727: default: insilmaril@727: snow="UndefinedStyle"; insilmaril@727: break; insilmaril@727: } insilmaril@721: insilmaril@721: saveState ( insilmaril@721: QString("setMapLinkStyle (\"%1\")").arg(s), insilmaril@721: QString("setMapLinkStyle (\"%1\")").arg(snow), insilmaril@721: QString("Set map link style (\"%1\")").arg(s) insilmaril@721: ); insilmaril@721: insilmaril@721: if (s=="StyleLine") insilmaril@721: linkstyle=LinkableMapObj::Line; insilmaril@721: else if (s=="StyleParabel") insilmaril@721: linkstyle=LinkableMapObj::Parabel; insilmaril@721: else if (s=="StylePolyLine") insilmaril@721: linkstyle=LinkableMapObj::PolyLine; insilmaril@727: else if (s=="StylePolyParabel") insilmaril@721: linkstyle=LinkableMapObj::PolyParabel; insilmaril@727: else insilmaril@727: linkstyle=LinkableMapObj::UndefinedStyle; insilmaril@721: insilmaril@750: BranchItem *cur=NULL; insilmaril@750: BranchItem *prev=NULL; insilmaril@721: BranchObj *bo; insilmaril@804: nextBranch (cur,prev); insilmaril@741: while (cur) insilmaril@721: { insilmaril@741: bo=(BranchObj*)(cur->getLMO() ); insilmaril@786: bo->setLinkStyle(bo->getDefLinkStyle(cur->parent() )); //FIXME-3 better emit dataCHanged and leave the changes to View insilmaril@804: cur=nextBranch(cur,prev); 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@750: BranchItem *cur=NULL; insilmaril@750: BranchItem *prev=NULL; insilmaril@721: BranchObj *bo; insilmaril@804: cur=nextBranch(cur,prev); insilmaril@741: while (cur) insilmaril@721: { insilmaril@741: bo=(BranchObj*)(cur->getLMO() ); insilmaril@721: bo->setLinkColor(); insilmaril@804: nextBranch(cur,prev); 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@750: BranchItem *cur=NULL; insilmaril@750: BranchItem *prev=NULL; insilmaril@721: BranchObj *bo; insilmaril@804: cur=nextBranch(cur,prev); insilmaril@741: while (cur) insilmaril@721: { insilmaril@741: bo=(BranchObj*)(cur->getLMO() ); insilmaril@721: bo->setLinkColor(); insilmaril@804: cur=nextBranch(cur,prev); 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@750: BranchItem *cur=NULL; insilmaril@750: BranchItem *prev=NULL; insilmaril@721: BranchObj *bo; insilmaril@804: cur=nextBranch(cur,prev); insilmaril@741: while (cur) insilmaril@721: { insilmaril@741: bo=(BranchObj*)(cur->getLMO() ); insilmaril@721: bo->setLinkColor(); insilmaril@804: nextBranch(cur,prev); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@746: void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME insilmaril@798: // FIXME-4 for using background image: view.setCacheMode(QGraphicsView::CacheBackground); 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@795: void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-3 missing savestate, move to ME 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@753: void VymModel::selectMapBackgroundColor() // FIXME-3 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@753: void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 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@753: QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME insilmaril@721: { insilmaril@721: return mapScene->backgroundBrush().color(); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@753: LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME insilmaril@721: { insilmaril@721: return linkcolorhint; insilmaril@721: } insilmaril@721: insilmaril@753: QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME insilmaril@721: { insilmaril@721: return defLinkColor; insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME insilmaril@721: { insilmaril@721: defXLinkColor=col; insilmaril@721: } insilmaril@721: insilmaril@753: QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME insilmaril@721: { insilmaril@721: return defXLinkColor; insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME insilmaril@721: { insilmaril@721: defXLinkWidth=w; insilmaril@721: } insilmaril@721: insilmaril@753: int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME insilmaril@721: { insilmaril@721: return defXLinkWidth; insilmaril@721: } insilmaril@721: insilmaril@794: void VymModel::move(const double &x, const double &y) insilmaril@753: { insilmaril@753: int i=x; i=y; insilmaril@794: MapItem *seli = (MapItem*)getSelectedItem(); insilmaril@794: if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image)) insilmaril@721: { insilmaril@794: LinkableMapObj *lmo=seli->getLMO(); insilmaril@794: if (lmo) insilmaril@794: { insilmaril@794: QPointF ap(lmo->getAbsPos()); insilmaril@794: QPointF to(x, y); insilmaril@794: if (ap != to) insilmaril@794: { insilmaril@794: QString ps=qpointFToString(ap); insilmaril@794: QString s=getSelectString(seli); insilmaril@794: saveState( insilmaril@794: s, "move "+ps, insilmaril@794: s, "move "+qpointFToString(to), insilmaril@794: QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps)); insilmaril@794: lmo->move(x,y); insilmaril@794: reposition(); insilmaril@794: emitSelectionChanged(); insilmaril@794: } insilmaril@794: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@794: void VymModel::moveRel (const double &x, const double &y) insilmaril@753: { insilmaril@753: int i=x; i=y; insilmaril@794: MapItem *seli = (MapItem*)getSelectedItem(); insilmaril@794: if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image)) insilmaril@721: { insilmaril@794: LinkableMapObj *lmo=seli->getLMO(); insilmaril@794: if (lmo) insilmaril@794: { insilmaril@794: QPointF rp(lmo->getRelPos()); insilmaril@794: QPointF to(x, y); insilmaril@794: if (rp != to) insilmaril@794: { insilmaril@794: QString ps=qpointFToString (lmo->getRelPos()); insilmaril@794: QString s=getSelectString(seli); insilmaril@794: saveState( insilmaril@794: s, "moveRel "+ps, insilmaril@794: s, "moveRel "+qpointFToString(to), insilmaril@794: QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps)); insilmaril@794: ((OrnamentedObj*)lmo)->move2RelPos (x,y); insilmaril@794: reposition(); insilmaril@794: lmo->updateLinkGeometry(); insilmaril@794: emitSelectionChanged(); insilmaril@794: } insilmaril@794: } 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@798: if (start==dest) return; insilmaril@755: if (bo && bo->getTreeItem()->depth()>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@773: sendData (QString("select (\"%1\")").arg(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@746: //FIXME-3 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@804: cout << "VymModel::readData command="<errorString())); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@785: /* FIXME-3 Playing with DBUS... insilmaril@784: QDBusVariant VymModel::query (const QString &query) insilmaril@784: { insilmaril@784: TreeItem *selti=getSelectedItem(); insilmaril@784: if (selti) insilmaril@784: return QDBusVariant (selti->getHeading()); insilmaril@784: else insilmaril@784: return QDBusVariant ("Nothing selected."); insilmaril@784: } insilmaril@784: */ insilmaril@721: insilmaril@801: void VymModel::testslot() //FIXME-3 Playing with DBUS insilmaril@785: { insilmaril@785: cout << "VM::testslot called\n"; insilmaril@785: } insilmaril@785: 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@775: void VymModel::emitSelectionChanged(const QItemSelection &newsel) insilmaril@735: { insilmaril@742: emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor insilmaril@798: //FIXME-3 emitShowSelection(); insilmaril@735: sendSelection(); insilmaril@721: } insilmaril@721: insilmaril@775: void VymModel::emitSelectionChanged() insilmaril@746: { insilmaril@746: QItemSelection newsel=selModel->selection(); insilmaril@775: emitSelectionChanged (newsel); insilmaril@746: } insilmaril@746: 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@753: void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode) insilmaril@721: { insilmaril@721: hidemode=mode; insilmaril@753: for (int i=0;ichildCount();i++) insilmaril@753: rootItem->child(i)->setHideTmp (mode); insilmaril@721: reposition(); insilmaril@746: // FIXME-3 needed? scene()->update(); insilmaril@721: } insilmaril@721: 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: } insilmaril@728: insilmaril@728: QItemSelectionModel* VymModel::getSelectionModel() insilmaril@728: { insilmaril@728: return selModel; insilmaril@727: } insilmaril@727: insilmaril@721: void VymModel::setSelectionBlocked (bool b) insilmaril@721: { insilmaril@773: selectionBlocked=b; insilmaril@721: } insilmaril@721: insilmaril@721: bool VymModel::isSelectionBlocked() insilmaril@721: { insilmaril@773: return selectionBlocked; insilmaril@721: } insilmaril@721: insilmaril@727: bool VymModel::select () insilmaril@727: { insilmaril@776: return select (selModel->selectedIndexes().first()); // TODO no multiselections yet insilmaril@727: } insilmaril@727: insilmaril@721: bool VymModel::select (const QString &s) insilmaril@721: { insilmaril@788: if (s.isEmpty()) insilmaril@788: { insilmaril@788: unselect(); insilmaril@788: return true; insilmaril@788: } insilmaril@754: TreeItem *ti=findBySelectString(s); insilmaril@787: if (ti) return select (index(ti)); 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@787: return select (index (lmo->getTreeItem()) ); insilmaril@738: else insilmaril@738: return false; insilmaril@738: } insilmaril@738: insilmaril@738: bool VymModel::select (TreeItem *ti) insilmaril@738: { insilmaril@769: if (ti) return select (index(ti)); insilmaril@769: return false; insilmaril@769: } insilmaril@769: insilmaril@769: bool VymModel::select (const QModelIndex &index) insilmaril@769: { insilmaril@769: if (index.isValid() ) insilmaril@721: { insilmaril@769: selModel->select (index,QItemSelectionModel::ClearAndSelect ); insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@787: if (bi) bi->setLastSelectedBranch(); insilmaril@721: return true; insilmaril@721: } insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::unselect() insilmaril@721: { insilmaril@804: if (!selModel->selectedIndexes().isEmpty()) insilmaril@804: { insilmaril@804: lastSelectString=getSelectString(); insilmaril@804: selModel->clearSelection(); insilmaril@804: } insilmaril@721: } insilmaril@721: insilmaril@787: bool VymModel::reselect() insilmaril@787: { insilmaril@787: return select (lastSelectString); insilmaril@721: } insilmaril@721: insilmaril@763: void VymModel::emitShowSelection() insilmaril@763: { insilmaril@763: if (!blockReposition) insilmaril@763: emit (showSelection() ); insilmaril@746: } insilmaril@746: insilmaril@753: void VymModel::emitNoteHasChanged (TreeItem *ti) insilmaril@746: { insilmaril@746: QModelIndex ix=index(ti); insilmaril@753: emit (noteHasChanged (ix) ); insilmaril@753: } insilmaril@753: insilmaril@753: void VymModel::emitDataHasChanged (TreeItem *ti) insilmaril@753: { insilmaril@753: QModelIndex ix=index(ti); insilmaril@767: emit (dataChanged (ix,ix) ); insilmaril@721: } insilmaril@721: insilmaril@750: insilmaril@787: bool VymModel::selectFirstBranch() insilmaril@787: { insilmaril@787: TreeItem *ti=getSelectedBranch(); insilmaril@738: if (ti) insilmaril@721: { insilmaril@738: TreeItem *par=ti->parent(); insilmaril@787: if (par) insilmaril@787: { insilmaril@787: TreeItem *ti2=par->getFirstBranch(); insilmaril@787: if (ti2) return select(ti2); insilmaril@721: } insilmaril@721: } insilmaril@787: return false; insilmaril@721: } insilmaril@721: insilmaril@787: bool VymModel::selectLastBranch() insilmaril@787: { insilmaril@787: TreeItem *ti=getSelectedBranch(); insilmaril@738: if (ti) insilmaril@721: { insilmaril@738: TreeItem *par=ti->parent(); insilmaril@787: if (par) insilmaril@787: { insilmaril@787: TreeItem *ti2=par->getLastBranch(); insilmaril@787: if (ti2) return select(ti2); insilmaril@721: } insilmaril@721: } insilmaril@787: return false; insilmaril@721: } insilmaril@721: insilmaril@787: bool VymModel::selectLastSelectedBranch() insilmaril@787: { insilmaril@787: BranchItem *bi=getSelectedBranch(); insilmaril@787: if (bi) insilmaril@735: { insilmaril@787: bi=bi->getLastSelectedBranch(); insilmaril@787: if (bi) return select (bi); insilmaril@735: } insilmaril@787: return false; insilmaril@735: } insilmaril@735: insilmaril@787: bool 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@787: if (par) insilmaril@787: return select(par); insilmaril@726: } insilmaril@787: return false; 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@745: TreeItem *ti = getItem (list.first() ); 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@745: TreeItem *ti = getItem (list.first() ); insilmaril@735: TreeItem::Type type=ti->getType(); insilmaril@735: if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image) insilmaril@779: return ((MapItem*)ti)->getLMO(); insilmaril@735: } insilmaril@735: return NULL; insilmaril@652: } insilmaril@735: insilmaril@753: BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!! insilmaril@652: { insilmaril@787: TreeItem *ti = getSelectedBranch(); insilmaril@738: if (ti) insilmaril@779: return (BranchObj*)( ((MapItem*)ti)->getLMO()); insilmaril@738: else insilmaril@738: return NULL; insilmaril@738: } insilmaril@738: insilmaril@787: BranchItem* VymModel::getSelectedBranch() insilmaril@738: { insilmaril@735: QModelIndexList list=selModel->selectedIndexes(); insilmaril@735: if (!list.isEmpty() ) insilmaril@735: { insilmaril@745: TreeItem *ti = getItem (list.first() ); insilmaril@735: TreeItem::Type type=ti->getType(); insilmaril@735: if (type ==TreeItem::Branch || type==TreeItem::MapCenter) insilmaril@749: return (BranchItem*)ti; insilmaril@735: } insilmaril@735: return NULL; insilmaril@735: } insilmaril@735: insilmaril@787: ImageItem* VymModel::getSelectedImage() insilmaril@776: { insilmaril@776: QModelIndexList list=selModel->selectedIndexes(); insilmaril@776: if (!list.isEmpty()) insilmaril@776: { insilmaril@776: TreeItem *ti=getItem (list.first()); insilmaril@776: if (ti && ti->getType()==TreeItem::Image) insilmaril@776: return (ImageItem*)ti; insilmaril@776: } insilmaril@773: return NULL; insilmaril@721: } insilmaril@721: insilmaril@787: AttributeItem* VymModel::getSelectedAttribute() insilmaril@787: { insilmaril@787: QModelIndexList list=selModel->selectedIndexes(); insilmaril@787: if (!list.isEmpty() ) insilmaril@787: { insilmaril@787: TreeItem *ti = getItem (list.first() ); insilmaril@787: TreeItem::Type type=ti->getType(); insilmaril@787: if (type ==TreeItem::Attribute) insilmaril@787: return (AttributeItem*)ti; insilmaril@787: } insilmaril@787: return NULL; insilmaril@787: } insilmaril@787: insilmaril@787: TreeItem* VymModel::getSelectedItem() insilmaril@787: { insilmaril@787: QModelIndexList list=selModel->selectedIndexes(); insilmaril@787: if (!list.isEmpty() ) insilmaril@787: return getItem (list.first() ); insilmaril@787: else insilmaril@787: return NULL; insilmaril@787: } insilmaril@787: insilmaril@787: QModelIndex VymModel::getSelectedIndex() insilmaril@787: { insilmaril@787: QModelIndexList list=selModel->selectedIndexes(); insilmaril@787: if (list.isEmpty() ) insilmaril@787: return QModelIndex(); insilmaril@787: else insilmaril@787: return list.first(); insilmaril@787: } insilmaril@787: insilmaril@721: QString VymModel::getSelectString () insilmaril@721: { insilmaril@775: return getSelectString (getSelectedItem()); insilmaril@652: } insilmaril@652: insilmaril@791: QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor insilmaril@749: { insilmaril@749: if (!lmo) return QString(); insilmaril@749: return getSelectString (lmo->getTreeItem() ); insilmaril@749: } insilmaril@749: insilmaril@791: QString VymModel::getSelectString (TreeItem *ti) insilmaril@652: { insilmaril@652: QString s; insilmaril@749: if (!ti) return s; insilmaril@777: switch (ti->getType()) insilmaril@777: { insilmaril@777: case TreeItem::MapCenter: s="mc:"; break; insilmaril@777: case TreeItem::Branch: s="bo:";break; insilmaril@777: case TreeItem::Image: s="fi:";break; insilmaril@787: case TreeItem::Attribute: s="ai:";break; insilmaril@794: case TreeItem::XLink: s="xl:";break; insilmaril@794: default: insilmaril@794: s="unknown type in VymModel::getSelectString()"; insilmaril@794: break; insilmaril@777: } insilmaril@777: s= s + QString("%1").arg(ti->num()); insilmaril@777: if (ti->depth() >0) insilmaril@777: // call myself recursively insilmaril@777: s= getSelectString(ti->parent()) +","+s; insilmaril@777: insilmaril@652: return s; insilmaril@652: } insilmaril@652: