insilmaril@650: #include insilmaril@687: #include insilmaril@650: insilmaril@721: #include "vymmodel.h" insilmaril@721: insilmaril@753: #include "treeitem.h" insilmaril@749: #include "branchitem.h" insilmaril@749: #include "mapcenteritem.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 "mapcenterobj.h" insilmaril@721: #include "misc.h" insilmaril@721: #include "parser.h" insilmaril@721: #include "selection.h" insilmaril@721: insilmaril@721: insilmaril@721: #include "warningdialog.h" insilmaril@721: #include "xml-freemind.h" insilmaril@726: #include "xmlobj.h" insilmaril@721: #include "xml-vym.h" insilmaril@721: insilmaril@721: insilmaril@721: extern bool debug; insilmaril@721: extern Main *mainWindow; insilmaril@696: extern Settings settings; insilmaril@721: extern QString tmpVymDir; insilmaril@721: insilmaril@721: extern TextEditor *textEditor; insilmaril@721: insilmaril@721: extern QString clipboardDir; insilmaril@721: extern QString clipboardFile; insilmaril@721: extern bool clipboardEmpty; insilmaril@721: insilmaril@721: extern ImageIO imageIO; insilmaril@721: insilmaril@721: extern QString vymName; insilmaril@721: extern QString vymVersion; insilmaril@721: extern QDir vymBaseDir; insilmaril@721: insilmaril@721: extern QDir lastImageDir; insilmaril@721: extern QDir lastFileDir; insilmaril@721: insilmaril@721: extern FlagRowObj *standardFlagsDefault; insilmaril@721: insilmaril@721: extern Settings settings; insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: int VymModel::mapNum=0; // make instance insilmaril@696: insilmaril@650: VymModel::VymModel() insilmaril@650: { insilmaril@650: // cout << "Const VymModel\n"; insilmaril@721: init(); insilmaril@746: rootItem->setModel (this); insilmaril@650: } insilmaril@650: insilmaril@650: insilmaril@650: VymModel::~VymModel() insilmaril@650: { insilmaril@650: // cout << "Destr VymModel\n"; insilmaril@721: autosaveTimer->stop(); insilmaril@721: fileChangedTimer->stop(); insilmaril@721: clear(); insilmaril@650: } insilmaril@650: insilmaril@650: void VymModel::clear() insilmaril@650: { insilmaril@735: selModel->clearSelection(); insilmaril@721: insilmaril@754: //QModelIndex ri=index(rootItem); insilmaril@746: //removeRows (0, rowCount(ri),ri); // FIXME-2 here should be at least a beginRemoveRows... insilmaril@650: } insilmaril@650: insilmaril@650: void VymModel::init () insilmaril@650: { insilmaril@721: // We should have at least one map center to start with insilmaril@746: // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that insilmaril@727: insilmaril@727: // No MapEditor yet insilmaril@727: mapEditor=NULL; insilmaril@721: insilmaril@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@721: insilmaril@721: // find routine insilmaril@741: findCurrent=NULL; insilmaril@741: findPrevious=NULL; insilmaril@721: EOFind=false; insilmaril@696: insilmaril@696: // animations insilmaril@696: animationUse=settings.readBoolEntry("/animation/use",false); insilmaril@696: animationTicks=settings.readNumEntry("/animation/ticks",10); insilmaril@696: animationInterval=settings.readNumEntry("/animation/interval",50); insilmaril@696: animObjList.clear(); insilmaril@696: animationTimer=new QTimer (this); insilmaril@696: connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate())); insilmaril@696: insilmaril@721: // View - map insilmaril@721: defLinkColor=QColor (0,0,255); insilmaril@721: defXLinkColor=QColor (180,180,180); insilmaril@721: linkcolorhint=LinkableMapObj::DefaultColor; insilmaril@721: linkstyle=LinkableMapObj::PolyParabel; insilmaril@721: defXLinkWidth=1; insilmaril@721: defXLinkColor=QColor (230,230,230); insilmaril@721: insilmaril@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@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@746: MapEditor* VymModel::getMapEditor() // FIXME-2 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@746: // Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe... insilmaril@721: standardFlagsDefault->resetUsedCounter(); insilmaril@721: insilmaril@721: // Reset the counters before saving insilmaril@721: // TODO constr. of FIO creates lots of objects, better do this in some other way... insilmaril@746: FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe... insilmaril@721: insilmaril@760: cout << "VM::saveToDir 0 " <getType()==TreeItem::MapCenter) 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@759: if (saveSel->getType()==TreeItem::Branch) insilmaril@721: // Save Subtree insilmaril@759: s+=saveSel->saveToDir(tmpdir,prefix,offset); insilmaril@759: //FIXME-2 else if (saveSel->getType()==TreeItem::Image) insilmaril@721: // Save image insilmaril@759: //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix); insilmaril@721: } insilmaril@721: insilmaril@760: cout << "VM::saveToDir 1 \n"; insilmaril@721: // Save local settings insilmaril@721: s+=settings.getDataXML (destPath); insilmaril@721: insilmaril@760: cout << "VM::saveToDir 2 \n"; 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@721: if (writeflags) insilmaril@721: standardFlagsDefault->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@754: s+=((MapCenterItem*)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@753: BranchItem *bi=getSelectedBranchItem(); 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@721: selection.update(); insilmaril@721: if (lmode==NewMap) insilmaril@721: { insilmaril@721: mapDefault=false; insilmaril@721: mapChanged=false; insilmaril@721: mapUnsaved=false; insilmaril@721: autosaveTimer->stop(); insilmaril@721: } insilmaril@721: insilmaril@721: // Reset timestamp to check for later updates of file insilmaril@721: fileChangedTime=QFileInfo (destPath).lastModified(); insilmaril@721: } else insilmaril@721: { insilmaril@721: QMessageBox::critical( 0, tr( "Critical Parse Error" ), insilmaril@721: tr( handler->errorProtocol() ) ); insilmaril@721: // returnCode=1; insilmaril@721: // Still return "success": the map maybe at least insilmaril@721: // partially read by the parser insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: // Delete tmpZipDir insilmaril@721: removeDir (QDir(tmpZipDir)); insilmaril@721: insilmaril@729: // Restore original zip state insilmaril@729: zipped=zipped_org; insilmaril@729: insilmaril@721: updateActions(); insilmaril@721: return err; insilmaril@721: } insilmaril@721: insilmaril@721: ErrorCode VymModel::save (const SaveMode &savemode) insilmaril@721: { insilmaril@721: QString tmpZipDir; insilmaril@721: QString mapFileName; insilmaril@721: QString safeFilePath; insilmaril@721: insilmaril@721: ErrorCode err=success; insilmaril@721: insilmaril@721: if (zipped) insilmaril@721: // save as .xml insilmaril@721: mapFileName=mapName+".xml"; insilmaril@721: else insilmaril@721: // use name given by user, even if he chooses .doc insilmaril@721: mapFileName=fileName; insilmaril@721: insilmaril@721: // Look, if we should zip the data: insilmaril@721: if (!zipped) insilmaril@721: { insilmaril@721: QMessageBox mb( vymName, insilmaril@721: tr("The map %1\ndid not use the compressed " insilmaril@721: "vym file format.\nWriting it uncompressed will also write images \n" insilmaril@721: "and flags and thus may overwrite files in the " insilmaril@721: "given directory\n\nDo you want to write the map").arg(filePath), insilmaril@721: QMessageBox::Warning, insilmaril@721: QMessageBox::Yes | QMessageBox::Default, insilmaril@721: QMessageBox::No , insilmaril@721: QMessageBox::Cancel | QMessageBox::Escape); insilmaril@721: mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") ); insilmaril@721: mb.setButtonText( QMessageBox::No, tr("uncompressed") ); insilmaril@721: mb.setButtonText( QMessageBox::Cancel, tr("Cancel")); insilmaril@721: switch( mb.exec() ) insilmaril@721: { insilmaril@721: case QMessageBox::Yes: insilmaril@721: // save compressed (default file format) insilmaril@721: zipped=true; insilmaril@721: break; insilmaril@721: case QMessageBox::No: insilmaril@721: // save uncompressed insilmaril@721: zipped=false; insilmaril@721: break; insilmaril@721: case QMessageBox::Cancel: insilmaril@721: // do nothing insilmaril@721: return aborted; insilmaril@721: break; insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: // First backup existing file, we insilmaril@721: // don't want to add to old zip archives insilmaril@721: QFile f(destPath); insilmaril@721: if (f.exists()) insilmaril@721: { insilmaril@721: if ( settings.value ("/mapeditor/writeBackupFile").toBool()) insilmaril@721: { insilmaril@721: QString backupFileName(destPath + "~"); insilmaril@721: QFile backupFile(backupFileName); insilmaril@721: if (backupFile.exists() && !backupFile.remove()) insilmaril@721: { insilmaril@721: QMessageBox::warning(0, tr("Save Error"), insilmaril@721: tr("%1\ncould not be removed before saving").arg(backupFileName)); insilmaril@721: } insilmaril@721: else if (!f.rename(backupFileName)) insilmaril@721: { insilmaril@721: QMessageBox::warning(0, tr("Save Error"), insilmaril@721: tr("%1\ncould not be renamed before saving").arg(destPath)); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: if (zipped) insilmaril@721: { insilmaril@721: // Create temporary directory for packing insilmaril@721: bool ok; insilmaril@721: tmpZipDir=makeTmpDir (ok,"vym-zip"); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: QMessageBox::critical( 0, tr( "Critical Load Error" ), insilmaril@721: tr("Couldn't create temporary directory before save\n")); insilmaril@721: return aborted; insilmaril@721: } insilmaril@721: insilmaril@721: safeFilePath=filePath; insilmaril@721: setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath); insilmaril@721: } // zipped insilmaril@721: insilmaril@721: // Create mapName and fileDir insilmaril@721: makeSubDirs (fileDir); insilmaril@721: insilmaril@721: QString saveFile; insilmaril@721: if (savemode==CompleteMap || selection.isEmpty()) insilmaril@721: { insilmaril@721: // Save complete map insilmaril@721: saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL); insilmaril@721: mapChanged=false; insilmaril@721: mapUnsaved=false; insilmaril@721: autosaveTimer->stop(); insilmaril@721: } insilmaril@721: else insilmaril@721: { insilmaril@721: // Save part of map insilmaril@735: if (selectionType()==TreeItem::Image) insilmaril@721: saveFloatImage(); insilmaril@721: else insilmaril@753: saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem()); insilmaril@721: // TODO take care of multiselections insilmaril@721: } insilmaril@721: insilmaril@721: if (!saveStringToDisk(fileDir+mapFileName,saveFile)) insilmaril@721: { insilmaril@721: err=aborted; insilmaril@721: qWarning ("ME::saveStringToDisk failed!"); insilmaril@721: } insilmaril@721: insilmaril@721: if (zipped) insilmaril@721: { insilmaril@721: // zip insilmaril@721: if (err==success) err=zipDir (tmpZipDir,destPath); insilmaril@721: insilmaril@721: // Delete tmpDir insilmaril@721: removeDir (QDir(tmpZipDir)); insilmaril@721: insilmaril@721: // Restore original filepath outside of tmp zip dir insilmaril@721: setFilePath (safeFilePath); insilmaril@721: } insilmaril@721: insilmaril@721: updateActions(); insilmaril@721: fileChangedTime=QFileInfo (destPath).lastModified(); insilmaril@721: return err; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path) insilmaril@721: { insilmaril@721: QString pathDir=path.left(path.findRev("/")); insilmaril@721: QDir d(pathDir); insilmaril@721: QFile file (path); insilmaril@721: insilmaril@721: if (d.exists() ) insilmaril@721: { insilmaril@721: // We need to parse saved XML data insilmaril@721: parseVYMHandler handler; insilmaril@721: QXmlInputSource source( file); insilmaril@721: QXmlSimpleReader reader; insilmaril@721: reader.setContentHandler( &handler ); insilmaril@721: reader.setErrorHandler( &handler ); insilmaril@721: handler.setModel ( this); insilmaril@721: handler.setTmpDir ( pathDir ); // needed to load files with rel. path insilmaril@721: if (undoSel.isEmpty()) insilmaril@721: { insilmaril@721: unselect(); insilmaril@721: clear(); insilmaril@721: handler.setLoadMode (NewMap); insilmaril@721: } else insilmaril@721: { insilmaril@721: select (undoSel); insilmaril@721: handler.setLoadMode (ImportReplace); insilmaril@721: } insilmaril@721: blockReposition=true; insilmaril@721: bool ok = reader.parse( source ); insilmaril@721: blockReposition=false; insilmaril@721: if (! ok ) insilmaril@721: { insilmaril@721: // This should never ever happen insilmaril@721: QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), insilmaril@721: handler.errorProtocol()); insilmaril@721: } insilmaril@721: } else insilmaril@721: QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::addMapInsertInt (const QString &path, int pos) insilmaril@721: { insilmaril@750: /* FIXME-2 addMapInsertInt not ported yet insilmaril@735: BranchObj *sel=getSelectedBranch(); insilmaril@721: if (sel) insilmaril@721: { insilmaril@721: QString pathDir=path.left(path.findRev("/")); insilmaril@721: QDir d(pathDir); insilmaril@721: QFile file (path); insilmaril@721: insilmaril@721: if (d.exists() ) insilmaril@721: { insilmaril@721: // We need to parse saved XML data insilmaril@721: parseVYMHandler handler; insilmaril@721: QXmlInputSource source( file); insilmaril@721: QXmlSimpleReader reader; insilmaril@721: reader.setContentHandler( &handler ); insilmaril@721: reader.setErrorHandler( &handler ); insilmaril@721: handler.setModel (this); insilmaril@721: handler.setTmpDir ( pathDir ); // needed to load files with rel. path insilmaril@721: handler.setLoadMode (ImportAdd); insilmaril@721: blockReposition=true; insilmaril@721: bool ok = reader.parse( source ); insilmaril@721: blockReposition=false; insilmaril@721: if (! ok ) insilmaril@721: { insilmaril@721: // This should never ever happen insilmaril@721: QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), insilmaril@721: handler.errorProtocol()); insilmaril@721: } insilmaril@721: if (sel->getDepth()>0) insilmaril@721: sel->getLastBranch()->linkTo (sel,pos); insilmaril@721: } else insilmaril@721: QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); insilmaril@721: } insilmaril@750: */ insilmaril@721: } insilmaril@721: insilmaril@721: FloatImageObj* VymModel::loadFloatImageInt (QString fn) insilmaril@721: { insilmaril@739: TreeItem *fi=createImage(); insilmaril@739: if (fi) insilmaril@721: { insilmaril@739: FloatImageObj *fio= ((FloatImageObj*)fi->getLMO()); insilmaril@739: fio->load (fn); insilmaril@721: reposition(); insilmaril@721: return fio; insilmaril@721: } insilmaril@721: return NULL; insilmaril@740: } insilmaril@721: insilmaril@753: void VymModel::loadFloatImage () // FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: insilmaril@721: Q3FileDialog *fd=new Q3FileDialog( NULL); insilmaril@721: fd->setMode (Q3FileDialog::ExistingFiles); insilmaril@721: fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); insilmaril@721: ImagePreview *p =new ImagePreview (fd); insilmaril@721: fd->setContentsPreviewEnabled( TRUE ); insilmaril@721: fd->setContentsPreview( p, p ); insilmaril@721: fd->setPreviewMode( Q3FileDialog::Contents ); insilmaril@721: fd->setCaption(vymName+" - " +tr("Load image")); insilmaril@721: fd->setDir (lastImageDir); insilmaril@721: fd->show(); insilmaril@721: insilmaril@721: if ( fd->exec() == QDialog::Accepted ) insilmaril@721: { insilmaril@721: // TODO loadFIO in QT4 use: lastImageDir=fd->directory(); insilmaril@721: lastImageDir=QDir (fd->dirPath()); insilmaril@721: QString s; insilmaril@721: FloatImageObj *fio; insilmaril@721: for (int j=0; jselectedFiles().count(); j++) insilmaril@721: { insilmaril@721: s=fd->selectedFiles().at(j); insilmaril@721: fio=loadFloatImageInt (s); insilmaril@721: if (fio) insilmaril@721: saveState( insilmaril@721: (LinkableMapObj*)fio, insilmaril@721: "delete ()", insilmaril@721: bo, insilmaril@721: QString ("loadImage (%1)").arg(s ), insilmaril@721: QString("Add image %1 to %2").arg(s).arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: else insilmaril@721: // TODO loadFIO error handling insilmaril@721: qWarning ("Failed to load "+s); insilmaril@721: } insilmaril@721: } insilmaril@721: delete (p); insilmaril@721: delete (fd); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn) insilmaril@721: { insilmaril@721: fio->save (fn,type); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::saveFloatImage () insilmaril@721: { insilmaril@721: FloatImageObj *fio=selection.getFloatImage(); insilmaril@721: if (fio) insilmaril@721: { insilmaril@721: QFileDialog *fd=new QFileDialog( NULL); insilmaril@721: fd->setFilters (imageIO.getFilters()); insilmaril@721: fd->setCaption(vymName+" - " +tr("Save image")); insilmaril@721: fd->setFileMode( QFileDialog::AnyFile ); insilmaril@721: fd->setDirectory (lastImageDir); insilmaril@721: // fd->setSelection (fio->getOriginalFilename()); insilmaril@721: fd->show(); insilmaril@721: insilmaril@721: QString fn; insilmaril@721: if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1) insilmaril@721: { insilmaril@721: fn=fd->selectedFiles().at(0); insilmaril@721: if (QFile (fn).exists() ) insilmaril@721: { insilmaril@721: QMessageBox mb( vymName, insilmaril@721: tr("The file %1 exists already.\n" insilmaril@721: "Do you want to overwrite it?").arg(fn), insilmaril@721: QMessageBox::Warning, insilmaril@721: QMessageBox::Yes | QMessageBox::Default, insilmaril@721: QMessageBox::Cancel | QMessageBox::Escape, insilmaril@721: QMessageBox::NoButton ); insilmaril@721: insilmaril@721: mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); insilmaril@721: mb.setButtonText( QMessageBox::No, tr("Cancel")); insilmaril@721: switch( mb.exec() ) insilmaril@721: { insilmaril@721: case QMessageBox::Yes: insilmaril@721: // save insilmaril@721: break; insilmaril@721: case QMessageBox::Cancel: insilmaril@721: // do nothing insilmaril@721: delete (fd); insilmaril@721: return; insilmaril@721: break; insilmaril@721: } insilmaril@721: } insilmaril@721: saveFloatImageInt (fio,fd->selectedFilter(),fn ); insilmaril@721: } insilmaril@721: delete (fd); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::importDirInt(BranchObj *dst, QDir d) insilmaril@721: { insilmaril@750: /* FIXME-2 importDirInt not ported yet insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: // Traverse directories insilmaril@721: d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks ); insilmaril@721: QFileInfoList list = d.entryInfoList(); insilmaril@721: QFileInfo fi; insilmaril@721: insilmaril@721: for (int i = 0; i < list.size(); ++i) insilmaril@721: { insilmaril@721: fi=list.at(i); insilmaril@721: if (fi.fileName() != "." && fi.fileName() != ".." ) insilmaril@721: { insilmaril@721: dst->addBranch(); insilmaril@721: bo=dst->getLastBranch(); insilmaril@749: BranchItem *bi=(BranchItem*)(bo->getTreeItem()); insilmaril@749: bi->setHeading (fi.fileName() ); // FIXME-3 check this insilmaril@721: bo->setColor (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@721: importDirInt (bo,d); insilmaril@721: d.cdUp(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: // Traverse files insilmaril@721: d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks ); insilmaril@721: list = d.entryInfoList(); insilmaril@721: insilmaril@721: for (int i = 0; i < list.size(); ++i) insilmaril@721: { insilmaril@721: fi=list.at(i); insilmaril@721: dst->addBranch(); insilmaril@721: bo=dst->getLastBranch(); insilmaril@721: bo->setHeading (fi.fileName() ); insilmaril@721: bo->setColor (QColor("black")); insilmaril@721: if (fi.fileName().right(4) == ".vym" ) insilmaril@721: bo->setVymLink (fi.filePath()); insilmaril@721: } insilmaril@721: } insilmaril@750: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::importDirInt (const QString &s) // FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s)); insilmaril@721: insilmaril@721: QDir d(s); insilmaril@721: importDirInt (bo,d); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::importDir() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QStringList filters; insilmaril@721: filters <<"VYM map (*.vym)"; insilmaril@721: QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import")); insilmaril@721: fd->setMode (QFileDialog::DirectoryOnly); insilmaril@721: fd->setFilters (filters); insilmaril@721: fd->setCaption(vymName+" - " +tr("Choose directory structure to import")); insilmaril@721: fd->show(); insilmaril@721: insilmaril@721: QString fn; insilmaril@721: if ( fd->exec() == QDialog::Accepted ) insilmaril@721: { insilmaril@721: importDirInt (fd->selectedFile() ); insilmaril@721: reposition(); insilmaril@746: //FIXME-3 VM needed? scene()->update(); insilmaril@721: } insilmaril@721: } insilmaril@753: */ 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@753: QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete insilmaril@721: { insilmaril@721: QString s; insilmaril@721: if (!lmo) return QString("Error: NULL has no name!"); insilmaril@721: insilmaril@721: if ((typeid(*lmo) == typeid(BranchObj) || insilmaril@721: typeid(*lmo) == typeid(MapCenterObj))) insilmaril@721: { insilmaril@721: insilmaril@753: s=lmo->getTreeItem()->getHeading(); insilmaril@721: if (s=="") s="unnamed"; insilmaril@721: return QString("branch (%1)").arg(s); insilmaril@721: } insilmaril@721: if ((typeid(*lmo) == typeid(FloatImageObj) )) insilmaril@721: return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename()); insilmaril@721: return QString("Unknown type has no name!"); insilmaril@721: } insilmaril@721: insilmaril@753: insilmaril@753: QString VymModel::getObjectName (const TreeItem *ti) insilmaril@753: { insilmaril@753: QString s; insilmaril@753: if (!ti) return QString("Error: NULL has no name!"); insilmaril@753: insilmaril@753: if (ti->isBranchLikeType() ) insilmaril@753: { insilmaril@753: s=ti->getHeading(); insilmaril@753: if (s=="") s="unnamed"; insilmaril@753: return QString("branch (%1)").arg(s); insilmaril@753: } insilmaril@753: /* FIXME-2 move floatimage to TreeModel first insilmaril@753: if (type==TreeItem::Image) insilmaril@753: return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename()); insilmaril@753: */ insilmaril@753: return QString("Unknown type has no name!"); 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@721: if (!undoSelection.isEmpty()) insilmaril@721: select (undoSelection); insilmaril@721: insilmaril@721: if (debug) insilmaril@721: { insilmaril@721: cout << "VymModel::undo() begin\n"; insilmaril@721: cout << " undosAvail="<updateHistory (undoSet); insilmaril@721: updateActions(); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@721: insilmaril@721: bool VymModel::isUndoAvailable() insilmaril@721: { insilmaril@721: if (undoSet.readNumEntry("/history/undosAvail",0)>0) insilmaril@721: return true; insilmaril@721: else insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::gotoHistoryStep (int i) insilmaril@721: { insilmaril@721: // Restore variables insilmaril@721: int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail")); insilmaril@721: int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail")); insilmaril@721: insilmaril@721: if (i<0) i=undosAvail+redosAvail; insilmaril@721: insilmaril@721: // Clicking above current step makes us undo things insilmaril@721: if (iundosAvail) insilmaril@721: for (int j=undosAvail; jstepsTotal) curStep=1; insilmaril@721: insilmaril@721: QString backupXML=""; insilmaril@721: QString histDir=getHistoryPath(); insilmaril@721: QString bakMapPath=histDir+"/map.xml"; insilmaril@721: insilmaril@721: // Create histDir if not available insilmaril@721: QDir d(histDir); insilmaril@721: if (!d.exists()) insilmaril@721: makeSubDirs (histDir); insilmaril@721: insilmaril@721: // Save depending on how much needs to be saved insilmaril@721: if (saveSel) insilmaril@721: backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel); insilmaril@721: insilmaril@721: QString undoCommand=""; insilmaril@721: if (savemode==UndoCommand) insilmaril@721: { insilmaril@721: undoCommand=undoCom; insilmaril@721: } insilmaril@721: else if (savemode==PartOfMap ) insilmaril@721: { insilmaril@721: undoCommand=undoCom; insilmaril@721: undoCommand.replace ("PATH",bakMapPath); insilmaril@721: } insilmaril@721: insilmaril@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@753: QString undoSelection=getSelectString (redoSel->parent() ); insilmaril@721: QString redoSelection=getSelectString(redoSel); insilmaril@753: if (redoSel->getType()==TreeItem::Branch) insilmaril@721: { 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@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@761: /* FIXME-2 insilmaril@761: else insilmaril@761: if (typ="fi") insilmaril@761: ti=ti->getImageNum (n); insilmaril@761: */ insilmaril@761: } insilmaril@761: return ti; insilmaril@650: } insilmaril@650: insilmaril@754: TreeItem* VymModel::findID (const QString &s) insilmaril@754: { insilmaril@754: TreeItem *ti; insilmaril@754: for (int i=0; ibranchCount(); i++) insilmaril@650: { insilmaril@754: ti=rootItem->getBranchNum(i)->findID (s); insilmaril@754: if (ti) return ti; insilmaril@650: } 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@749: int VymModel::branchCount() // FIXME-2 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@742: int d; insilmaril@742: next(cur,prev,d); insilmaril@742: while (cur) insilmaril@742: { insilmaril@742: c++; insilmaril@742: next(cur,prev,d); insilmaril@742: } insilmaril@742: return c; insilmaril@742: } insilmaril@742: insilmaril@721: void VymModel::setHeading(const QString &s) insilmaril@721: { insilmaril@753: BranchItem *selbi=getSelectedBranchItem(); 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@753: QModelIndex ix2=index (selbi); insilmaril@753: emit (dataChanged ( ix2,ix2)); insilmaril@746: /* FIXME-3 testing only insilmaril@736: */ insilmaril@726: insilmaril@721: reposition(); insilmaril@753: // selection.update(); //FIXME-4 insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@753: BranchItem* VymModel::findText (QString s, bool cs) insilmaril@721: { insilmaril@741: int d=0; 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@741: next (findCurrent,findPrevious,d); 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@741: if (findCurrent->getNote().contains(s,cs)) insilmaril@721: { insilmaril@741: select (findCurrent); insilmaril@741: /* insilmaril@735: if (getSelectedBranch()!=itFind) insilmaril@721: { insilmaril@735: select(itFind); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@741: */ insilmaril@721: if (textEditor->findText(s,flags)) insilmaril@721: { insilmaril@721: searching=false; insilmaril@721: foundNote=true; insilmaril@721: } insilmaril@721: } insilmaril@721: // Searching in Heading insilmaril@741: if (searching && findCurrent->getHeading().contains (s,cs) ) insilmaril@721: { insilmaril@741: select(findCurrent); insilmaril@721: searching=false; insilmaril@721: } insilmaril@721: } insilmaril@721: if (!foundNote) insilmaril@721: { insilmaril@741: if (!next(findCurrent,findPrevious,d) ) insilmaril@741: EOFind=true; insilmaril@721: } insilmaril@721: //cout <<"still searching... "<getHeading())<getURL(); insilmaril@721: bo->setURL (url); insilmaril@721: saveState ( insilmaril@721: bo, insilmaril@721: QString ("setURL (\"%1\")").arg(oldurl), insilmaril@721: bo, insilmaril@721: QString ("setURL (\"%1\")").arg(url), insilmaril@721: QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url) insilmaril@721: ); insilmaril@721: updateActions(); insilmaril@721: reposition(); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: QString VymModel::getURL() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: return bo->getURL(); insilmaril@721: else insilmaril@721: return ""; insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@746: QStringList VymModel::getURLs() // FIXME-1 first, next moved to vymmodel insilmaril@746: { insilmaril@746: return QStringList(); insilmaril@746: /* insilmaril@721: QStringList urls; insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bo=bo->first(); insilmaril@721: while (bo) insilmaril@721: { insilmaril@721: if (!bo->getURL().isEmpty()) urls.append( bo->getURL()); insilmaril@721: bo=bo->next(); insilmaril@721: } insilmaril@721: } insilmaril@721: return urls; insilmaril@746: */ insilmaril@721: } insilmaril@721: insilmaril@754: void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-2 insilmaril@721: { insilmaril@721: FloatImageObj *fio=selection.getFloatImage(); insilmaril@721: if (fio) insilmaril@721: { insilmaril@754: TreeItem *dst=findBySelectString (dstString); insilmaril@754: if (dst && dst->isBranchLikeType() ) insilmaril@721: { insilmaril@754: TreeItem *dstPar=dst->parent(); insilmaril@721: QString parString=getSelectString(dstPar); insilmaril@721: QString fioPreSelectString=getSelectString(fio); insilmaril@721: QString fioPreParentSelectString=getSelectString (fio->getParObj()); insilmaril@754: // FIXME-2 ((BranchObj*)dst)->addFloatImage (fio); insilmaril@754: unselect(); insilmaril@754: // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio); insilmaril@721: fio=((BranchObj*)dst)->getLastFloatImage(); insilmaril@721: fio->setRelPos(); insilmaril@721: fio->reposition(); insilmaril@754: // select (fio); insilmaril@721: saveState( insilmaril@721: getSelectString(fio), insilmaril@721: QString("linkTo (\"%1\")").arg(fioPreParentSelectString), insilmaril@721: fioPreSelectString, insilmaril@721: QString ("linkTo (\"%1\")").arg(dstString), insilmaril@721: QString ("Link floatimage to %1").arg(getObjectName(dst))); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@753: void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QString s=bo->getFrameTypeName(); insilmaril@721: bo->setFrameType (t); insilmaril@721: saveState (bo, QString("setFrameType (\"%1\")").arg(s), insilmaril@721: bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s)); insilmaril@721: reposition(); insilmaril@721: bo->updateLink(); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::setFrameType(const QString &s) //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()), insilmaril@721: bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s)); insilmaril@721: bo->setFrameType (s); insilmaril@721: reposition(); insilmaril@721: bo->updateLink(); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::setFramePenColor(const QColor &c) //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ), insilmaril@721: bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() )); insilmaril@721: bo->setFramePenColor (c); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ), insilmaril@721: bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() )); insilmaril@721: bo->setFrameBrushColor (c); insilmaril@721: } insilmaril@753: */} insilmaril@753: insilmaril@753: void VymModel::setFramePadding (const int &i) //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ), insilmaril@721: bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i)); insilmaril@721: bo->setFramePadding (i); insilmaril@721: reposition(); insilmaril@721: bo->updateLink(); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::setFrameBorderWidth(const int &i) //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ), insilmaril@721: bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i)); insilmaril@721: bo->setFrameBorderWidth (i); insilmaril@721: reposition(); insilmaril@721: bo->updateLink(); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::setIncludeImagesVer(bool b) //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QString u= b ? "false" : "true"; insilmaril@721: QString r=!b ? "false" : "true"; insilmaril@721: insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: QString("setIncludeImagesVertically (%1)").arg(u), insilmaril@721: bo, insilmaril@721: QString("setIncludeImagesVertically (%1)").arg(r), insilmaril@721: QString("Include images vertically in %1").arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: bo->setIncludeImagesVer(b); insilmaril@721: reposition(); insilmaril@721: } insilmaril@753: */} insilmaril@753: insilmaril@753: void VymModel::setIncludeImagesHor(bool b) //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QString u= b ? "false" : "true"; insilmaril@721: QString r=!b ? "false" : "true"; insilmaril@721: insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: QString("setIncludeImagesHorizontally (%1)").arg(u), insilmaril@721: bo, insilmaril@721: QString("setIncludeImagesHorizontally (%1)").arg(r), insilmaril@721: QString("Include images horizontally in %1").arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: bo->setIncludeImagesHor(b); insilmaril@721: reposition(); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::setHideLinkUnselected (bool b)//FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: LinkableMapObj *sel=getSelectedLMO(); insilmaril@721: if (sel && insilmaril@735: (selectionType() == TreeItem::Branch || insilmaril@735: selectionType() == TreeItem::MapCenter || insilmaril@735: selectionType() == TreeItem::Image )) insilmaril@721: { insilmaril@721: QString u= b ? "false" : "true"; insilmaril@721: QString r=!b ? "false" : "true"; insilmaril@721: insilmaril@721: saveState( insilmaril@721: sel, insilmaril@721: QString("setHideLinkUnselected (%1)").arg(u), insilmaril@721: sel, insilmaril@721: QString("setHideLinkUnselected (%1)").arg(r), insilmaril@721: QString("Hide link of %1 if unselected").arg(getObjectName(sel)) insilmaril@721: ); insilmaril@721: sel->setHideLinkUnselected(b); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setHideExport(bool b) insilmaril@721: { insilmaril@753: BranchItem *bi=getSelectedBranchItem(); insilmaril@753: if (bi) insilmaril@721: { insilmaril@753: bi->setHideInExport (b); insilmaril@721: QString u= b ? "false" : "true"; insilmaril@721: QString r=!b ? "false" : "true"; insilmaril@721: insilmaril@721: saveState( insilmaril@753: bi, insilmaril@721: QString ("setHideExport (%1)").arg(u), insilmaril@753: bi, insilmaril@721: QString ("setHideExport (%1)").arg(r), insilmaril@753: QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r) insilmaril@721: ); insilmaril@721: updateActions(); insilmaril@721: reposition(); insilmaril@753: // selection.update(); insilmaril@746: // FIXME-3 VM needed? scene()->update(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::toggleHideExport() insilmaril@721: { insilmaril@753: BranchItem *selbi=getSelectedBranchItem(); insilmaril@753: if (selbi) insilmaril@753: setHideExport ( !selbi->hideInExport() ); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@753: void VymModel::copy() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: LinkableMapObj *sel=getSelectedLMO(); insilmaril@735: if (sel && insilmaril@735: (selectionType() == TreeItem::Branch || insilmaril@735: selectionType() == TreeItem::MapCenter || insilmaril@735: selectionType() == TreeItem::Image )) insilmaril@721: { insilmaril@721: if (redosAvail == 0) insilmaril@721: { insilmaril@721: // Copy to history insilmaril@721: QString s=getSelectString(sel); insilmaril@721: saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel ); insilmaril@721: curClipboard=curStep; insilmaril@721: } insilmaril@721: insilmaril@721: // Copy also to global clipboard, because we are at last step in history insilmaril@721: QString bakMapName(QString("history-%1").arg(curStep)); insilmaril@721: QString bakMapDir(tmpMapDir +"/"+bakMapName); insilmaril@721: copyDir (bakMapDir,clipboardDir ); insilmaril@721: insilmaril@721: clipboardEmpty=false; insilmaril@721: updateActions(); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@753: void VymModel::pasteNoSave(const int &n) //FIXME-2 insilmaril@753: { insilmaril@753: /* 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@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::paste() //FIXME-2 insilmaril@721: { insilmaril@753: /* insilmaril@735: BranchObj *sel=getSelectedBranch(); insilmaril@721: if (sel) insilmaril@721: { insilmaril@721: saveStateChangingPart( insilmaril@721: sel, insilmaril@721: sel, insilmaril@721: QString ("paste (%1)").arg(curClipboard), insilmaril@721: QString("Paste to %1").arg( getObjectName(sel)) insilmaril@721: ); insilmaril@721: pasteNoSave(0); insilmaril@721: reposition(); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::cut() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: LinkableMapObj *sel=getSelectedLMO(); insilmaril@735: if ( sel && (selectionType() == TreeItem::Branch || insilmaril@735: selectionType()==TreeItem::MapCenter || insilmaril@735: selectionType()==TreeItem::Image)) insilmaril@721: { insilmaril@753: */ insilmaril@721: /* No savestate! savestate is called in cutNoSave insilmaril@721: saveStateChangingPart( insilmaril@721: sel->getParObj(), insilmaril@721: sel, insilmaril@721: "cut ()", insilmaril@721: QString("Cut %1").arg(getObjectName(sel )) insilmaril@721: ); insilmaril@721: */ insilmaril@753: /* insilmaril@721: copy(); insilmaril@721: deleteSelection(); insilmaril@721: reposition(); insilmaril@721: } insilmaril@753: */} insilmaril@753: insilmaril@753: void VymModel::moveBranchUp() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj* bo=getSelectedBranch(); insilmaril@721: BranchObj* par; insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: if (!bo->canMoveBranchUp()) return; insilmaril@721: par=(BranchObj*)(bo->getParObj()); insilmaril@721: BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection insilmaril@721: saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo))); insilmaril@721: reposition(); insilmaril@746: //FIXME-3 VM needed? scene()->update(); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::moveBranchDown() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj* bo=getSelectedBranch(); insilmaril@721: BranchObj* par; insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: if (!bo->canMoveBranchDown()) return; insilmaril@721: par=(BranchObj*)(bo->getParObj()); insilmaril@721: BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection insilmaril@721: saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo))); insilmaril@721: reposition(); insilmaril@746: //FIXME-3 VM needed? scene()->update(); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::sortChildren() // FIXME-2 not implemented yet insilmaril@749: { insilmaril@749: /* insilmaril@735: BranchObj* bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@749: if(treeItem->branchCount()>1) insilmaril@721: { insilmaril@721: saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo))); insilmaril@721: bo->sortChildren(); insilmaril@721: reposition(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@721: } insilmaril@749: */ insilmaril@721: } insilmaril@721: insilmaril@753: MapCenterItem* VymModel::createMapCenter() insilmaril@753: { insilmaril@753: MapCenterItem *mci=addMapCenter (QPointF (0,0) ); insilmaril@753: select (mci); insilmaril@753: return mci; insilmaril@726: } insilmaril@726: insilmaril@755: BranchItem* VymModel::createBranch() insilmaril@755: { insilmaril@755: return addNewBranchInt (-2); insilmaril@739: } insilmaril@739: insilmaril@753: TreeItem* VymModel::createImage() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@726: if (bo) insilmaril@726: { insilmaril@746: FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below insilmaril@726: insilmaril@726: // Create TreeItem insilmaril@726: QList cData; insilmaril@739: cData << "VM:createImage" << "undef"<<"undef"; insilmaril@726: TreeItem *parti=bo->getTreeItem(); insilmaril@726: TreeItem *ti=new TreeItem (cData,parti); insilmaril@739: ti->setLMO (newfio); insilmaril@739: ti->setType (TreeItem::Image); insilmaril@726: parti->appendChild (ti); insilmaril@726: insilmaril@739: if (newfio) insilmaril@726: { insilmaril@739: newfio->setTreeItem (ti); insilmaril@746: select (newfio); // FIXME-2 VM really needed here? insilmaril@739: return ti; insilmaril@726: } insilmaril@726: } insilmaril@739: return NULL; insilmaril@753: */ insilmaril@726: } insilmaril@726: insilmaril@753: MapCenterItem* VymModel::addMapCenter () insilmaril@753: { insilmaril@761: MapCenterItem *mci=addMapCenter (contextPos); insilmaril@746: //FIXME-3 selection.select (mco); insilmaril@721: updateActions(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: saveState ( insilmaril@753: mci, 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@753: return mci; insilmaril@721: } insilmaril@721: insilmaril@753: MapCenterItem* VymModel::addMapCenter(QPointF absPos) insilmaril@721: { insilmaril@749: insilmaril@749: // Create TreeItem insilmaril@749: QModelIndex parix=index(rootItem); insilmaril@749: insilmaril@749: int n=rootItem->branchCount(); insilmaril@749: insilmaril@749: emit (layoutAboutToBeChanged() ); insilmaril@749: beginInsertRows (parix,n,n+1); insilmaril@749: insilmaril@749: QList cData; insilmaril@749: cData << "VM:addMapCenter" << "undef"<<"undef"; insilmaril@760: MapCenterItem *mci=new MapCenterItem (cData); insilmaril@753: mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); insilmaril@753: rootItem->appendChild (mci); insilmaril@749: insilmaril@749: endInsertRows(); insilmaril@749: emit (newChildObject (parix)); insilmaril@749: emit (layoutChanged() ); insilmaril@749: insilmaril@749: // Create MapObj insilmaril@760: BranchObj *newbo=mci->createMapObj(mapScene); insilmaril@760: insilmaril@760: /* insilmaril@760: insilmaril@760: if (!mci->getHeading().isEmpty() ) insilmaril@760: { insilmaril@760: newbo->updateHeading(); insilmaril@760: newbo->setColor (headingColor); insilmaril@760: } insilmaril@760: */ insilmaril@760: insilmaril@760: //newbo->updateLink(); //FIXME-3 insilmaril@760: insilmaril@760: /* insilmaril@754: //mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects insilmaril@753: mapCenter->setTreeItem (mci); // TreeItem needs to exist before setVisibility insilmaril@753: mci->setLMO (mapCenter); insilmaril@753: mapCenter->updateHeading(); insilmaril@721: mapCenter->move (absPos); insilmaril@721: mapCenter->setVisibility (true); insilmaril@753: //mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); insilmaril@745: */ insilmaril@753: return mci; insilmaril@721: } insilmaril@721: insilmaril@755: BranchItem* VymModel::addNewBranchInt(int num) insilmaril@721: { insilmaril@721: // Depending on pos: insilmaril@721: // -3 insert in children of parent above selection insilmaril@721: // -2 add branch to selection insilmaril@721: // -1 insert in children of parent below selection insilmaril@721: // 0..n insert in children of parent at pos insilmaril@721: BranchObj *newbo=NULL; insilmaril@753: BranchObj *bo=getSelectedBranchObj(); //FIXME-2 insilmaril@749: BranchItem *bi=getSelectedBranchItem(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: if (num==-2) insilmaril@721: { insilmaril@749: // Create TreeItem insilmaril@749: QList cData; insilmaril@749: cData << "new" << "undef"<<"undef"; insilmaril@749: insilmaril@749: BranchItem *parbi=bi; insilmaril@749: QModelIndex parix=index(parbi); insilmaril@756: int n=parbi->childCount(); insilmaril@749: insilmaril@749: emit (layoutAboutToBeChanged() ); insilmaril@756: beginInsertRows (parix,n,n+1); //FIXME-1 check if n is correct: should be index below _last_ branch... insilmaril@756: bi=new BranchItem (cData); insilmaril@753: bi->setHeading (QApplication::translate("Heading of new branch in map", "new")); insilmaril@749: insilmaril@756: parbi->appendChild (bi); insilmaril@749: endInsertRows (); insilmaril@749: emit (newChildObject (parix)); insilmaril@749: emit (layoutChanged() ); insilmaril@749: insilmaril@721: // save scroll state. If scrolled, automatically select insilmaril@721: // new branch in order to tmp unscroll parent... insilmaril@755: newbo=bi->createMapObj(mapScene); insilmaril@755: select (bi); insilmaril@721: }else if (num==-1) insilmaril@721: { insilmaril@755: /* insilmaril@749: num=bi->num()+1; insilmaril@721: bo=(BranchObj*)bo->getParObj(); insilmaril@746: if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing insilmaril@755: */ insilmaril@721: }else if (num==-3) insilmaril@721: { insilmaril@755: /* insilmaril@749: num=bi->num(); insilmaril@721: bo=(BranchObj*)bo->getParObj(); insilmaril@746: if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing insilmaril@755: */ insilmaril@721: } insilmaril@721: } insilmaril@755: return bi; 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@755: BranchItem *selbi=getSelectedBranchItem(); insilmaril@755: insilmaril@755: if (selbi) insilmaril@721: { insilmaril@749: // FIXME-2 VM do we still need this in model? setCursor (Qt::ArrowCursor); insilmaril@721: insilmaril@755: newbi=addNewBranchInt (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@746: // selection.update(); 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@755: BranchItem* VymModel::addNewBranchBefore() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@721: BranchObj *newbo=NULL; insilmaril@735: BranchObj *bo = getSelectedBranch(); insilmaril@735: if (bo && selectionType()==TreeItem::Branch) insilmaril@721: // We accept no MapCenterObj here, so we _have_ a parent insilmaril@721: { insilmaril@721: QPointF p=bo->getRelPos(); insilmaril@721: insilmaril@721: insilmaril@721: BranchObj *parbo=(BranchObj*)(bo->getParObj()); insilmaril@721: insilmaril@721: // add below selection insilmaril@749: newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing insilmaril@745: insilmaril@721: if (newbo) insilmaril@721: { insilmaril@721: newbo->move2RelPos (p); insilmaril@721: insilmaril@721: // Move selection to new branch insilmaril@721: bo->linkTo (newbo,-1); insilmaril@721: insilmaril@721: saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()", insilmaril@721: QString ("Add branch before %1").arg(getObjectName(bo))); insilmaril@721: insilmaril@721: reposition(); insilmaril@746: // selection.update(); FIXME-3 insilmaril@721: } insilmaril@721: } insilmaril@721: latestSelectionString=selection.getSelectString(); insilmaril@721: return newbo; insilmaril@753: */ insilmaril@753: return NULL; insilmaril@721: } insilmaril@721: insilmaril@755: BranchItem* VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos) insilmaril@755: { insilmaril@755: if (branch && dst) insilmaril@755: { 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@756: branch->getLMO()->setParObj(dst->getLMO()); //FIXME-5 update parObj in View insilmaril@756: emit (layoutChanged() ); insilmaril@756: select (branch); insilmaril@755: } insilmaril@755: } insilmaril@755: insilmaril@721: void VymModel::deleteSelection() insilmaril@721: { insilmaril@753: BranchItem *selbi=getSelectedBranchItem(); insilmaril@753: insilmaril@753: if (!selbi) return; insilmaril@753: insilmaril@760: TreeItem *pi=selbi->parent(); insilmaril@760: QModelIndex parentIndex=index(pi); insilmaril@728: insilmaril@753: if (selbi->isBranchLikeType() ) insilmaril@721: { insilmaril@735: unselect(); insilmaril@760: saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi))); insilmaril@745: insilmaril@745: emit (layoutAboutToBeChanged() ); insilmaril@745: insilmaril@760: int n=selbi->childNum(); insilmaril@745: beginRemoveRows (parentIndex,n,n); insilmaril@748: removeRows (n,1,parentIndex); insilmaril@749: endRemoveRows(); insilmaril@760: select (pi); insilmaril@721: ensureSelectionVisible(); insilmaril@721: reposition(); insilmaril@745: insilmaril@745: emit (layoutChanged() ); insilmaril@721: return; insilmaril@721: } insilmaril@749: //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing insilmaril@745: insilmaril@748: /* insilmaril@721: if (fio) insilmaril@721: { insilmaril@721: BranchObj* par=(BranchObj*)fio->getParObj(); insilmaril@721: saveStateChangingPart( insilmaril@721: par, insilmaril@721: fio, insilmaril@721: "delete ()", insilmaril@721: QString("Delete %1").arg(getObjectName(fio)) insilmaril@721: ); insilmaril@735: unselect(); insilmaril@721: par->removeFloatImage(fio); insilmaril@735: select (par); insilmaril@721: reposition(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: return; insilmaril@721: } insilmaril@748: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::deleteKeepChildren() //FIXME-2 VM still missing insilmaril@753: insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: BranchObj *par; insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: par=(BranchObj*)(bo->getParObj()); insilmaril@726: insilmaril@726: // Don't use this on mapcenter insilmaril@726: if (!par) return; insilmaril@726: insilmaril@726: // Check if we have childs at all to keep insilmaril@749: if (bo->getTreeItem()->branchCount()==0) insilmaril@726: { insilmaril@726: deleteSelection(); insilmaril@726: return; insilmaril@726: } insilmaril@726: insilmaril@721: QPointF p=bo->getRelPos(); insilmaril@721: saveStateChangingPart( insilmaril@721: bo->getParObj(), insilmaril@721: bo, insilmaril@721: "deleteKeepChildren ()", insilmaril@721: QString("Remove %1 and keep its children").arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: insilmaril@721: QString sel=getSelectString(bo); insilmaril@721: unselect(); insilmaril@721: par->removeBranchHere(bo); insilmaril@721: reposition(); insilmaril@721: select (sel); insilmaril@735: getSelectedBranch()->move2RelPos (p); insilmaril@721: reposition(); insilmaril@721: } insilmaril@753: */} insilmaril@753: insilmaril@753: void VymModel::deleteChildren() //FIXME-2 VM still missing insilmaril@753: insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveStateChangingPart( insilmaril@721: bo, insilmaril@721: bo, insilmaril@721: "deleteChildren ()", insilmaril@721: QString( "Remove children of branch %1").arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: bo->removeChildren(); insilmaril@721: reposition(); insilmaril@721: } insilmaril@753: */} insilmaril@721: insilmaril@721: 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@721: QString u,r; insilmaril@721: r="scroll"; insilmaril@721: u="unscroll"; insilmaril@753: /* FIXME-3 no savestate yet insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: QString ("%1 ()").arg(u), insilmaril@721: bo, insilmaril@721: QString ("%1 ()").arg(r), insilmaril@721: QString ("%1 %2").arg(r).arg(getObjectName(bo)) insilmaril@721: ); insilmaril@749: */ insilmaril@749: bi->toggleScroll(); insilmaril@749: //selection.update(); insilmaril@746: // FIXME-3 VM needed? scene()->update(); insilmaril@721: return true; 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@749: if (bi->isScrolled()) return false; insilmaril@749: if (bi->branchCount()==0) return false; insilmaril@749: if (bi->depth()==0) return false; insilmaril@749: insilmaril@721: QString u,r; insilmaril@721: u="scroll"; insilmaril@721: r="unscroll"; insilmaril@753: /* FIXME-3 no savestate yet insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: QString ("%1 ()").arg(u), insilmaril@721: bo, insilmaril@721: QString ("%1 ()").arg(r), insilmaril@721: QString ("%1 %2").arg(r).arg(getObjectName(bo)) insilmaril@721: ); insilmaril@749: */ insilmaril@749: bi->toggleScroll(); insilmaril@749: // selection.update(); insilmaril@746: // FIXME-3 VM needed? scene()->update(); insilmaril@721: return true; insilmaril@721: } insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::toggleScroll() insilmaril@721: { insilmaril@749: BranchItem *bi=(BranchItem*)getSelectedBranchItem(); insilmaril@749: if (bi && bi->getType()==TreeItem::Branch ) insilmaril@721: { insilmaril@749: if (bi->isScrolled()) insilmaril@749: unscrollBranch (bi); insilmaril@721: else insilmaril@749: scrollBranch (bi); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@746: void VymModel::unscrollChildren() // FIXME-1 first, next moved to vymmodel insilmaril@746: insilmaril@746: { insilmaril@746: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bo->first(); insilmaril@721: while (bo) insilmaril@721: { insilmaril@721: if (bo->isScrolled()) unscrollBranch (bo); insilmaril@721: bo=bo->next(); insilmaril@721: } insilmaril@721: } insilmaril@746: */ insilmaril@721: } insilmaril@746: insilmaril@753: void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: FloatImageObj *fio=bo->addFloatImage(); insilmaril@721: fio->load(img); insilmaril@721: fio->setOriginalFilename("No original filename (image added by dropevent)"); insilmaril@721: QString s=getSelectString(bo); insilmaril@721: saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio ); insilmaril@721: saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image"); insilmaril@721: reposition(); insilmaril@746: // FIXME-3 VM needed? scene()->update(); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@753: void VymModel::colorBranch (QColor c) //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: QString ("colorBranch (\"%1\")").arg(bo->getColor().name()), insilmaril@721: bo, insilmaril@721: QString ("colorBranch (\"%1\")").arg(c.name()), insilmaril@721: QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name()) insilmaril@721: ); insilmaril@721: bo->setColor(c); // color branch insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::colorSubtree (QColor c) //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: saveStateChangingPart( insilmaril@721: bo, insilmaril@721: bo, insilmaril@721: QString ("colorSubtree (\"%1\")").arg(c.name()), insilmaril@721: QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name()) insilmaril@721: ); insilmaril@721: bo->setColorSubtree (c); // color links, color children insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: QColor VymModel::getCurrentHeadingColor() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) return bo->getColor(); insilmaril@721: insilmaril@721: QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected"); insilmaril@753: */ insilmaril@721: return Qt::black; insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@753: void VymModel::editURL() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bool ok; insilmaril@721: QString text = QInputDialog::getText( insilmaril@721: "VYM", tr("Enter URL:"), QLineEdit::Normal, insilmaril@721: bo->getURL(), &ok, NULL); insilmaril@721: if ( ok) insilmaril@721: // user entered something and pressed OK insilmaril@721: setURL(text); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::editLocalURL() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QStringList filters; insilmaril@721: filters <<"All files (*)"; insilmaril@721: filters << tr("Text","Filedialog") + " (*.txt)"; insilmaril@721: filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)"; insilmaril@721: filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)"; insilmaril@721: filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"; insilmaril@721: QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file")); insilmaril@721: fd->setFilters (filters); insilmaril@721: fd->setCaption(vymName+" - " +tr("Set URL to a local file")); insilmaril@721: fd->setDirectory (lastFileDir); insilmaril@721: if (! bo->getVymLink().isEmpty() ) insilmaril@721: fd->selectFile( bo->getURL() ); insilmaril@721: fd->show(); insilmaril@721: insilmaril@721: if ( fd->exec() == QDialog::Accepted ) insilmaril@721: { insilmaril@721: lastFileDir=QDir (fd->directory().path()); insilmaril@721: setURL (fd->selectedFile() ); insilmaril@721: } insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@753: void VymModel::editHeading2URL() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: setURL (bo->getHeading()); insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::editBugzilla2URL() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading(); insilmaril@721: setURL (url); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::editFATE2URL() //FIXME-2 insilmaril@753: { insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading(); insilmaril@721: saveState( insilmaril@721: bo, insilmaril@721: "setURL (\""+bo->getURL()+"\")", insilmaril@721: bo, insilmaril@721: "setURL (\""+url+"\")", insilmaril@721: QString("Use heading of %1 as link to FATE").arg(getObjectName(bo)) insilmaril@721: ); insilmaril@721: bo->setURL (url); insilmaril@721: updateActions(); insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::editVymLink() insilmaril@721: { insilmaril@753: BranchItem *bi=getSelectedBranchItem(); 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@753: BranchItem *bi=getSelectedBranchItem(); insilmaril@753: if (bi) insilmaril@721: { insilmaril@753: bi->getBranchObj()->setVymLink(s); //FIXME-3 check getBO insilmaril@721: reposition(); insilmaril@721: updateActions(); insilmaril@753: //selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::deleteVymLink() insilmaril@721: { insilmaril@753: BranchItem *bi=getSelectedBranchItem(); insilmaril@753: if (bi) insilmaril@721: { insilmaril@721: saveState( insilmaril@753: bi, insilmaril@753: "setVymLink (\""+bi->getBranchObj()->getVymLink()+"\")", //FIXME-3 check getBO insilmaril@753: insilmaril@753: bi, insilmaril@721: "setVymLink (\"\")", insilmaril@753: QString("Unset vymlink of %1").arg(getObjectName(bi)) insilmaril@721: ); insilmaril@753: bi->getBranchObj()->setVymLink ("" ); //FIXME-3 check getBO insilmaril@721: updateActions(); insilmaril@721: reposition(); insilmaril@746: // FIXME-3 VM needed? scene()->update(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: QString VymModel::getVymLink() insilmaril@721: { insilmaril@753: BranchItem *bi=getSelectedBranchItem(); insilmaril@753: if (bi) insilmaril@753: return bi->getBranchObj()->getVymLink(); //FIXME-3 check getBO here... insilmaril@721: else insilmaril@721: return ""; insilmaril@721: insilmaril@721: } insilmaril@721: insilmaril@746: QStringList VymModel::getVymLinks() // FIXME-1 first, next moved to vymmodel insilmaril@746: { insilmaril@746: return QStringList(); insilmaril@746: /* insilmaril@721: QStringList links; insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bo=bo->first(); insilmaril@721: while (bo) insilmaril@721: { insilmaril@721: if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink()); insilmaril@721: bo=bo->next(); insilmaril@721: } insilmaril@721: } insilmaril@721: return links; insilmaril@746: */ insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@753: void VymModel::followXLink(int i) // FIXME-2 insilmaril@753: { insilmaril@753: i=0; insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bo=bo->XLinkTargetAt(i); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: selection.select(bo); insilmaril@721: ensureSelectionVisible(); insilmaril@721: } insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::editXLink(int i) // FIXME-2 VM missing saveState insilmaril@753: { insilmaril@753: i=0; insilmaril@753: /* insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: XLinkObj *xlo=bo->XLinkAt(i); insilmaril@721: if (xlo) insilmaril@721: { insilmaril@721: EditXLinkDialog dia; insilmaril@721: dia.setXLink (xlo); insilmaril@721: dia.setSelection(bo); insilmaril@721: if (dia.exec() == QDialog::Accepted) insilmaril@721: { insilmaril@721: if (dia.useSettingsGlobal() ) insilmaril@721: { insilmaril@721: setMapDefXLinkColor (xlo->getColor() ); insilmaril@721: setMapDefXLinkWidth (xlo->getWidth() ); insilmaril@721: } insilmaril@721: if (dia.deleteXLink()) insilmaril@721: bo->deleteXLinkAt(i); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: ////////////////////////////////////////////// insilmaril@721: // Scripting insilmaril@721: ////////////////////////////////////////////// insilmaril@721: insilmaril@721: void VymModel::parseAtom(const QString &atom) insilmaril@721: { insilmaril@753: //BranchObj *selb=getSelectedBranch(); // FIXME-4 insilmaril@750: TreeItem* selti=getSelectedItem(); insilmaril@750: BranchItem *selbi=getSelectedBranchItem(); insilmaril@721: QString s,t; insilmaril@721: double x,y; insilmaril@721: int n; insilmaril@721: bool b,ok; insilmaril@721: insilmaril@721: // Split string s into command and parameters insilmaril@721: parser.parseAtom (atom); insilmaril@721: QString com=parser.getCommand(); insilmaril@721: insilmaril@721: // External commands insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: if (com=="addBranch") insilmaril@721: { insilmaril@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@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.checkParCount(2)) insilmaril@721: { insilmaril@721: t=parser.parString (ok,0); // path to map insilmaril@721: n=parser.parInt(ok,1); // position insilmaril@721: if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); insilmaril@721: addMapInsertInt(t,n); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@753: } else /*if (com=="clearFlags") // FIXME-2 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: selb->clearStandardFlags(); insilmaril@721: selb->updateFlagsToolbar(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@753: } 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@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@746: //FIXME-1 missing action for 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@721: } else if (com=="exportASCII") insilmaril@721: { insilmaril@721: QString fname=""; insilmaril@721: ok=true; insilmaril@721: if (parser.parCount()>=1) insilmaril@721: // Hey, we even have a filename insilmaril@721: fname=parser.parString(ok,0); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Could not read filename"); insilmaril@721: } else insilmaril@721: { insilmaril@721: exportASCII (fname,false); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="exportImage") insilmaril@721: { insilmaril@721: QString fname=""; insilmaril@721: ok=true; insilmaril@721: if (parser.parCount()>=2) insilmaril@721: // Hey, we even have a filename insilmaril@721: fname=parser.parString(ok,0); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Could not read filename"); insilmaril@721: } else insilmaril@721: { insilmaril@721: QString format="PNG"; insilmaril@721: if (parser.parCount()>=2) insilmaril@721: { insilmaril@721: format=parser.parString(ok,1); insilmaril@721: } insilmaril@721: exportImage (fname,false,format); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="exportXHTML") insilmaril@721: { insilmaril@721: QString fname=""; insilmaril@721: ok=true; insilmaril@721: if (parser.parCount()>=2) insilmaril@721: // Hey, we even have a filename insilmaril@721: fname=parser.parString(ok,1); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Could not read filename"); insilmaril@721: } else insilmaril@721: { insilmaril@721: exportXHTML (fname,false); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="exportXML") insilmaril@721: { insilmaril@721: QString fname=""; insilmaril@721: ok=true; insilmaril@721: if (parser.parCount()>=2) insilmaril@721: // Hey, we even have a filename insilmaril@721: fname=parser.parString(ok,1); insilmaril@721: if (!ok) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Could not read filename"); insilmaril@721: } else insilmaril@721: { insilmaril@721: exportXML (fname,false); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="importDir") insilmaril@721: { insilmaril@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@753: } else /* FIXME-2 if (com=="linkTo") 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@721: LinkableMapObj *dst=findObjBySelect (s); insilmaril@721: if (dst) insilmaril@721: { insilmaril@721: if (typeid(*dst) == typeid(BranchObj) ) insilmaril@721: { insilmaril@721: // Get number in parent insilmaril@721: n=parser.parInt (ok,1); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: selb->linkTo ((BranchObj*)(dst),n); insilmaril@721: selection.update(); insilmaril@721: } insilmaril@721: } else if (typeid(*dst) == typeid(MapCenterObj) ) insilmaril@721: { insilmaril@721: selb->linkTo ((BranchObj*)(dst),-1); insilmaril@721: // Get coordinates of mainbranch insilmaril@721: x=parser.parDouble(ok,2); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: y=parser.parDouble(ok,3); insilmaril@721: if (ok) insilmaril@721: { insilmaril@753: selbi->move (x,y); insilmaril@721: selection.update(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@735: } else if ( selectionType() == TreeItem::Image) insilmaril@721: { insilmaril@721: if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: // 0 selectstring of parent insilmaril@721: s=parser.parString(ok,0); insilmaril@721: LinkableMapObj *dst=findObjBySelect (s); insilmaril@721: if (dst) insilmaril@721: { insilmaril@721: if (typeid(*dst) == typeid(BranchObj) || insilmaril@721: typeid(*dst) == typeid(MapCenterObj)) insilmaril@721: linkFloatImageTo (getSelectString(dst)); insilmaril@721: } else insilmaril@721: parser.setError (Aborted,"Destination is not a branch"); insilmaril@721: } insilmaril@721: } else insilmaril@721: parser.setError (Aborted,"Type of selection is not a floatimage or branch"); insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@753: } 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@721: if (ok) loadFloatImageInt (s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="moveBranchUp") 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: moveBranchUp(); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="moveBranchDown") 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: moveBranchDown(); 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@721: FloatImageObj *fio=selection.getFloatImage(); insilmaril@721: if (!fio) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not an image"); insilmaril@721: } else if (parser.checkParCount(2)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: t=parser.parString(ok,1); insilmaril@721: if (ok) saveFloatImageInt (fio,t,s); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="scroll") insilmaril@721: { insilmaril@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@721: } else if (com=="setFrameType") insilmaril@721: { insilmaril@735: if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection does not allow setting frame type"); insilmaril@721: } insilmaril@721: else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) setFrameType (s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setFramePenColor") insilmaril@721: { insilmaril@735: if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection does not allow setting of pen color"); insilmaril@721: } insilmaril@721: else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: QColor c=parser.parColor(ok,0); insilmaril@721: if (ok) setFramePenColor (c); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setFrameBrushColor") insilmaril@721: { insilmaril@735: if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection does not allow setting brush color"); insilmaril@721: } insilmaril@721: else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: QColor c=parser.parColor(ok,0); insilmaril@721: if (ok) setFrameBrushColor (c); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setFramePadding") insilmaril@721: { insilmaril@735: if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection does not allow setting frame padding"); insilmaril@721: } insilmaril@721: else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: n=parser.parInt(ok,0); insilmaril@721: if (ok) setFramePadding(n); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setFrameBorderWidth") insilmaril@721: { insilmaril@735: if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection does not allow setting frame border width"); insilmaril@721: } insilmaril@721: else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: n=parser.parInt(ok,0); insilmaril@721: if (ok) setFrameBorderWidth (n); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setMapAuthor") insilmaril@721: { insilmaril@721: if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) setAuthor (s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setMapComment") insilmaril@721: { insilmaril@721: if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) setComment(s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setMapBackgroundColor") insilmaril@721: { insilmaril@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) setMapBackgroundColor (c); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setMapDefLinkColor") 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) setMapDefLinkColor (c); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setMapLinkStyle") insilmaril@721: { insilmaril@721: if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString (ok,0); insilmaril@721: if (ok) setMapLinkStyle(s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@721: } else if (com=="setHeading") insilmaril@721: { insilmaril@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@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@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@753: else /* FIXME-2 if (com=="setFlag") 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: { insilmaril@721: selb->activateStandardFlag(s); insilmaril@721: selb->updateFlagsToolbar(); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@753: } else */ /* FIXME-2 if (com=="setFrameType") insilmaril@721: { insilmaril@750: if (!selti ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Nothing selected"); insilmaril@721: } else if (! selb ) insilmaril@721: { insilmaril@721: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@721: } else if (parser.checkParCount(1)) insilmaril@721: { insilmaril@721: s=parser.parString(ok,0); insilmaril@721: if (ok) insilmaril@721: setFrameType (s); insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@753: } 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@753: } else /* FIXME-2 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@721: { insilmaril@753: selbi->toggleStandardFlag(s); insilmaril@721: selb->updateFlagsToolbar(); insilmaril@721: } insilmaril@721: } insilmaril@721: ///////////////////////////////////////////////////////////////////// insilmaril@753: } 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@753: } else /* FIXME-2 if (com=="unsetFlag") insilmaril@721: { insilmaril@721: if (selection.isEmpty() ) 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: { insilmaril@721: selb->deactivateStandardFlag(s); insilmaril@721: selb->updateFlagsToolbar(); insilmaril@721: } insilmaril@721: } insilmaril@753: } 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@721: } insilmaril@721: else insilmaril@721: { insilmaril@721: // TODO Error handling insilmaril@721: qWarning("VymModel::parseAtom: Error!"); insilmaril@721: qWarning(parser.errorMessage()); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::runScript (QString script) insilmaril@721: { insilmaril@721: parser.setScript (script); insilmaril@721: parser.runScript(); insilmaril@721: while (parser.next() ) insilmaril@721: parseAtom(parser.getAtom()); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setExportMode (bool b) insilmaril@721: { insilmaril@721: // should be called before and after exports insilmaril@721: // depending on the settings insilmaril@721: if (b && settings.value("/export/useHideExport","true")=="true") insilmaril@753: setHideTmpMode (TreeItem::HideExport); insilmaril@721: else insilmaril@753: setHideTmpMode (TreeItem::HideNone); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::exportImage(QString fname, bool askName, QString format) insilmaril@721: { insilmaril@721: if (fname=="") insilmaril@721: { insilmaril@721: fname=getMapName()+".png"; insilmaril@721: format="PNG"; insilmaril@721: } insilmaril@721: insilmaril@721: if (askName) insilmaril@721: { insilmaril@721: QStringList fl; insilmaril@721: QFileDialog *fd=new QFileDialog (NULL); insilmaril@721: fd->setCaption (tr("Export map as image")); insilmaril@721: fd->setDirectory (lastImageDir); insilmaril@721: fd->setFileMode(QFileDialog::AnyFile); insilmaril@721: fd->setFilters (imageIO.getFilters() ); insilmaril@721: if (fd->exec()) insilmaril@721: { insilmaril@721: fl=fd->selectedFiles(); insilmaril@721: fname=fl.first(); insilmaril@721: format=imageIO.getType(fd->selectedFilter()); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: setExportMode (true); insilmaril@721: QPixmap pix (getPixmap()); insilmaril@721: pix.save(fname, format); insilmaril@721: setExportMode (false); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::exportXML(QString dir, bool askForName) insilmaril@721: { insilmaril@721: if (askForName) insilmaril@721: { insilmaril@721: dir=browseDirectory(NULL,tr("Export XML to directory")); insilmaril@721: if (dir =="" && !reallyWriteDirectory(dir) ) insilmaril@721: return; insilmaril@721: } insilmaril@721: insilmaril@721: // Hide stuff during export, if settings want this insilmaril@721: setExportMode (true); insilmaril@721: insilmaril@721: // Create subdirectories insilmaril@721: makeSubDirs (dir); insilmaril@721: insilmaril@721: // write to directory insilmaril@721: QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL); insilmaril@721: QFile file; insilmaril@721: insilmaril@721: file.setName ( dir + "/"+mapName+".xml"); insilmaril@721: if ( !file.open( QIODevice::WriteOnly ) ) insilmaril@721: { insilmaril@721: // This should neverever happen insilmaril@721: QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name())); insilmaril@721: return; insilmaril@721: } insilmaril@721: insilmaril@721: // Write it finally, and write in UTF8, no matter what insilmaril@721: QTextStream ts( &file ); insilmaril@721: ts.setEncoding (QTextStream::UnicodeUTF8); insilmaril@721: ts << saveFile; insilmaril@721: file.close(); insilmaril@721: insilmaril@721: // Now write image, too insilmaril@721: exportImage (dir+"/images/"+mapName+".png",false,"PNG"); insilmaril@721: insilmaril@721: setExportMode (false); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::exportASCII(QString fname,bool askName) insilmaril@721: { insilmaril@721: ExportASCII ex; insilmaril@721: ex.setModel (this); insilmaril@721: if (fname=="") insilmaril@721: ex.setFile (mapName+".txt"); insilmaril@721: else insilmaril@721: ex.setFile (fname); insilmaril@721: insilmaril@721: if (askName) insilmaril@721: { insilmaril@721: //ex.addFilter ("TXT (*.txt)"); insilmaril@721: ex.setDir(lastImageDir); insilmaril@721: //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)")); insilmaril@721: ex.execDialog() ; insilmaril@721: } insilmaril@721: if (!ex.canceled()) insilmaril@721: { insilmaril@721: setExportMode(true); insilmaril@721: ex.doExport(); insilmaril@721: setExportMode(false); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::exportXHTML (const QString &dir, bool askForName) insilmaril@721: { insilmaril@721: ExportXHTMLDialog dia(NULL); insilmaril@721: dia.setFilePath (filePath ); insilmaril@721: dia.setMapName (mapName ); insilmaril@721: dia.readSettings(); insilmaril@721: if (dir!="") dia.setDir (dir); insilmaril@721: insilmaril@721: bool ok=true; insilmaril@721: insilmaril@721: if (askForName) insilmaril@721: { insilmaril@721: if (dia.exec()!=QDialog::Accepted) insilmaril@721: ok=false; insilmaril@721: else insilmaril@721: { insilmaril@721: QDir d (dia.getDir()); insilmaril@721: // Check, if warnings should be used before overwriting insilmaril@721: // the output directory insilmaril@721: if (d.exists() && d.count()>0) insilmaril@721: { insilmaril@721: WarningDialog warn; insilmaril@721: warn.showCancelButton (true); insilmaril@721: warn.setText(QString( insilmaril@721: "The directory %1 is not empty.\n" insilmaril@721: "Do you risk to overwrite some of its contents?").arg(d.path() )); insilmaril@721: warn.setCaption("Warning: Directory not empty"); insilmaril@721: warn.setShowAgainName("mainwindow/overwrite-dir-xhtml"); insilmaril@721: insilmaril@721: if (warn.exec()!=QDialog::Accepted) ok=false; insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: if (ok) insilmaril@721: { insilmaril@721: exportXML (dia.getDir(),false ); insilmaril@721: dia.doExport(mapName ); insilmaril@721: //if (dia.hasChanged()) setChanged(); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::exportOOPresentation(const QString &fn, const QString &cf) insilmaril@721: { insilmaril@721: ExportOO ex; insilmaril@721: ex.setFile (fn); insilmaril@721: ex.setModel (this); insilmaril@721: if (ex.setConfigFile(cf)) insilmaril@721: { insilmaril@721: setExportMode (true); insilmaril@721: ex.exportPresentation(); insilmaril@721: setExportMode (false); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@650: insilmaril@652: ////////////////////////////////////////////// insilmaril@652: // View related insilmaril@652: ////////////////////////////////////////////// insilmaril@652: insilmaril@723: void VymModel::registerEditor(QWidget *me) insilmaril@721: { insilmaril@723: mapEditor=(MapEditor*)me; insilmaril@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@746: cout << "VM::updateNoteFlag()\n"; insilmaril@746: /* FIXME-1 modify note flag insilmaril@735: BranchObj *bo=getSelectedBranch(); insilmaril@721: if (bo) insilmaril@721: { insilmaril@721: bo->updateNoteFlag(); insilmaril@721: mainWindow->updateActions(); insilmaril@721: } insilmaril@746: */ insilmaril@721: } insilmaril@721: insilmaril@754: void VymModel::updateRelPositions() //FIXME-2 VM should have no need to updateRelPos insilmaril@754: { insilmaril@760: //cout << "VM::updateRelPos...\n"; insilmaril@754: for (int i=0; ibranchCount(); i++) insilmaril@754: ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions(); insilmaril@652: } insilmaril@652: insilmaril@761: void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views??? insilmaril@761: { insilmaril@761: //cout << "VM::reposition blocked="<branchCount(); i++) insilmaril@754: rootItem->getBranchObjNum(i)->reposition(); // for positioning heading insilmaril@652: } insilmaril@652: insilmaril@755: QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4 insilmaril@755: { insilmaril@755: /* insilmaril@665: // Creating (arbitrary) shapes insilmaril@665: insilmaril@665: QPolygonF p; insilmaril@665: QRectF rb=bo->getBBox(); insilmaril@665: if (bo->getDepth()==0) insilmaril@665: { insilmaril@665: // Just take BBox of this mapCenter insilmaril@665: p<getTotalBBox(); insilmaril@665: if (bo->getOrientation()==LinkableMapObj::LeftOfCenter) insilmaril@665: p <branchCount(); i++) insilmaril@665: { insilmaril@754: boB=rootItem->getBranchNum(i); insilmaril@665: pA=shape (boA); insilmaril@665: pB=shape (boB); insilmaril@665: PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0)); insilmaril@665: cout <<"------->" insilmaril@665: <<"="<getHeading() )<<")" insilmaril@665: <<" with ("<< qPrintable (boB->getHeading() ) insilmaril@665: <<") willIntersect" insilmaril@665: <getLMO() ); insilmaril@721: bo->setLinkStyle(bo->getDefLinkStyle()); insilmaril@741: cur=next(cur,prev,d); insilmaril@721: } insilmaril@721: reposition(); insilmaril@721: } insilmaril@721: insilmaril@721: LinkableMapObj::Style VymModel::getMapLinkStyle () insilmaril@721: { insilmaril@721: return linkstyle; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setMapDefLinkColor(QColor col) insilmaril@721: { insilmaril@721: if ( !col.isValid() ) return; insilmaril@721: saveState ( insilmaril@721: QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()), insilmaril@721: QString("setMapDefLinkColor (\"%1\")").arg(col.name()), insilmaril@721: QString("Set map link color to %1").arg(col.name()) insilmaril@721: ); insilmaril@721: insilmaril@721: defLinkColor=col; insilmaril@750: BranchItem *cur=NULL; insilmaril@750: BranchItem *prev=NULL; insilmaril@741: int d=0; insilmaril@721: BranchObj *bo; insilmaril@741: cur=next(cur,prev,d); insilmaril@741: while (cur) insilmaril@721: { insilmaril@741: bo=(BranchObj*)(cur->getLMO() ); insilmaril@721: bo->setLinkColor(); insilmaril@741: next(cur,prev,d); insilmaril@721: } insilmaril@721: updateActions(); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setMapLinkColorHintInt() insilmaril@721: { insilmaril@721: // called from setMapLinkColorHint(lch) or at end of parse insilmaril@750: BranchItem *cur=NULL; insilmaril@750: BranchItem *prev=NULL; insilmaril@741: int d=0; insilmaril@721: BranchObj *bo; insilmaril@741: cur=next(cur,prev,d); insilmaril@741: while (cur) insilmaril@721: { insilmaril@741: bo=(BranchObj*)(cur->getLMO() ); insilmaril@721: bo->setLinkColor(); insilmaril@741: cur=next(cur,prev,d); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch) insilmaril@721: { insilmaril@721: linkcolorhint=lch; insilmaril@721: setMapLinkColorHintInt(); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::toggleMapLinkColorHint() insilmaril@721: { insilmaril@721: if (linkcolorhint==LinkableMapObj::HeadingColor) insilmaril@721: linkcolorhint=LinkableMapObj::DefaultColor; insilmaril@721: else insilmaril@721: linkcolorhint=LinkableMapObj::HeadingColor; insilmaril@750: BranchItem *cur=NULL; insilmaril@750: BranchItem *prev=NULL; insilmaril@741: int d=0; insilmaril@721: BranchObj *bo; insilmaril@741: cur=next(cur,prev,d); insilmaril@741: while (cur) insilmaril@721: { insilmaril@741: bo=(BranchObj*)(cur->getLMO() ); insilmaril@721: bo->setLinkColor(); insilmaril@741: next(cur,prev,d); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@746: void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME insilmaril@721: { insilmaril@721: Q3FileDialog *fd=new Q3FileDialog( NULL); insilmaril@721: fd->setMode (Q3FileDialog::ExistingFile); insilmaril@721: fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); insilmaril@721: ImagePreview *p =new ImagePreview (fd); insilmaril@721: fd->setContentsPreviewEnabled( TRUE ); insilmaril@721: fd->setContentsPreview( p, p ); insilmaril@721: fd->setPreviewMode( Q3FileDialog::Contents ); insilmaril@721: fd->setCaption(vymName+" - " +tr("Load background image")); insilmaril@721: fd->setDir (lastImageDir); insilmaril@721: fd->show(); insilmaril@721: insilmaril@721: if ( fd->exec() == QDialog::Accepted ) insilmaril@721: { insilmaril@721: // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory(); insilmaril@721: lastImageDir=QDir (fd->dirPath()); insilmaril@721: setMapBackgroundImage (fd->selectedFile()); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@746: void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate insilmaril@721: { insilmaril@721: QColor oldcol=mapScene->backgroundBrush().color(); insilmaril@721: /* insilmaril@721: saveState( insilmaril@721: selection, insilmaril@721: QString ("setMapBackgroundImage (%1)").arg(oldcol.name()), insilmaril@721: selection, insilmaril@721: QString ("setMapBackgroundImage (%1)").arg(col.name()), insilmaril@721: QString("Set background color of map to %1").arg(col.name())); insilmaril@721: */ insilmaril@721: QBrush brush; insilmaril@721: brush.setTextureImage (QPixmap (fn)); insilmaril@721: mapScene->setBackgroundBrush(brush); insilmaril@721: } insilmaril@721: insilmaril@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@753: void VymModel::move(const double &x, const double &y) // FIXME-3 insilmaril@753: { insilmaril@753: int i=x; i=y; insilmaril@753: /* insilmaril@735: BranchObj *bo = getSelectedBranch(); insilmaril@735: if (bo && insilmaril@735: (selectionType()==TreeItem::Branch || insilmaril@735: selectionType()==TreeItem::MapCenter || insilmaril@735: selectionType()==TreeItem::Image insilmaril@735: )) insilmaril@721: { insilmaril@735: QPointF ap(bo->getAbsPos()); insilmaril@721: QPointF to(x, y); insilmaril@721: if (ap != to) insilmaril@721: { insilmaril@721: QString ps=qpointfToString(ap); insilmaril@735: QString s=getSelectString(); insilmaril@721: saveState( insilmaril@721: s, "move "+ps, insilmaril@721: s, "move "+qpointfToString(to), insilmaril@735: QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps)); insilmaril@735: bo->move(x,y); insilmaril@721: reposition(); insilmaril@721: selection.update(); insilmaril@721: } insilmaril@721: } insilmaril@753: */ insilmaril@721: } insilmaril@721: insilmaril@753: void VymModel::moveRel (const double &x, const double &y) // FIXME-3 insilmaril@753: { insilmaril@753: int i=x; i=y; insilmaril@753: /* insilmaril@735: BranchObj *bo = getSelectedBranch(); insilmaril@735: if (bo && insilmaril@735: (selectionType()==TreeItem::Branch || insilmaril@735: selectionType()==TreeItem::MapCenter || insilmaril@735: selectionType()==TreeItem::Image insilmaril@735: )) insilmaril@735: if (bo) insilmaril@721: { insilmaril@735: QPointF rp(bo->getRelPos()); insilmaril@721: QPointF to(x, y); insilmaril@721: if (rp != to) insilmaril@721: { insilmaril@735: QString ps=qpointfToString (bo->getRelPos()); insilmaril@735: QString s=getSelectString(bo); insilmaril@721: saveState( insilmaril@721: s, "moveRel "+ps, insilmaril@721: s, "moveRel "+qpointfToString(to), insilmaril@735: QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps)); insilmaril@735: ((OrnamentedObj*)bo)->move2RelPos (x,y); insilmaril@721: reposition(); insilmaril@735: bo->updateLink(); insilmaril@721: selection.update(); insilmaril@721: } insilmaril@721: } insilmaril@753: */ 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@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@721: sendData (QString("select (\"%1\")").arg(selection.getSelectString()) ); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::newServer() insilmaril@721: { insilmaril@721: port=54321; insilmaril@721: sendCounter=0; insilmaril@721: tcpServer = new QTcpServer(this); insilmaril@721: if (!tcpServer->listen(QHostAddress::Any,port)) { insilmaril@721: QMessageBox::critical(NULL, "vym server", insilmaril@721: QString("Unable to start the server: %1.").arg(tcpServer->errorString())); insilmaril@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@721: cout << " t="<errorString())); insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::selectMapSelectionColor() insilmaril@721: { insilmaril@721: QColor col = QColorDialog::getColor( defLinkColor, NULL); insilmaril@721: setSelectionColor (col); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::setSelectionColorInt (QColor col) insilmaril@721: { insilmaril@721: if ( !col.isValid() ) return; insilmaril@721: saveState ( insilmaril@728: QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()), insilmaril@721: QString("setSelectionColor (%1)").arg(col.name()), insilmaril@721: QString("Set color of selection box to %1").arg(col.name()) insilmaril@721: ); insilmaril@721: insilmaril@728: mapEditor->setSelectionColor (col); insilmaril@721: } insilmaril@721: insilmaril@746: /* insilmaril@746: void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel) insilmaril@746: { insilmaril@746: cout << "VymModel::changeSelection ("; insilmaril@746: if (!newsel.indexes().isEmpty() ) insilmaril@746: cout << getItem(newsel.indexes().first() )->getHeading().toStdString(); insilmaril@746: cout << ","; insilmaril@746: if (!oldsel.indexes().isEmpty() ) insilmaril@746: cout << getItem(oldsel.indexes().first() )->getHeading().toStdString(); insilmaril@746: cout << ")\n"; insilmaril@735: } insilmaril@746: */ insilmaril@735: insilmaril@742: void VymModel::updateSelection(const QItemSelection &newsel) insilmaril@735: { insilmaril@742: emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor insilmaril@735: ensureSelectionVisible(); insilmaril@735: sendSelection(); insilmaril@721: } insilmaril@721: insilmaril@746: void VymModel::updateSelection() insilmaril@746: { insilmaril@746: QItemSelection newsel=selModel->selection(); insilmaril@746: updateSelection (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@721: insilmaril@754: QRectF VymModel::getTotalBBox() //FIXME-2 insilmaril@721: { insilmaril@721: QRectF r; insilmaril@754: /* insilmaril@754: for (int i=0;ibranchCount(); i++) insilmaril@754: r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r); insilmaril@754: */ insilmaril@721: return r; insilmaril@721: } insilmaril@652: insilmaril@652: ////////////////////////////////////////////// insilmaril@652: // Selection related insilmaril@652: ////////////////////////////////////////////// insilmaril@652: insilmaril@727: void VymModel::setSelectionModel (QItemSelectionModel *sm) insilmaril@727: { insilmaril@727: selModel=sm; insilmaril@728: } 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@721: if (b) insilmaril@721: selection.block(); insilmaril@721: else insilmaril@721: selection.unblock(); insilmaril@721: } insilmaril@721: insilmaril@721: bool VymModel::isSelectionBlocked() insilmaril@721: { insilmaril@721: return selection.isBlocked(); insilmaril@721: } insilmaril@721: insilmaril@727: bool VymModel::select () insilmaril@727: { insilmaril@727: QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet insilmaril@727: insilmaril@745: TreeItem *item = getItem (index); insilmaril@727: return select (item->getLMO() ); insilmaril@727: } insilmaril@727: insilmaril@721: bool VymModel::select (const QString &s) insilmaril@721: { insilmaril@754: TreeItem *ti=findBySelectString(s); insilmaril@754: if (ti) insilmaril@721: { insilmaril@735: unselect(); insilmaril@754: select (ti); insilmaril@721: return true; insilmaril@735: } insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@721: bool VymModel::select (LinkableMapObj *lmo) insilmaril@721: { insilmaril@735: QItemSelection oldsel=selModel->selection(); insilmaril@735: insilmaril@735: if (lmo) insilmaril@738: return select (lmo->getTreeItem() ); insilmaril@738: else insilmaril@738: return false; insilmaril@738: } insilmaril@738: insilmaril@738: bool VymModel::select (TreeItem *ti) insilmaril@738: { insilmaril@738: if (ti) insilmaril@721: { insilmaril@735: QModelIndex ix=index(ti); insilmaril@735: selModel->select (ix,QItemSelectionModel::ClearAndSelect ); insilmaril@738: ti->setLastSelectedBranch(); insilmaril@721: return true; insilmaril@721: } insilmaril@721: return false; insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::unselect() insilmaril@721: { insilmaril@735: selModel->clearSelection(); insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::reselect() insilmaril@721: { insilmaril@721: selection.reselect(); insilmaril@721: } insilmaril@721: insilmaril@746: void VymModel::ensureSelectionVisible() //FIXME-3 needed? in vymmodel.h commented... insilmaril@721: { insilmaril@735: LinkableMapObj *lmo=getSelectedLMO(); insilmaril@721: if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() ); 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@753: emit (dataHasChanged (ix) ); insilmaril@721: } insilmaril@721: insilmaril@750: insilmaril@750: //void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed? insilmaril@750: /* insilmaril@721: { insilmaril@721: if (selection.select(lmo)) insilmaril@721: { insilmaril@729: //selection.update(); insilmaril@746: sendSelection (); // FIXME-4 VM use signal insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@750: void VymModel::selectInt (TreeItem *ti) insilmaril@750: { insilmaril@750: if (selection.select(lmo)) insilmaril@750: { insilmaril@750: //selection.update(); insilmaril@750: sendSelection (); // FIXME-4 VM use signal insilmaril@750: } insilmaril@750: } insilmaril@750: */ insilmaril@721: insilmaril@721: void VymModel::selectNextBranchInt() insilmaril@721: { insilmaril@755: BranchItem *bi=getSelectedBranchItem(); insilmaril@755: if (bi) insilmaril@721: { insilmaril@755: TreeItem *pi=bi->parent(); insilmaril@755: if (bi!=rootItem) insilmaril@755: { insilmaril@755: int i=bi->num(); insilmaril@755: if (ibranchCount() ) insilmaril@755: { insilmaril@755: // select previous branch with same parent insilmaril@755: i++; insilmaril@755: select (pi->getBranchNum(i)); insilmaril@755: return; insilmaril@755: } insilmaril@755: } insilmaril@721: insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@755: void VymModel::selectPrevBranchInt() insilmaril@755: { insilmaril@755: insilmaril@755: BranchItem *bi=getSelectedBranchItem(); insilmaril@755: if (bi) insilmaril@755: { insilmaril@755: BranchItem *pi=(BranchItem*)bi->parent(); insilmaril@755: if (bi!=rootItem) insilmaril@755: { insilmaril@755: int i=bi->num(); insilmaril@755: if (i>0) insilmaril@755: { insilmaril@755: // select previous branch with same parent insilmaril@755: bi=pi->getBranchNum(i-1); insilmaril@755: select (bi); insilmaril@755: return; insilmaril@755: } insilmaril@755: bi=pi; insilmaril@755: while (bi->branchCount() >0) insilmaril@755: bi=bi->getLastBranch(); insilmaril@755: select (bi); insilmaril@755: insilmaril@755: // Try to select last branch in parent pi2 previous to own parent pi insilmaril@755: /* insilmaril@755: TreeItem *pi2=pi->parent(); insilmaril@755: if (pi2) insilmaril@755: { insilmaril@755: int j=pi->num(); insilmaril@755: if (pi2->) insilmaril@755: } insilmaril@755: */ insilmaril@755: } insilmaril@755: } insilmaril@755: } insilmaril@755: insilmaril@755: void VymModel::selectAboveBranchInt() insilmaril@755: { insilmaril@755: BranchItem *bi=getSelectedBranchItem(); insilmaril@755: if (bi) insilmaril@755: { insilmaril@755: BranchItem *newbi=NULL; insilmaril@755: BranchItem *pi=(BranchItem*)bi->parent(); insilmaril@755: int i=bi->num(); insilmaril@755: if (i>0) insilmaril@755: { insilmaril@755: // goto previous branch with same parent insilmaril@755: newbi=pi->getBranchNum(i-1); insilmaril@755: while (newbi->branchCount() >0 ) insilmaril@755: newbi=newbi->getLastBranch(); insilmaril@755: } insilmaril@755: else insilmaril@755: newbi=pi; insilmaril@755: if (newbi==rootItem) insilmaril@755: // already at top branch (resp. mapcenter) insilmaril@755: return; insilmaril@755: select (newbi); insilmaril@755: } insilmaril@755: } insilmaril@755: insilmaril@755: void VymModel::selectBelowBranchInt() insilmaril@755: { insilmaril@755: BranchItem *bi=getSelectedBranchItem(); insilmaril@755: if (bi) insilmaril@755: { insilmaril@755: BranchItem *newbi=NULL; insilmaril@755: insilmaril@755: if (bi->branchCount() >0) insilmaril@755: newbi=bi->getFirstBranch(); insilmaril@755: else insilmaril@755: { insilmaril@755: BranchItem *pi; insilmaril@755: int i; insilmaril@755: while (!newbi) insilmaril@755: { insilmaril@755: pi=(BranchItem*)bi->parent(); insilmaril@755: i=bi->num(); insilmaril@755: if (pi->branchCount()-1 > i) insilmaril@755: { insilmaril@755: newbi=(BranchItem*)pi->getBranchNum(i+1); insilmaril@755: //done... insilmaril@755: break; insilmaril@755: } insilmaril@755: else insilmaril@755: // look for siblings of myself insilmaril@755: // or parent, or parent of parent... insilmaril@755: bi=pi; insilmaril@755: if (bi==rootItem) insilmaril@755: // already at end insilmaril@755: return; insilmaril@755: } insilmaril@755: } insilmaril@755: select (newbi); insilmaril@755: } insilmaril@755: } insilmaril@755: insilmaril@755: void VymModel::selectUpperBranch() insilmaril@755: { insilmaril@755: if (selection.isBlocked() ) return; insilmaril@755: insilmaril@755: BranchItem *bi=getSelectedBranchItem(); insilmaril@755: if (bi && bi->isBranchLikeType()) insilmaril@755: selectAboveBranchInt(); insilmaril@755: } insilmaril@755: insilmaril@721: void VymModel::selectLowerBranch() insilmaril@721: { insilmaril@721: if (selection.isBlocked() ) return; insilmaril@721: insilmaril@753: BranchItem *bi=getSelectedBranchItem(); insilmaril@755: if (bi && bi->isBranchLikeType()) insilmaril@755: selectBelowBranchInt(); insilmaril@721: } insilmaril@721: insilmaril@721: insilmaril@721: void VymModel::selectLeftBranch() insilmaril@721: { insilmaril@721: if (selection.isBlocked() ) return; insilmaril@721: insilmaril@735: QItemSelection oldsel=selModel->selection(); insilmaril@735: insilmaril@753: BranchItem* par; insilmaril@753: BranchItem *selbi=getSelectedBranchItem(); insilmaril@753: TreeItem::Type type=selbi->getType(); insilmaril@753: if (selbi) insilmaril@721: { insilmaril@753: if (type == TreeItem::MapCenter) insilmaril@721: { insilmaril@753: QModelIndex ix=index(selbi); insilmaril@735: selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect ); insilmaril@721: } else insilmaril@721: { insilmaril@753: par=(BranchItem*)selbi->parent(); insilmaril@753: if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO... insilmaril@721: { insilmaril@735: // right of center insilmaril@753: if (type == TreeItem::Branch || insilmaril@753: type == TreeItem::Image) insilmaril@721: { insilmaril@753: QModelIndex ix=index (selbi->parent()); insilmaril@735: selModel->select (ix,QItemSelectionModel::ClearAndSelect ); insilmaril@721: } insilmaril@721: } else insilmaril@721: { insilmaril@735: // left of center insilmaril@753: if (type == TreeItem::Branch ) insilmaril@721: { insilmaril@754: cout << "VM::selLeft\n"; insilmaril@735: selectLastSelectedBranch(); insilmaril@735: return; insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::selectRightBranch() insilmaril@721: { insilmaril@721: if (selection.isBlocked() ) return; insilmaril@721: insilmaril@735: QItemSelection oldsel=selModel->selection(); insilmaril@735: insilmaril@753: BranchItem* par; insilmaril@753: BranchItem *selbi=getSelectedBranchItem(); insilmaril@753: TreeItem::Type type=selbi->getType(); insilmaril@753: if (selbi) insilmaril@721: { insilmaril@753: if (type==TreeItem::MapCenter) insilmaril@721: { insilmaril@753: QModelIndex ix=index(selbi); insilmaril@737: selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect ); insilmaril@721: } else insilmaril@721: { insilmaril@753: par=(BranchItem*)selbi->parent(); insilmaril@753: if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO insilmaril@721: { insilmaril@737: // right of center insilmaril@753: if ( type== TreeItem::Branch ) insilmaril@737: { insilmaril@737: selectLastSelectedBranch(); insilmaril@737: return; insilmaril@737: } insilmaril@737: } else insilmaril@737: { insilmaril@737: // left of center insilmaril@753: if (type == TreeItem::Branch || insilmaril@753: type == TreeItem::Image) insilmaril@721: { insilmaril@754: cout << "VM::selRight\n"; insilmaril@753: QModelIndex ix=index(selbi->parent()); insilmaril@735: selModel->select (ix,QItemSelectionModel::ClearAndSelect ); insilmaril@721: } insilmaril@721: } insilmaril@737: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::selectFirstBranch() insilmaril@721: { insilmaril@738: TreeItem *ti=getSelectedBranchItem(); insilmaril@738: if (ti) insilmaril@721: { insilmaril@738: TreeItem *par=ti->parent(); insilmaril@721: if (!par) return; insilmaril@738: TreeItem *ti2=par->getFirstBranch(); insilmaril@738: if (ti2) { insilmaril@738: select(ti2); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: sendSelection(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@721: void VymModel::selectLastBranch() insilmaril@721: { insilmaril@738: TreeItem *ti=getSelectedBranchItem(); insilmaril@738: if (ti) insilmaril@721: { insilmaril@738: TreeItem *par=ti->parent(); insilmaril@721: if (!par) return; insilmaril@738: TreeItem *ti2=par->getLastBranch(); insilmaril@738: if (ti2) { insilmaril@738: select(ti2); insilmaril@721: selection.update(); insilmaril@721: ensureSelectionVisible(); insilmaril@721: sendSelection(); insilmaril@721: } insilmaril@721: } insilmaril@721: } insilmaril@721: insilmaril@735: void VymModel::selectLastSelectedBranch() insilmaril@735: { insilmaril@738: TreeItem *ti=getSelectedBranchItem(); insilmaril@738: if (ti) insilmaril@735: { insilmaril@738: ti=ti->getLastSelectedBranch(); insilmaril@738: if (ti) select (ti); insilmaril@735: } insilmaril@735: } insilmaril@735: insilmaril@726: void VymModel::selectParent() insilmaril@726: { insilmaril@738: TreeItem *ti=getSelectedItem(); insilmaril@738: TreeItem *par; insilmaril@738: if (ti) insilmaril@726: { insilmaril@738: par=ti->parent(); insilmaril@726: if (!par) return; insilmaril@735: select(par); insilmaril@726: selection.update(); insilmaril@726: ensureSelectionVisible(); insilmaril@726: sendSelection(); insilmaril@726: } insilmaril@726: } insilmaril@726: insilmaril@735: TreeItem::Type VymModel::selectionType() insilmaril@721: { insilmaril@735: QModelIndexList list=selModel->selectedIndexes(); insilmaril@735: if (list.isEmpty()) return TreeItem::Undefined; insilmaril@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@735: { insilmaril@735: return ti->getLMO(); insilmaril@735: } 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@738: TreeItem *ti = getSelectedBranchItem(); insilmaril@738: if (ti) insilmaril@738: return (BranchObj*)ti->getLMO(); insilmaril@738: else insilmaril@738: return NULL; insilmaril@738: } insilmaril@738: insilmaril@749: BranchItem* VymModel::getSelectedBranchItem() 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@738: TreeItem* VymModel::getSelectedItem() insilmaril@735: { insilmaril@746: QModelIndexList list=selModel->selectedIndexes(); insilmaril@746: if (!list.isEmpty() ) insilmaril@746: return getItem (list.first() ); insilmaril@746: else insilmaril@746: return NULL; insilmaril@735: } insilmaril@735: insilmaril@735: QModelIndex VymModel::getSelectedIndex() insilmaril@735: { insilmaril@735: QModelIndexList list=selModel->selectedIndexes(); insilmaril@735: if (list.isEmpty() ) insilmaril@735: return QModelIndex(); insilmaril@735: else insilmaril@735: return list.first(); insilmaril@652: } insilmaril@652: insilmaril@721: FloatImageObj* VymModel::getSelectedFloatImage() insilmaril@652: { insilmaril@721: return selection.getFloatImage(); insilmaril@721: } insilmaril@721: insilmaril@721: QString VymModel::getSelectString () insilmaril@721: { insilmaril@738: LinkableMapObj *lmo=getSelectedLMO(); insilmaril@738: if (lmo) insilmaril@738: return getSelectString(lmo); insilmaril@738: else insilmaril@738: return QString(); insilmaril@652: } insilmaril@652: insilmaril@749: QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below... insilmaril@749: { insilmaril@749: if (!lmo) return QString(); insilmaril@749: return getSelectString (lmo->getTreeItem() ); insilmaril@749: } insilmaril@749: insilmaril@749: QString VymModel::getSelectString (TreeItem *ti) insilmaril@652: { insilmaril@652: QString s; insilmaril@749: if (!ti) return s; insilmaril@749: if (ti->getType() == TreeItem::Branch || insilmaril@749: ti->getType() == TreeItem::MapCenter) insilmaril@652: { insilmaril@749: TreeItem *par=ti->parent(); insilmaril@652: if (par) insilmaril@652: { insilmaril@749: if (ti->depth() ==1) insilmaril@652: // Mainbranch, return insilmaril@749: s= "bo:" + QString("%1").arg(ti->num() ); insilmaril@652: else insilmaril@652: // Branch, call myself recursively insilmaril@749: s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num()); insilmaril@652: } else insilmaril@652: { insilmaril@652: // MapCenter insilmaril@749: int i=rootItem->num(ti); insilmaril@652: if (i>=0) s=QString("mc:%1").arg(i); insilmaril@652: } insilmaril@652: } insilmaril@652: return s; insilmaril@652: } insilmaril@652: