diff -r 43268373032d -r e265f07f2173 vymmodel.cpp --- a/vymmodel.cpp Wed Jun 09 13:14:08 2010 +0000 +++ b/vymmodel.cpp Mon Jun 14 13:59:17 2010 +0000 @@ -85,20 +85,14 @@ // Also no scene yet (should not be needed anyway) FIXME-3 VM mapScene=NULL; - // History + // States and IDs idLast++; mapID=idLast; mapChanged=false; mapDefault=true; mapUnsaved=false; - curStep=0; - redosAvail=0; - undosAvail=0; - - stepsTotal=settings.readNumEntry("/history/stepsTotal",100); - undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal)); - mainWindow->updateHistory (undoSet); + resetHistory(); // Create tmp dirs makeTmpDirectories(); @@ -516,6 +510,8 @@ // Reset timestamp to check for later updates of file fileChangedTime=QFileInfo (destPath).lastModified(); + + resetHistory(); } @@ -1062,7 +1058,7 @@ return false; } -void VymModel::undo() //FIXME-1 segfault when trying to undo in a brandnew map +void VymModel::undo() { // Can we undo at all? if (undosAvail<1) return; @@ -1180,6 +1176,17 @@ return (tmpMapDir+"/"+histName); } +void VymModel::resetHistory() +{ + curStep=0; + redosAvail=0; + undosAvail=0; + + stepsTotal=settings.readNumEntry("/history/stepsTotal",100); + undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal)); + mainWindow->updateHistory (undoSet); +} + void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel) { sendData(redoCom); //FIXME-3 testing @@ -1732,9 +1739,9 @@ QString ("setURL (\"%1\")").arg(url), QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url) ); + emitDataHasChanged (selti); reposition(); - emitDataHasChanged (selti); - emitShowSelection(); + emitSelectionChanged(); } } @@ -2274,12 +2281,12 @@ return NULL; } -BranchItem* VymModel::addMapCenter () +BranchItem* VymModel::addMapCenter (bool saveStateFlag) { BranchItem *bi=addMapCenter (contextPos); updateActions(); emitShowSelection(); - saveState ( + if (saveStateFlag) saveState ( bi, "delete()", NULL, @@ -3279,9 +3286,8 @@ } else parser.setError (Aborted,"Wrong number of parameters"); ///////////////////////////////////////////////////////////////////// - } else if (com==QString("addXLink")) //FIXME-2 not ported yet to Link - { - /* + } else if (com==QString("addXLink")) + { if (parser.parCount()>1) { s=parser.parString (ok,0); // begin @@ -3292,13 +3298,11 @@ { if (begin->isBranchLikeType() && end->isBranchLikeType()) { - XLinkItem *xl=createXLink (begin,true); - if (xl) - { - xl->setEnd (end); - xl->activate(); - } else - parser.setError (Aborted,"Failed to create xLink"); + Link *li=new Link (this); + li->setBeginBranch ( (BranchItem*)begin ); + li->setEndBranch ( (BranchItem*)end); + + createLink (li,true); // create MO by default } else parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter"); @@ -3307,7 +3311,6 @@ parser.setError (Aborted,"Couldn't select begin or end of xLink"); } else parser.setError (Aborted,"Need at least 2 parameters for begin and end"); - */ ///////////////////////////////////////////////////////////////////// } else if (com=="clearFlags") { @@ -3319,7 +3322,11 @@ parser.setError (Aborted,"Type of selection is not a branch"); } else if (parser.checkParCount(0)) { - selbi->deactivateAllStandardFlags(); //FIXME-2 this probably should emitDataChanged and also setChanged. Similar all other direct changes should be done... + selbi->deactivateAllStandardFlags(); + reposition(); + emitDataHasChanged(selbi); + emitSelectionChanged(); + setChanged(); } ///////////////////////////////////////////////////////////////////// } else if (com=="colorBranch") @@ -5156,6 +5163,21 @@ return false; } +bool VymModel::selectLastImage() +{ + TreeItem *ti=getSelectedBranch(); + if (ti) + { + TreeItem *par=ti->parent(); + if (par) + { + TreeItem *ti2=par->getLastImage(); + if (ti2) return select(ti2); + } + } + return false; +} + bool VymModel::selectParent() { TreeItem *ti=getSelectedItem();