diff -r 053b8645e3e9 -r 67cfa6e6b863 mapeditor.cpp --- a/mapeditor.cpp Wed Oct 18 10:45:00 2006 +0000 +++ b/mapeditor.cpp Tue Oct 24 15:36:38 2006 +0000 @@ -387,21 +387,33 @@ void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment) { - if (!redoSel ||typeid(*redoSel) != typeid(BranchObj) ) + if (!redoSel) { - qWarning ("MapEditor::saveStateRemovingPart no undoSel given!"); + qWarning ("MapEditor::saveStateRemovingPart no redoSel given!"); return; } - - // save the selected part of the map, Undo will insert part of map QString undoSelection=redoSel->getParObj()->getSelectString(); QString redoSelection=redoSel->getSelectString(); - - saveState (PartOfMap, - undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()), - redoSelection, "delete ()", - comment, - redoSel); + if (typeid(*redoSel) == typeid(BranchObj) && redoSel->getDepth()>1 ) + { + // save the selected branch of the map, Undo will insert part of map + saveState (PartOfMap, + undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()), + redoSelection, "delete ()", + comment, + redoSel); + } else if (typeid(*redoSel) == typeid(BranchObj) ) + { + // save the selected mainbranch of the map, Undo will insert part of map + saveState (PartOfMap, + undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()), +// undoSelection, QString("addMapInsert (\"PATH\",%1,%2)").arg(((BranchObj*)redoSel)->getNum()) +// .arg(((BranchObj*)redoSel)->x()).arg(((BranchObj*)redoSel)->y()), + redoSelection, "delete ()", + comment, + redoSel); + + } } void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment) @@ -545,81 +557,185 @@ bool ok; // Split string s into command and parameters - api.parseCommand (atom); + api.parseInput (atom); QString com=api.command(); // External commands if (com=="addBranch") { - if (api.checkParamCount(1) && selection ) + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else { - y=api.parInt (ok,0); - if (ok ) addNewBranchInt (y); - } + QList pl; + pl << 0 <<1; + if (api.checkParamCount(pl)) + { + if (api.paramCount()==0) + addNewBranchInt (-2); + else + { + y=api.parInt (ok,0); + if (ok ) addNewBranchInt (y); + } + } + } + } else if (com=="addBranchBefore") + { + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else + { + if (api.paramCount()==0) + { + addNewBranchBefore (); + } + } } else if (com==QString("addMapReplace")) { - if (api.checkParamCount(2)) + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else if (api.checkParamCount(2)) { s=api.parString (ok,0); // selection t=api.parString (ok,1); // path to map if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t); - addMapReplace(s,t); + addMapReplaceInt(s,t); } } else if (com==QString("addMapInsert")) { - if (api.checkParamCount(2)) + if (!selection) { - t=api.parString (ok,0); // path to map - y=api.parInt(ok,1); // position - if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t); - addMapInsert(t,y); + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else + { + if (api.checkParamCount(2)) + { + t=api.parString (ok,0); // path to map + y=api.parInt(ok,1); // position + if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t); + addMapInsertInt(t,y); + } } } else if (com=="delete") { - if (api.checkParamCount(0) && selection ) + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else if (api.checkParamCount(0)) { deleteSelection(); } + } else if (com=="deleteKeepChilds") + { + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else if (api.checkParamCount(0)) + { + removeBranchKeepChilds(); + } } else if (com=="linkBranchToPos") { - if (selection && typeid(*selection) == typeid(BranchObj) ) + if (!selection) { - if (api.checkParamCount(4)) - { - // 0 selectstring of parent - // 1 num in parent (for branches) - // 2,3 x,y of mainbranch or mapcenter - s=api.parString(ok,0); - LinkableMapObj *dst=mapCenter->findObjBySelect (s); - if (dst) - { - if (typeid(*dst) == typeid(BranchObj) ) + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else if (api.checkParamCount(4)) + { + // 0 selectstring of parent + // 1 num in parent (for branches) + // 2,3 x,y of mainbranch or mapcenter + s=api.parString(ok,0); + LinkableMapObj *dst=mapCenter->findObjBySelect (s); + if (dst) + { + if (typeid(*dst) == typeid(BranchObj) ) + { + // Get number in parent + x=api.parInt (ok,1); + if (ok) + ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x); + } else if (typeid(*dst) == typeid(MapCenterObj) ) + { + ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1); + // Get coordinates of mainbranch + x=api.parInt (ok,2); + if (ok) { - // Get number in parent - x=api.parInt (ok,1); - if (ok) - ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x); - } else if (typeid(*dst) == typeid(MapCenterObj) ) - { - ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1); - // Get coordinates of mainbranch - x=api.parInt (ok,2); - if (ok) - { - y=api.parInt (ok,3); - if (ok) ((BranchObj*)selection)->move (x,y); - } - } + y=api.parInt (ok,3); + if (ok) ((BranchObj*)selection)->move (x,y); + } } - } + } } } else if (com=="moveBranchUp") - moveBranchUp(); - else if (com=="moveBranchDown") - moveBranchDown(); - else if (com=="move") { - if (api.checkParamCount(2) && selection ) + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else if (api.checkParamCount(0)) + { + moveBranchUp(); + } + } else if (com=="moveBranchDown") + { + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else if (api.checkParamCount(0)) + { + moveBranchDown(); + } + } else if (com=="move") + { + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj) && + typeid(*selection) != typeid(FloatImageObj) ) + { + api.setError (Aborted,"Type of selection is not a branch or floatimage"); + } else if (api.checkParamCount(2)) { x=api.parInt (ok,0); if (ok) @@ -631,7 +747,15 @@ } else if (com=="moveRel") { - if (api.checkParamCount(2) && selection ) + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj) && + typeid(*selection) != typeid(FloatImageObj) ) + { + api.setError (Aborted,"Type of selection is not a branch or floatimage"); + } else if (api.checkParamCount(2)) { x=api.parInt (ok,0); if (ok) @@ -642,7 +766,14 @@ } } else if (com=="setHeading") { - if (api.checkParamCount(1)) + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else if (api.checkParamCount(1)) { s=api.parString (ok,0); if (ok) @@ -650,55 +781,98 @@ } } else if (com=="setURL") { - if (api.checkParamCount(1)) + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else if (api.checkParamCount(1)) { s=api.parString (ok,0); if (ok) setURLInt(s); } } else if (com=="setVymLink") { - if (api.checkParamCount(1)) + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else if (api.checkParamCount(1)) { s=api.parString (ok,0); if (ok) setVymLinkInt(s); } } + else if (com=="setHideExport") + { + if (!selection) + { + api.setError (Aborted,"Nothing selected"); + } else if ( typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj) && + typeid(*selection) != typeid(FloatImageObj) ) + { + api.setError (Aborted,"Type of selection is not a branch or floatimage"); + } else if (api.checkParamCount(2)) + { + s=api.parString(ok,0); + if (ok) + { + BranchObj* bo=(BranchObj*)selection; + bo->activateStandardFlag(s); + bo->updateFlagsToolbar(); + } + } + } else if (com=="setFlag") { - if (selection && typeid(*selection) == typeid(BranchObj) ) + if (!selection) { - if (api.checkParamCount(1) ) - { - s=api.parString(ok,0); - if (ok) - { - BranchObj* bo=(BranchObj*)selection; - bo->activateStandardFlag(s); - bo->updateFlagsToolbar(); - } + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else if (api.checkParamCount(1)) + { + s=api.parString(ok,0); + if (ok) + { + BranchObj* bo=(BranchObj*)selection; + bo->activateStandardFlag(s); + bo->updateFlagsToolbar(); } } } else if (com=="unsetFlag") { - if (selection && typeid(*selection) == typeid(BranchObj) ) + if (!selection) { - if (api.checkParamCount(1) ) - { - s=api.parString(ok,0); - if (ok) - { - BranchObj* bo=(BranchObj*)selection; - bo->deactivateStandardFlag(s); - bo->updateFlagsToolbar(); - } + api.setError (Aborted,"Nothing selected"); + } else if ( (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid(MapCenterObj)) ) + { + api.setError (Aborted,"Type of selection is not a branch"); + } else if (api.checkParamCount(1)) + { + s=api.parString(ok,0); + if (ok) + { + BranchObj* bo=(BranchObj*)selection; + bo->deactivateStandardFlag(s); + bo->updateFlagsToolbar(); } } // Internal commands } else if (com==QString("undoMap")) { if (api.checkParamCount(1)) - addMapReplace("",api.parString (ok,0)); + addMapReplaceInt("",api.parString (ok,0)); } else if (com=="select") { if (api.checkParamCount(1)) @@ -709,16 +883,18 @@ } else { - api.setError ("Unknown command in: "+atom); + api.setError (Aborted,"Unknown command"); } // Any errors? - if (api.error()) + if (api.errorLevel()==NoError) + setChanged(); + else { // TODO Error handling qWarning("MapEditor::parseAtom: Error!"); - qWarning(api.errorDesc()); - } + qWarning(api.errorMessage()); + } } void MapEditor::toggleHistoryWindow() @@ -1388,7 +1564,7 @@ // And ignore clicking the current row ;-) } -void MapEditor::addMapReplace(const QString &undoSel, const QString &path) +void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path) { QString pathDir=path.left(path.findRev("/")); QDir d(pathDir); @@ -1427,7 +1603,7 @@ QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); } -void MapEditor::addMapInsert(const QString &path, int pos) +void MapEditor::addMapInsertInt (const QString &path, int pos) { if (selection && (typeid(*selection) == typeid(BranchObj) || typeid(*selection) == typeid(MapCenterObj))) @@ -1436,20 +1612,6 @@ QDir d(pathDir); QFile file (path); - BranchObj *bo=addNewBranchInt (pos); - if (!bo) - { - - QMessageBox::critical( 0, tr( "Critical Error" ), - tr("Could insert branch at position %1\n in branch %2").arg(pos) - .arg(((BranchObj*)selection)->getHeading())); - return; - } - unselect(); - selection=bo; - selection->select(); - - if (d.exists() ) { // We need to parse saved XML data @@ -1460,7 +1622,7 @@ reader.setErrorHandler( &handler ); handler.setMapEditor( this ); handler.setTmpDir ( pathDir ); // needed to load files with rel. path - handler.setLoadMode (ImportReplace); + handler.setLoadMode (ImportAdd); blockReposition=true; bool ok = reader.parse( source ); blockReposition=false; @@ -1470,6 +1632,8 @@ QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), handler.errorProtocol()); } + if (selection!=mapCenter) + ((BranchObj*)selection)->getLastBranch()->moveBranchTo ((BranchObj*)(selection),pos); } else QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); } @@ -1689,18 +1853,19 @@ return newbo; } -void MapEditor::addNewBranch(int pos) +BranchObj* MapEditor::addNewBranch(int pos) { // Different meaning than num in addNewBranchInt! // -1 add above // 0 add as child // +1 add below + BranchObj *bo = (BranchObj*) selection; + BranchObj *newbo=NULL; + if (selection && (typeid(*selection) == typeid(BranchObj) || typeid(*selection) == typeid(MapCenterObj) ) ) { - BranchObj *bo = (BranchObj*) selection; - BranchObj *newbo; newbo=addNewBranchInt (pos-2); if (newbo) @@ -1711,72 +1876,44 @@ QString ("addBranch (%1)").arg(pos-2), QString ("Add new branch to %1").arg(getName(bo))); //TODO undoCommand - LinkableMapObj *oldselection=selection; - mapCenter->reposition(); adjustCanvasSize(); - - - if (mainWindow->autoEdit() || - mainWindow->autoSelectHeading() ) - { - selection->unselect(); - selection=newbo; - selection->select(); - if (mainWindow->autoEdit() ) - mainWindow->editHeading(); - if (!mainWindow->autoSelectHeading() - )//&& !wasScrolled) //FIXME wasScrolled was moved to addNewBranchInt - { - selection->unselect(); - selection=oldselection; - selection->select(); - } - } } } + return newbo; } -void MapEditor::addNewBranchHere() +BranchObj* MapEditor::addNewBranchBefore() { + BranchObj *newbo=NULL; if (selection && (typeid(*selection) == typeid(BranchObj) ) ) + // We accept no MapCenterObj here, so we _have_ a parent { - BranchObj* bo1 = (BranchObj*) selection; - saveStateChangingPart(selection, QString("Add new branch here").arg(getName(bo1))); - - bool wasScrolled=false; - BranchObj *newbo=NULL; + BranchObj* bo = (BranchObj*) selection; + QPoint p=bo->getRelPos(); + + BranchObj *parbo=(BranchObj*)(selection->getParObj()); - if (parbo) + + // add below selection + newbo=parbo->insertBranch(bo->getNum()+1); + if (newbo) { - // add below selection - newbo=parbo->insertBranch(bo1->getNum()+1); - } - - LinkableMapObj *oldselection=selection; - ((BranchObj*)selection)->moveBranchTo (newbo,-1); - - mapCenter->reposition(); - adjustCanvasSize(); - if (mainWindow->autoEdit() || - mainWindow->autoSelectHeading() ) - { - selection->unselect(); - selection=newbo; - selection->select(); - if (mainWindow->autoEdit() ) - mainWindow->editHeading(); - if (!mainWindow->autoSelectHeading() - && !wasScrolled) - { - selection->unselect(); - selection=oldselection; - selection->select(); - } - } + newbo->move2RelPos (p); + + // Move selection to new branch + ((BranchObj*)selection)->moveBranchTo (newbo,-1); + + saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()", + QString ("Add branch before %1").arg(getName(bo))); + + mapCenter->reposition(); + adjustCanvasSize(); + } } + return newbo; } void MapEditor::deleteSelection() @@ -1786,13 +1923,7 @@ BranchObj* bo=(BranchObj*)selection; BranchObj* par=(BranchObj*)(bo->getParObj()); bo->unselect(); - if (selection->getDepth()>1) - // Normal branch, save parent with childs - saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo))); - else - // Mainbranch, save whole map - // TODO Better would be to insert mainbranch again at pos But undoCommand is missing right now - saveStateComplete(QString("Delete %1").arg(getName(bo))); + saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo))); selection=NULL; par->removeBranch(bo); selection=par; @@ -2584,16 +2715,21 @@ { BranchObj* bo=(BranchObj*)selection; BranchObj* par=(BranchObj*)(bo->getParObj()); + QPoint p=bo->getRelPos(); QString s=QString("Remove %1 and keep its childs").arg(getName(bo)); if (bo->getDepth()==1) saveStateComplete(s); else saveStateChangingPart(selection->getParObj(),s); // TODO undoCommand + QString sel=selection->getSelectString(); unselect(); par->removeBranchHere(bo); mapCenter->reposition(); select (sel); + ((BranchObj*)selection)->move2RelPos (p); + mapCenter->reposition(); + adjustCanvasSize(); } } @@ -2601,6 +2737,7 @@ { if (selection && (typeid(*selection) == typeid(BranchObj) )) { + // TODO undoCommand saveStateChangingPart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection))); ((BranchObj*)selection)->removeChilds(); mapCenter->reposition(); @@ -3048,6 +3185,15 @@ { cout << "MapEditor::testFunction() called\n"; + if (selection && + (typeid(*selection) == typeid(BranchObj)) || + (typeid(*selection) == typeid(MapCenterObj)) ) + { + BranchObj* bo=(BranchObj*)selection; + cout << bo->getHeading().ascii() <<" is scrolled: "<isScrolled()<