diff -r 557239819c45 -r 70c41284cb48 mapeditor.cpp --- a/mapeditor.cpp Wed Aug 30 12:16:25 2006 +0000 +++ b/mapeditor.cpp Thu Aug 31 11:55:33 2006 +0000 @@ -123,7 +123,6 @@ extern QAction *actionSettingsAutoedit; extern QAction *actionSettingsAutoselectHeading; extern QAction *actionSettingsAutoselectText; -extern QAction *actionSettingsPasteNewHeading; extern QAction *actionSettingsUseFlagGroups; extern QMenu* branchContextMenu; @@ -184,14 +183,12 @@ linkcolorhint=DefaultColor; linkstyle=StylePolyParabel; - // Create bitmap cursors, patform dependant + // Create bitmap cursors, platform dependant #if defined(Q_OS_MACX) - handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png") ); - // set hot spot to tip of picker + handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png"),1,1 ); pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 ); #else - handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen16.png")); - // set hot spot to tip of picker + handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1); pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); #endif @@ -465,8 +462,8 @@ { // Save complete map, Undo will replace whole map saveState (CompleteMap, - NULL, "", - NULL, "", + "", "", + "", "", comment, mapCenter); } @@ -474,9 +471,12 @@ void MapEditor::saveStatePart(LinkableMapObj *undoSel, const QString &comment) { // save the selected part of the map, Undo will replace part of map + QString undoSelection=""; + if (undoSel) undoSelection=undoSel->getSelectString(); + saveState (PartOfMap, - undoSel, "", - NULL, "", + undoSelection, "", + "", "", comment, undoSel); } @@ -486,33 +486,63 @@ // selection does not change during action, // so just save commands for undo and redo // and use current selection + + QString sel; + if (selection) sel=selection->getSelectString(); + saveState (UndoCommand, - selection, uc, - selection, rc, + sel, uc, + sel, rc, comment, NULL); } -void MapEditor::saveStateX(LinkableMapObj *unsel, const QString &uc, const QString &comment) +void MapEditor::saveStateComData(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel) { - // TODO Is this still needed? + QString redoSelection=""; + if (redoSel) redoSelection=redoSel->getSelectString(); + QString undoSelection=""; + if (undoSel) undoSelection=undoSel->getSelectString(); + saveState (UndoCommand, - unsel, uc, - NULL, "FIXME-redoCom", //FIXME + undoSelection, uc, + redoSelection, "FIXME-redoCom", //FIXME + comment, + saveSel); +} + +void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) +{ + // "Normal" savestate: save commands, selections and comment + // so just save commands for undo and redo + // and use current selection + + QString redoSelection=""; + if (redoSel) redoSelection=redoSel->getSelectString(); + QString undoSelection=""; + if (undoSel) undoSelection=undoSel->getSelectString(); + + saveState (UndoCommand, + undoSelection, uc, + redoSelection, rc, comment, NULL); } -void MapEditor::saveStateComData(LinkableMapObj *unSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel) +void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment) { + // "Normal" savestate: save commands, selections and comment + // so just save commands for undo and redo + // and use current selection saveState (UndoCommand, - unSel, uc, - NULL, "FIXME-redoCom", //FIXME + undoSel, uc, + redoSel, rc, comment, - saveSel); + NULL); } -void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom, LinkableMapObj *redoSel, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel) + +void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel) { // Main saveState @@ -541,16 +571,6 @@ if (!d.exists()) makeSubDirs (bakMapDir); - // Save current selection - QString redoSelection=""; - if (redoSel) - redoSelection=redoSel->getSelectString(); - - // Save the object, which should be undone - QString undoSelection=""; - if (undoSel) - undoSelection=undoSel->getSelectString(); - // Save depending on how much needs to be saved if (!saveSel) backupXML=""; @@ -562,7 +582,7 @@ { undoCommand=undoCom; } - else if (savemode==PartOfMap && undoSel) + else if (savemode==PartOfMap ) { undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")"; } else @@ -630,10 +650,15 @@ if (api.checkParamCount(1) && selection ) { s=api.parString(ok,0); - if (ok) - { - if (select (s)) deleteSelection(); - } + if (ok &&select (s)) deleteSelection(); + } + } + else if (com=="addBranch") + { + if (api.checkParamCount(1) && selection ) + { + y=api.parInt (ok,0); + if (ok ) addNewBranchInt (y); } } else if (com=="linkBranchToPos") @@ -642,6 +667,9 @@ { 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) @@ -696,7 +724,12 @@ if (api.checkParamCount(1) ) { s=api.parString(ok,0); - if (ok) ((BranchObj*)selection)->activateStandardFlag(s); + if (ok) + { + BranchObj* bo=(BranchObj*)selection; + bo->activateStandardFlag(s); + bo->updateFlagsToolbar(); + } } } } @@ -707,7 +740,12 @@ if (api.checkParamCount(1) ) { s=api.parString(ok,0); - if (ok) ((BranchObj*)selection)->deactivateStandardFlag(s); + if (ok) + { + BranchObj* bo=(BranchObj*)selection; + bo->deactivateStandardFlag(s); + bo->updateFlagsToolbar(); + } } } } @@ -1286,12 +1324,17 @@ parseAtom (redoCommand); mapCenter->reposition(); - //if (!redoSelection.isEmpty()) - // select (redoSelection); - blockSaveState=false; -/* TODO remove testing -*/ + + undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); + undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail)); + undoSet.setEntry ("/history/curStep",QString::number(curStep)); + undoSet.writeSettings(histPath); + + updateActions(); + + /* TODO remove testing +*/ cout << "ME::redo() end\n"; cout << " undosAvail="<reposition(); - //if (!redoSelection.isEmpty()) - // select (redoSelection); - - undosAvail--; - if (undosAvail<1) - // Undo not longer available now - actionEditUndo->setEnabled (false); - else - curStep--; if (curStep<1) curStep=undosTotal; + curStep--; + if (curStep<1) curStep=undosTotal; redosAvail++; @@ -1367,7 +1397,7 @@ cout << " ---------------------------"<canMoveBranchUp()) return; par=(BranchObj*)(bo->getParObj()); selection->unselect(); - selection=par->moveBranchUp (bo); + bo=par->moveBranchUp (bo); // bo will be the one below selection selection->select(); - saveStateX(bo,"moveBranchDown ()",QString("Move up %1").arg(getName(bo))); + saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo))); mapCenter->reposition(); ensureSelectionVisible(); } @@ -1488,9 +1518,9 @@ if (!bo->canMoveBranchDown()) return; par=(BranchObj*)(bo->getParObj()); selection->unselect(); - selection=par->moveBranchDown(bo); + bo=par->moveBranchDown(bo); // bo will be the one above selection selection->select(); - saveStateX(bo,"moveBranchUp ()",QString("Move down %1").arg(getName(bo))); + saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo))); mapCenter->reposition(); ensureSelectionVisible(); } @@ -1573,68 +1603,84 @@ } } -void MapEditor::addNewBranch(int pos) +BranchObj* MapEditor::addNewBranchInt(int num) { + // Depending on pos: + // -3 insert in childs of parent above selection + // -2 add branch to selection + // -1 insert in childs of parent below selection + // 0..n insert in childs of parent at pos + BranchObj *newbo=NULL; if (selection && (typeid(*selection) == typeid(BranchObj) || typeid(*selection) == typeid(MapCenterObj) ) ) { - BranchObj* bo1 = (BranchObj*) selection; - - bool wasScrolled=false; - BranchObj *newbo=NULL; - if (pos==0) + BranchObj* bo = (BranchObj*) selection; + if (num==-2) { // save scroll state. If scrolled, automatically select // new branch in order to tmp unscroll parent... - wasScrolled=bo1->isScrolled(); - newbo=bo1->addBranch(); - } else + return bo->addBranch(); + + }else if (num==-1) { - BranchObj *parbo=(BranchObj*)(selection->getParObj()); - if (parbo) - { - if (pos<0) - // add above selection - newbo=parbo->insertBranch(bo1->getNum()); - else - // add below selection - newbo=parbo->insertBranch(bo1->getNum()+1); - } else - // This should not happen... - // ...but it happens if CTRL-A is pressed on MCO, - // ignore it then - return; - } - saveStateX(selection,QString ("delete (\"%1\")").arg(newbo->getSelectString()),QString("Add new branch to %1").arg(getName(bo1))); //TODO undoCommand - - LinkableMapObj *oldselection=selection; - - mapCenter->reposition(); - adjustCanvasSize(); - - - if (actionSettingsAutoedit->isOn() || - actionSettingsAutoselectHeading->isOn() ) + num=bo->getNum()+1; + bo=(BranchObj*)bo->getParObj(); + }else if (num==-3) { - selection->unselect(); - selection=newbo; - selection->select(); - if (actionSettingsPasteNewHeading->isOn() ) - { - BranchObj *bo2= (BranchObj*)selection; - bo2->setHeading(""); - } - if (actionSettingsAutoedit->isOn() ) - mainWindow->editHeading(); - if (!actionSettingsAutoselectHeading->isOn() - && !wasScrolled) + num=bo->getNum(); + bo=(BranchObj*)bo->getParObj(); + } + if (!bo) return bo; + newbo=bo->insertBranch(num); + } + return newbo; +} + +void MapEditor::addNewBranch(int pos) +{ + // Different meaning than num in addNewBranchInt! + // -1 add above + // 0 add as child + // +1 add below + if (selection && + (typeid(*selection) == typeid(BranchObj) || + typeid(*selection) == typeid(MapCenterObj) ) ) + { + BranchObj *bo = (BranchObj*) selection; + BranchObj *newbo; + newbo=addNewBranchInt (pos-2); + + if (newbo) + { + saveStateConstSelection ( + QString ("delete (\"%1\")").arg(newbo->getSelectString()), + QString ("addBranch (%1)").arg(pos-2), + QString ("Add new branch to %1").arg(getName(bo))); //TODO undoCommand + + LinkableMapObj *oldselection=selection; + + mapCenter->reposition(); + adjustCanvasSize(); + + + if (actionSettingsAutoedit->isOn() || + actionSettingsAutoselectHeading->isOn() ) { selection->unselect(); - selection=oldselection; + selection=newbo; selection->select(); - } - } + if (actionSettingsAutoedit->isOn() ) + mainWindow->editHeading(); + if (!actionSettingsAutoselectHeading->isOn() + )//&& !wasScrolled) //FIXME wasScrolled was moved to addNewBranchInt + { + selection->unselect(); + selection=oldselection; + selection->select(); + } + } + } } } @@ -1667,11 +1713,6 @@ selection->unselect(); selection=newbo; selection->select(); - if (actionSettingsPasteNewHeading->isOn() ) - { - BranchObj *bo2= (BranchObj*)selection; - bo2->setHeading(""); - } if (actionSettingsAutoedit->isOn() ) mainWindow->editHeading(); if (!actionSettingsAutoselectHeading->isOn() @@ -1784,7 +1825,6 @@ adjustCanvasSize(); } - } void MapEditor::selectNextBranchInt() @@ -3606,41 +3646,64 @@ // Reset the temporary drawn link to the original one ((LinkableMapObj*)selection)->unsetParObjTmp(); + // For Redo we may need to save original selection + QString orgSel=selection->getSelectString(); copyingObj=false; if (dst ) { - BranchObj* bs=((BranchObj*)selection); + BranchObj* bsel=(BranchObj*)selection; + BranchObj* bdst=(BranchObj*)dst; + + QString undoCom="linkBranchToPos (\""+ - (bs->getParObj())->getSelectString()+ + (bsel->getParObj())->getSelectString()+ "\","+ - QString("%1").arg(bs->getNum())+ + QString("%1").arg(bsel->getNum())+ ","+ QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")"; - // TODO we also could check, if dest and src are on same branch, - // then it would be sufficient to saveState of this branch // Modifiers allow to insert above/below dst if (e->state() & Qt::ShiftModifier) { - bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()); + bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()); } else if (e->state() & Qt::ControlModifier) { - bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1); + bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1); } else { - bs->moveBranchTo ((BranchObj*)(dst),-1); + bsel->moveBranchTo (bdst,-1); if (dst->getDepth()==0) - bs->move (savePos); + bsel->move (savePos); } - saveStateConstSelection (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) ); + QString redoCom="linkBranchToPos (\""+ + ((BranchObj*)(bsel->getParObj()))->getSelectString()+ + "\","+ + QString("%1").arg(bsel->getNum())+ + ","+ + QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ + ")"; + + saveState ( + selection->getSelectString(),undoCom, + orgSel,redoCom, + QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) ); } else if (selection->getDepth()==1) - // If we have moved mainbranch only save endposition - saveStateConstSelection("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos))); + { + // The select string might be different _after_ moving around. + // Therefor reposition and then use string of old selection, too + mapCenter->reposition(); + + QString ps=qpointToString ( ((BranchObj*)selection)->getAbsPos() ); + saveState( + selection->getSelectString(), "move "+qpointToString(movingObj_orgPos), + orgSel, "move "+ps, + QString("Move %1 to %2").arg(getName(selection)).arg(ps)); + } // Draw the original link, before selection was moved around mapCenter->reposition(); }