diff -r 920e6ed5889b -r e90f5bef70c8 branchobj.cpp --- a/branchobj.cpp Sun Jan 30 12:59:10 2005 +0000 +++ b/branchobj.cpp Sun Jan 30 23:25:47 2005 +0000 @@ -27,6 +27,7 @@ BranchObj::BranchObj (QCanvas* c):OrnamentedObj (c) { // cout << "Const BranchObj (c) called from MapCenterObj (c)\n"; + parObj=NULL; canvas=c; } @@ -47,16 +48,18 @@ BranchObj::~BranchObj () { - //cout << "Destr BranchObj\n"; +// cout << "Destr BranchObj of "<getLastBranch(); + bo=((BranchObj*)(parObj))->getLastBranch(); if (!bo) po->unScroll(); } + clear(); } bool BranchObj::operator< ( const BranchObj & other ) @@ -82,17 +85,19 @@ void BranchObj::init () { - branch.setAutoDelete (true); + branch.setAutoDelete (false); floatimage.setAutoDelete (true); + link.setAutoDelete (false); - absPos=getRandPos(); - absPos+=parObj->getChildPos(); + if (parObj) + { + absPos=getRandPos(); + absPos+=parObj->getChildPos(); + } // TODO This should be done in TextObj later QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0"); -// font.setPointSize(12); - heading->setFont(font ); -// heading->setText(QObject::tr("new branch")); + heading->setFont(font ); lastSelectedBranch=-1; @@ -135,8 +140,17 @@ void BranchObj::clear() { - branch.clear(); floatimage.clear(); + while (!link.isEmpty()) + deleteLink (link.first() ); + + BranchObj *bo; + while (!branch.isEmpty()) + { + bo=branch.first(); + branch.removeFirst(); + delete (bo); + } } int BranchObj::getNum() @@ -541,7 +555,7 @@ for (b=branch.first(); b;b=branch.next() ) b->moveBy (x,y); } - + void BranchObj::moveBy (QPoint p) { moveBy (p.x(), p.y()); @@ -550,6 +564,14 @@ void BranchObj::positionBBox() { + // FIXME testing + /* + QString h=getHeading(); + if (!h.isEmpty()) + cout << "BO::positionBBox("<positionBBox(); systemFlags->positionBBox(); @@ -561,12 +583,16 @@ bbox.setY (absPos.y() ); bbox.setWidth(w_old); bbox.setHeight(h_old); - - + setSelBox(); // set the frame frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) ); + + // Update links to other branches + LinkObj *l; + for (l=link.first(); l; l=link.next() ) + l->updateLink(); } void BranchObj::calcBBoxSize() @@ -759,6 +785,28 @@ return s; } +void BranchObj::addLink (LinkObj *lo) +{ + link.append (lo); + +} + +void BranchObj::removeLink (LinkObj *lo) +{ + link.remove (lo); +} + +void BranchObj::deleteLink(LinkObj *lo) +{ + lo->deactivate(); + if (!lo->isUsed()) delete (lo); +} + +int BranchObj::countLink() +{ + return link.count(); +} + LinkableMapObj* BranchObj::addFloatImage () { FloatImageObj *newfi=new FloatImageObj (canvas,this); @@ -850,6 +898,17 @@ return newbo; } +BranchObj* BranchObj::addBranchPtr(BranchObj* bo) +{ + branch.append (bo); + bo->setParObj (this); + bo->depth=depth+1; + bo->setLinkStyle (bo->getDefLinkStyle() ); + if (scrolled) tmpUnscroll(); + setLastSelectedBranch (bo); + return bo; +} + BranchObj* BranchObj::insertBranch(int pos) { savePosInAngle(); @@ -870,11 +929,36 @@ return newbo; } +BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos) +{ + savePosInAngle(); + // Add new bo and resort branches + bo->angle=pos-0.5; + branch.append (bo); + bo->setParObj (this); + bo->depth=depth+1; + bo->setLinkStyle (bo->getDefLinkStyle() ); + if (scrolled) tmpUnscroll(); + setLastSelectedBranch (bo); + branch.sort(); + return bo; +} + void BranchObj::removeBranch(BranchObj* bo) { // if bo is not in branch remove returns false, we // don't care... - branch.remove (bo); + + if (branch.remove (bo)) + delete (bo); + else + qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n"); + requestReposition(); +} + +void BranchObj::removeBranchPtr(BranchObj* bo) +{ + branch.remove (bo); requestReposition(); } @@ -939,6 +1023,32 @@ return branch.at(i); } +BranchObj* BranchObj::moveBranchTo (BranchObj* dst, int pos) +{ + // Find current parent and + // remove pointer to myself there + BranchObj *par=(BranchObj*)(parObj); + if (par) + par->removeBranchPtr (this); + else + return NULL; + + if (pos<0) + { + // links adds myself as last branch at dst + dst->addBranchPtr (this); + return this; + } else + { + // inserts me at pos in parent of dst + par=(BranchObj*)(dst->getParObj()); + if (par) + return par->insertBranchPtr (this,pos); + else + return NULL; + } +} + void BranchObj::alignRelativeTo (QPoint ref) { /* FIXME testing