diff -r db0ec4bcf416 -r ed5b407975b3 vymmodel.cpp --- a/vymmodel.cpp Mon Apr 20 10:42:05 2009 +0000 +++ b/vymmodel.cpp Thu Apr 23 12:15:31 2009 +0000 @@ -2008,10 +2008,9 @@ return mci; } -BranchItem* VymModel::createBranch() // FIXME-2 switcht addNewBrancInt to BranchItem... -{ - BranchObj* bo=addNewBranchInt (-2); - return (BranchItem*)bo->getTreeItem(); +BranchItem* VymModel::createBranch() +{ + return addNewBranchInt (-2); } TreeItem* VymModel::createImage() //FIXME-2 @@ -2123,7 +2122,7 @@ } -BranchObj* VymModel::addNewBranchInt(int num) +BranchItem* VymModel::addNewBranchInt(int num) { // Depending on pos: // -3 insert in children of parent above selection @@ -2158,6 +2157,8 @@ // save scroll state. If scrolled, automatically select // new branch in order to tmp unscroll parent... + newbo=bi->createMapObj(mapScene); + /* newbo=bo->addBranch(); if (newbo) @@ -2166,63 +2167,70 @@ newbo->setTreeItem (bi); select (bi); } + */ + select (bi); }else if (num==-1) { + /* num=bi->num()+1; bo=(BranchObj*)bo->getParObj(); if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing + */ }else if (num==-3) { + /* num=bi->num(); bo=(BranchObj*)bo->getParObj(); if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing + */ } } - return newbo; + return bi; } -BranchObj* VymModel::addNewBranch(int pos) +BranchItem* VymModel::addNewBranch(int pos) { // Different meaning than num in addNewBranchInt! // -1 add above // 0 add as child // +1 add below - BranchObj *bo = getSelectedBranchObj(); //FIXME-2 - BranchObj *newbo=NULL; - - if (bo) + BranchItem *newbi=NULL; + BranchItem *selbi=getSelectedBranchItem(); + + if (selbi) { // FIXME-2 VM do we still need this in model? setCursor (Qt::ArrowCursor); - newbo=addNewBranchInt (pos-2); - - if (newbo) + newbi=addNewBranchInt (pos-2); + + if (newbi) { saveState( - newbo->getTreeItem(), + newbi, "delete ()", - bo->getTreeItem(), + selbi, QString ("addBranch (%1)").arg(pos), - QString ("Add new branch to %1").arg(getObjectName(bo))); + QString ("Add new branch to %1").arg(getObjectName(selbi))); reposition(); // selection.update(); FIXME-3 - latestSelectionString=getSelectString(newbo); + latestSelectionString=getSelectString(newbi); // In Network mode, the client needs to know where the new branch is, // so we have to pass on this information via saveState. // TODO: Get rid of this positioning workaround - QString ps=qpointfToString (newbo->getAbsPos()); + /* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos()); sendData ("selectLatestAdded ()"); sendData (QString("move %1").arg(ps)); sendSelection(); + */ } } - return newbo; + return newbi; } -BranchObj* VymModel::addNewBranchBefore() //FIXME-2 +BranchItem* VymModel::addNewBranchBefore() //FIXME-2 { /* BranchObj *newbo=NULL; @@ -2258,6 +2266,22 @@ return NULL; } +BranchItem* VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos) +{ + cout << "VM::relinkBranch "<getHeadingStd()<<" to "<getHeadingStd()<<" at pos="<parent(); + BranchItem *dstpi=(BranchItem*)dst->parent(); + if (pos<0) + { + // Append as last branch to dst + branchpi->removeChild (branch->childNum() ); + dst->appendChild (branch); + } + } +} + void VymModel::deleteSelection() { BranchObj *bo = getSelectedBranchObj(); // FIXME-2 VM should not be necessary @@ -2319,7 +2343,7 @@ beginRemoveRows (parentIndex,n,n); removeRows (n,1,parentIndex); endRemoveRows(); - par->removeBranch(bo); // remove from BranchObj lists... + // delete (selbi->getLMO() ); // FIXME-0 selbi is removed implicetely, destructor is called. from there BO is deleted, but somhow still segfaulting :-( select (par); ensureSelectionVisible(); reposition(); @@ -3964,8 +3988,9 @@ rootItem->getBranchObjNum(i)->reposition(); // for positioning heading } -QPolygonF VymModel::shape(BranchObj *bo) -{ +QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4 +{ +/* // Creating (arbitrary) shapes QPolygonF p; @@ -3995,7 +4020,7 @@ <getDepth()>0) + if (bo && bo->getTreeItem()->depth()>0) { AnimPoint ap; ap.setStart (start); @@ -4710,197 +4735,136 @@ void VymModel::selectNextBranchInt() { - // Increase number of branch - BranchItem *selbi=getSelectedBranchItem(); - if (selbi) + BranchItem *bi=getSelectedBranchItem(); + if (bi) { - QString s=getSelectString(); - QString part; - QString typ; - QString num; - - // Where am I? - part=s.section(",",-1); - typ=part.left (3); - num=part.right(part.length() - 3); - - s=s.left (s.length() -num.length()); - - // Go to next lmo - num=QString ("%1").arg(num.toUInt()+1); - - s=s+num; + TreeItem *pi=bi->parent(); + if (bi!=rootItem) + { + int i=bi->num(); + if (ibranchCount() ) + { + // select previous branch with same parent + i++; + select (pi->getBranchNum(i)); + return; + } + } - // Try to select this one - if (select (s)) return; - - // We have no direct successor, - // try to increase the parental number in order to - // find a successor with same depth - - int d=getSelectedBranchItem()->depth(); - int oldDepth=d; - int i; - bool found=false; - bool b; - while (!found && d>0) - { - s=s.section (",",0,d-1); - // replace substring of current depth in s with "1" - part=s.section(",",-1); - typ=part.left (3); - num=part.right(part.length() - 3); - - if (d>1) - { - // increase number of parent - num=QString ("%1").arg(num.toUInt()+1); - s=s.section (",",0,d-2) + ","+ typ+num; - } else - { - // Special case, look at orientation - if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter) // FIXME-3 check access to LMO - num=QString ("%1").arg(num.toUInt()+1); - else - num=QString ("%1").arg(num.toUInt()-1); - s=typ+num; - } - - if (select (s)) - // pad to oldDepth, select the first branch for each depth - for (i=d;ibranchCount()>0) - s+=",bo:0"; - else - break; - } else - break; - } - - // try to select the freshly built string - found=select(s); - d--; - } - return; - } -} - -void VymModel::selectPrevBranchInt() -{ - // Decrease number of branch - if (selectionType()==TreeItem::Branch) - { - QString s=getSelectString(); - QString part; - QString typ; - QString num; - - // Where am I? - part=s.section(",",-1); - typ=part.left (3); - num=part.right(part.length() - 3); - - s=s.left (s.length() -num.length()); - - int n=num.toInt()-1; - - // Go to next lmo - num=QString ("%1").arg(n); - s=s+num; - - // Try to select this one - if (n>=0 && select (s)) return; - - // We have no direct precessor, - // try to decrease the parental number in order to - // find a precessor with same depth - - int d=getSelectedBranchItem()->depth(); - int oldDepth=d; - int i; - bool found=false; - bool b; - while (!found && d>0) - { - s=s.section (",",0,d-1); - // replace substring of current depth in s with "1" - part=s.section(",",-1); - typ=part.left (3); - num=part.right(part.length() - 3); - - if (d>1) - { - // decrease number of parent - num=QString ("%1").arg(num.toInt()-1); - s=s.section (",",0,d-2) + ","+ typ+num; - } else - { - // Special case, look at orientation - if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter) // FIXME-3 check access to LMO - num=QString ("%1").arg(num.toInt()-1); - else - num=QString ("%1").arg(num.toInt()+1); - s=typ+num; - } - - if (select(s)) - // pad to oldDepth, select the last branch for each depth - for (i=d;ibranchCount()>0) - s+=",bo:"+ QString ("%1").arg( getSelectedItem()->branchCount()-1 ); - else - break; - else - break; - } - - // try to select the freshly built string - found=select(s); - d--; - } - return; - } -} - -void VymModel::selectUpperBranch() -{ - if (selection.isBlocked() ) return; - - BranchItem *bi=getSelectedBranchItem(); - if (bi && bi->getType()==TreeItem::Branch) - { - if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO - selectPrevBranchInt(); - else - if (bi->depth()==1) - selectNextBranchInt(); - else - selectPrevBranchInt(); } } +void VymModel::selectPrevBranchInt() +{ + + BranchItem *bi=getSelectedBranchItem(); + if (bi) + { + BranchItem *pi=(BranchItem*)bi->parent(); + if (bi!=rootItem) + { + int i=bi->num(); + if (i>0) + { + // select previous branch with same parent + bi=pi->getBranchNum(i-1); + select (bi); + return; + } + bi=pi; + while (bi->branchCount() >0) + bi=bi->getLastBranch(); + select (bi); + + // Try to select last branch in parent pi2 previous to own parent pi + /* + TreeItem *pi2=pi->parent(); + if (pi2) + { + int j=pi->num(); + if (pi2->) + } + */ + } + } +} + +void VymModel::selectAboveBranchInt() +{ + BranchItem *bi=getSelectedBranchItem(); + if (bi) + { + BranchItem *newbi=NULL; + BranchItem *pi=(BranchItem*)bi->parent(); + int i=bi->num(); + if (i>0) + { + // goto previous branch with same parent + newbi=pi->getBranchNum(i-1); + while (newbi->branchCount() >0 ) + newbi=newbi->getLastBranch(); + } + else + newbi=pi; + if (newbi==rootItem) + // already at top branch (resp. mapcenter) + return; + select (newbi); + } +} + +void VymModel::selectBelowBranchInt() +{ + BranchItem *bi=getSelectedBranchItem(); + if (bi) + { + BranchItem *newbi=NULL; + + if (bi->branchCount() >0) + newbi=bi->getFirstBranch(); + else + { + BranchItem *pi; + int i; + while (!newbi) + { + pi=(BranchItem*)bi->parent(); + i=bi->num(); + if (pi->branchCount()-1 > i) + { + newbi=(BranchItem*)pi->getBranchNum(i+1); + //done... + break; + } + else + // look for siblings of myself + // or parent, or parent of parent... + bi=pi; + if (bi==rootItem) + // already at end + return; + } + } + select (newbi); + } +} + +void VymModel::selectUpperBranch() +{ + if (selection.isBlocked() ) return; + + BranchItem *bi=getSelectedBranchItem(); + if (bi && bi->isBranchLikeType()) + selectAboveBranchInt(); +} + void VymModel::selectLowerBranch() { if (selection.isBlocked() ) return; BranchItem *bi=getSelectedBranchItem(); - if (bi && bi->getType()==TreeItem::Branch) - { - if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO - selectNextBranchInt(); - else - if (bi->depth()==1) - selectPrevBranchInt(); - else - selectNextBranchInt(); - } + if (bi && bi->isBranchLikeType()) + selectBelowBranchInt(); }