1.1 --- a/branchobj.cpp Sun Jan 30 12:59:10 2005 +0000
1.2 +++ b/branchobj.cpp Sun Jan 30 23:25:47 2005 +0000
1.3 @@ -27,6 +27,7 @@
1.4 BranchObj::BranchObj (QCanvas* c):OrnamentedObj (c)
1.5 {
1.6 // cout << "Const BranchObj (c) called from MapCenterObj (c)\n";
1.7 + parObj=NULL;
1.8 canvas=c;
1.9 }
1.10
1.11 @@ -47,16 +48,18 @@
1.12
1.13 BranchObj::~BranchObj ()
1.14 {
1.15 - //cout << "Destr BranchObj\n";
1.16 +// cout << "Destr BranchObj of "<<this<<endl;
1.17 // Check, if this branch was the last child to be deleted
1.18 // If so, unset the scrolled flags
1.19
1.20 BranchObj *po=(BranchObj*)(parObj);
1.21 + BranchObj *bo;
1.22 if (po)
1.23 {
1.24 - BranchObj *bo=((BranchObj*)(parObj))->getLastBranch();
1.25 + bo=((BranchObj*)(parObj))->getLastBranch();
1.26 if (!bo) po->unScroll();
1.27 }
1.28 + clear();
1.29 }
1.30
1.31 bool BranchObj::operator< ( const BranchObj & other )
1.32 @@ -82,17 +85,19 @@
1.33
1.34 void BranchObj::init ()
1.35 {
1.36 - branch.setAutoDelete (true);
1.37 + branch.setAutoDelete (false);
1.38 floatimage.setAutoDelete (true);
1.39 + link.setAutoDelete (false);
1.40
1.41 - absPos=getRandPos();
1.42 - absPos+=parObj->getChildPos();
1.43 + if (parObj)
1.44 + {
1.45 + absPos=getRandPos();
1.46 + absPos+=parObj->getChildPos();
1.47 + }
1.48
1.49 // TODO This should be done in TextObj later
1.50 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1.51 -// font.setPointSize(12);
1.52 - heading->setFont(font );
1.53 -// heading->setText(QObject::tr("new branch"));
1.54 + heading->setFont(font );
1.55
1.56 lastSelectedBranch=-1;
1.57
1.58 @@ -135,8 +140,17 @@
1.59
1.60 void BranchObj::clear()
1.61 {
1.62 - branch.clear();
1.63 floatimage.clear();
1.64 + while (!link.isEmpty())
1.65 + deleteLink (link.first() );
1.66 +
1.67 + BranchObj *bo;
1.68 + while (!branch.isEmpty())
1.69 + {
1.70 + bo=branch.first();
1.71 + branch.removeFirst();
1.72 + delete (bo);
1.73 + }
1.74 }
1.75
1.76 int BranchObj::getNum()
1.77 @@ -541,7 +555,7 @@
1.78 for (b=branch.first(); b;b=branch.next() )
1.79 b->moveBy (x,y);
1.80 }
1.81 -
1.82 +
1.83 void BranchObj::moveBy (QPoint p)
1.84 {
1.85 moveBy (p.x(), p.y());
1.86 @@ -550,6 +564,14 @@
1.87
1.88 void BranchObj::positionBBox()
1.89 {
1.90 + // FIXME testing
1.91 + /*
1.92 + QString h=getHeading();
1.93 + if (!h.isEmpty())
1.94 + cout << "BO::positionBBox("<<h<<")\n";
1.95 + else
1.96 + cout << "BO::positionBBox (noHeading)\n";
1.97 + */
1.98
1.99 heading->positionBBox();
1.100 systemFlags->positionBBox();
1.101 @@ -561,12 +583,16 @@
1.102 bbox.setY (absPos.y() );
1.103 bbox.setWidth(w_old);
1.104 bbox.setHeight(h_old);
1.105 -
1.106 -
1.107 +
1.108 setSelBox();
1.109
1.110 // set the frame
1.111 frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
1.112 +
1.113 + // Update links to other branches
1.114 + LinkObj *l;
1.115 + for (l=link.first(); l; l=link.next() )
1.116 + l->updateLink();
1.117 }
1.118
1.119 void BranchObj::calcBBoxSize()
1.120 @@ -759,6 +785,28 @@
1.121 return s;
1.122 }
1.123
1.124 +void BranchObj::addLink (LinkObj *lo)
1.125 +{
1.126 + link.append (lo);
1.127 +
1.128 +}
1.129 +
1.130 +void BranchObj::removeLink (LinkObj *lo)
1.131 +{
1.132 + link.remove (lo);
1.133 +}
1.134 +
1.135 +void BranchObj::deleteLink(LinkObj *lo)
1.136 +{
1.137 + lo->deactivate();
1.138 + if (!lo->isUsed()) delete (lo);
1.139 +}
1.140 +
1.141 +int BranchObj::countLink()
1.142 +{
1.143 + return link.count();
1.144 +}
1.145 +
1.146 LinkableMapObj* BranchObj::addFloatImage ()
1.147 {
1.148 FloatImageObj *newfi=new FloatImageObj (canvas,this);
1.149 @@ -850,6 +898,17 @@
1.150 return newbo;
1.151 }
1.152
1.153 +BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1.154 +{
1.155 + branch.append (bo);
1.156 + bo->setParObj (this);
1.157 + bo->depth=depth+1;
1.158 + bo->setLinkStyle (bo->getDefLinkStyle() );
1.159 + if (scrolled) tmpUnscroll();
1.160 + setLastSelectedBranch (bo);
1.161 + return bo;
1.162 +}
1.163 +
1.164 BranchObj* BranchObj::insertBranch(int pos)
1.165 {
1.166 savePosInAngle();
1.167 @@ -870,11 +929,36 @@
1.168 return newbo;
1.169 }
1.170
1.171 +BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1.172 +{
1.173 + savePosInAngle();
1.174 + // Add new bo and resort branches
1.175 + bo->angle=pos-0.5;
1.176 + branch.append (bo);
1.177 + bo->setParObj (this);
1.178 + bo->depth=depth+1;
1.179 + bo->setLinkStyle (bo->getDefLinkStyle() );
1.180 + if (scrolled) tmpUnscroll();
1.181 + setLastSelectedBranch (bo);
1.182 + branch.sort();
1.183 + return bo;
1.184 +}
1.185 +
1.186 void BranchObj::removeBranch(BranchObj* bo)
1.187 {
1.188 // if bo is not in branch remove returns false, we
1.189 // don't care...
1.190 - branch.remove (bo);
1.191 +
1.192 + if (branch.remove (bo))
1.193 + delete (bo);
1.194 + else
1.195 + qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1.196 + requestReposition();
1.197 +}
1.198 +
1.199 +void BranchObj::removeBranchPtr(BranchObj* bo)
1.200 +{
1.201 + branch.remove (bo);
1.202 requestReposition();
1.203 }
1.204
1.205 @@ -939,6 +1023,32 @@
1.206 return branch.at(i);
1.207 }
1.208
1.209 +BranchObj* BranchObj::moveBranchTo (BranchObj* dst, int pos)
1.210 +{
1.211 + // Find current parent and
1.212 + // remove pointer to myself there
1.213 + BranchObj *par=(BranchObj*)(parObj);
1.214 + if (par)
1.215 + par->removeBranchPtr (this);
1.216 + else
1.217 + return NULL;
1.218 +
1.219 + if (pos<0)
1.220 + {
1.221 + // links adds myself as last branch at dst
1.222 + dst->addBranchPtr (this);
1.223 + return this;
1.224 + } else
1.225 + {
1.226 + // inserts me at pos in parent of dst
1.227 + par=(BranchObj*)(dst->getParObj());
1.228 + if (par)
1.229 + return par->insertBranchPtr (this,pos);
1.230 + else
1.231 + return NULL;
1.232 + }
1.233 +}
1.234 +
1.235 void BranchObj::alignRelativeTo (QPoint ref)
1.236 {
1.237 /* FIXME testing