1.1 --- a/branchobj.cpp Mon Nov 20 12:12:05 2006 +0000
1.2 +++ b/branchobj.cpp Thu Nov 23 13:53:08 2006 +0000
1.3 @@ -8,6 +8,19 @@
1.4 extern FlagRowObj *standardFlagsDefault;
1.5
1.6
1.7 +/* FIXME not needed any longer in QT4
1.8 +int BranchObjPointrList::compareItems ( Q3PtrCollection::Item i, Q3PtrCollection::Item j)
1.9 +{
1.10 + // Make sure PtrList::find works
1.11 + if (i==j) return 0;
1.12 +
1.13 + if ( ((BranchObj*)(i))->angle > ((BranchObj*)(j))->angle )
1.14 + return 1;
1.15 + else
1.16 + return -1;
1.17 +}
1.18 +*/
1.19 +
1.20 /////////////////////////////////////////////////////////////////
1.21 // BranchObj
1.22 /////////////////////////////////////////////////////////////////
1.23 @@ -72,22 +85,8 @@
1.24 return angle == other.angle;
1.25 }
1.26
1.27 -int BranchObjPtrList::compareItems ( Q3PtrCollection::Item i, Q3PtrCollection::Item j)
1.28 -{
1.29 - // Make sure PtrList::find works
1.30 - if (i==j) return 0;
1.31 -
1.32 - if ( ((BranchObj*)(i))->angle > ((BranchObj*)(j))->angle )
1.33 - return 1;
1.34 - else
1.35 - return -1;
1.36 -}
1.37 -
1.38 void BranchObj::init ()
1.39 {
1.40 - branch.setAutoDelete (false);
1.41 - xlink.setAutoDelete (false);
1.42 -
1.43 if (parObj)
1.44 {
1.45 absPos=getRandPos();
1.46 @@ -110,12 +109,11 @@
1.47 OrnamentedObj::copy(other);
1.48
1.49 branch.clear();
1.50 - BranchObj* b;
1.51 - for (b=other->branch.first(); b;b=other->branch.next() )
1.52 + for (int i=0; i<other->branch.size(); ++i)
1.53 // Make deep copy of b
1.54 // Because addBranch again calls copy for the childs,
1.55 // Those will get a deep copy, too
1.56 - addBranch(b);
1.57 + addBranch(other->branch.at(i) );
1.58
1.59 for (int i=0; i<other->floatimage.size(); ++i)
1.60 addFloatImage (other->floatimage.at(i));
1.61 @@ -134,15 +132,10 @@
1.62 delete floatimage.takeFirst();
1.63
1.64 while (!xlink.isEmpty())
1.65 - deleteXLink (xlink.first() );
1.66 + delete xlink.takeFirst();
1.67
1.68 - BranchObj *bo;
1.69 while (!branch.isEmpty())
1.70 - {
1.71 - bo=branch.first();
1.72 - branch.removeFirst();
1.73 - delete (bo);
1.74 - }
1.75 + delete branch.takeFirst();
1.76 }
1.77
1.78 int BranchObj::getNum()
1.79 @@ -155,12 +148,7 @@
1.80
1.81 int BranchObj::getNum(BranchObj *bo)
1.82 {
1.83 - // keep current pointer in branch,
1.84 - // otherwise saveToDir will fail
1.85 - int cur=branch.at();
1.86 - int ind=branch.findRef (bo);
1.87 - branch.at(cur);
1.88 - return ind;
1.89 + return branch.indexOf (bo);
1.90 }
1.91
1.92 int BranchObj::getFloatImageNum(FloatImageObj *fio)
1.93 @@ -273,23 +261,18 @@
1.94
1.95 void BranchObj::toggleScroll()
1.96 {
1.97 - BranchObj *bo;
1.98 if (scrolled)
1.99 {
1.100 scrolled=false;
1.101 systemFlags->deactivate("scrolledright");
1.102 - for (bo=branch.first(); bo; bo=branch.next() )
1.103 - {
1.104 - bo->setVisibility(true);
1.105 - }
1.106 + for (int i=0; i<branch.size(); ++i)
1.107 + branch.at(i)->setVisibility(true);
1.108 } else
1.109 {
1.110 scrolled=true;
1.111 systemFlags->activate("scrolledright");
1.112 - for (bo=branch.first(); bo; bo=branch.next() )
1.113 - {
1.114 - bo->setVisibility(false);
1.115 - }
1.116 + for (int i=0; i<branch.size(); ++i)
1.117 + branch.at(i)->setVisibility(false);
1.118 }
1.119 calcBBoxSize();
1.120 positionBBox();
1.121 @@ -362,14 +345,13 @@
1.122 if (!scrolled && (depth < toDepth))
1.123 {
1.124 // Now go recursivly through all childs
1.125 - BranchObj* b;
1.126 - for (b=branch.first(); b;b=branch.next() )
1.127 - b->setVisibility (v,toDepth);
1.128 - for (int i=0; i<floatimage.size(); ++i)
1.129 + int i;
1.130 + for (i=0; i<branch.size(); ++i)
1.131 + branch.at(i)->setVisibility (v,toDepth);
1.132 + for (i=0; i<floatimage.size(); ++i)
1.133 floatimage.at(i)->setVisibility (v);
1.134 - XLinkObj* xlo;
1.135 - for (xlo=xlink.first(); xlo;xlo=xlink.next() )
1.136 - xlo->setVisibility ();
1.137 + for (i=0; i<xlink.size(); ++i)
1.138 + xlink.at(i)->setVisibility ();
1.139 }
1.140 } // depth <= toDepth
1.141 requestReposition();
1.142 @@ -396,9 +378,8 @@
1.143 void BranchObj::setColorChilds (QColor col)
1.144 {
1.145 OrnamentedObj::setColor (col);
1.146 - BranchObj *bo;
1.147 - for (bo=branch.first(); bo; bo=branch.next() )
1.148 - bo->setColorChilds(col);
1.149 + for (int i=0; i<branch.size(); ++i)
1.150 + branch.at(i)->setColorChilds(col);
1.151 }
1.152
1.153 BranchObj* BranchObj::first()
1.154 @@ -410,28 +391,35 @@
1.155
1.156 BranchObj* BranchObj::next()
1.157 {
1.158 + BranchObj *bo;
1.159 BranchObj *lmo;
1.160 - BranchObj *bo=branch.first();
1.161 - BranchObj *po=(BranchObj*)(parObj);
1.162 + BranchObj *po=(BranchObj*)parObj;
1.163 +
1.164 + if (branch.isEmpty())
1.165 + bo=NULL;
1.166 + else
1.167 + bo=branch.first();
1.168
1.169 if (!itLast)
1.170 {
1.171 + // no itLast, we are just beginning
1.172 if (bo)
1.173 - { // We are just beginning,
1.174 - // return first child
1.175 + {
1.176 + // we have childs, return first one
1.177 itLast=this;
1.178 return bo;
1.179 }
1.180 else
1.181 {
1.182 - // No childs
1.183 + // No childs, so there is no next
1.184 itLast=this;
1.185 return NULL;
1.186 }
1.187 }
1.188
1.189 - if (itLast==parObj)
1.190 - { // We come from above
1.191 + // We have an itLast
1.192 + if (itLast==po)
1.193 + { // We come from parent
1.194 if (bo)
1.195 {
1.196 // there are childs, go there
1.197 @@ -442,7 +430,7 @@
1.198 { // no childs, try to go up again
1.199 if (po)
1.200 {
1.201 - // go up
1.202 + // go back to parent and try to find next there
1.203 itLast=this;
1.204 lmo=po->next();
1.205 itLast=this;
1.206 @@ -451,22 +439,36 @@
1.207 }
1.208 else
1.209 {
1.210 - // can't go up, I am mapCenter
1.211 + // can't go up, I am mapCenter, no next
1.212 itLast=NULL;
1.213 return NULL;
1.214 }
1.215 }
1.216 }
1.217
1.218 + // We don't come from parent, but from brother or childs
1.219 +
1.220 // Try to find last child, where we came from, in my own childs
1.221 bool searching=true;
1.222 - while (bo && searching)
1.223 + int i=0;
1.224 + while (i<branch.size())
1.225 {
1.226 - if (itLast==bo) searching=false;
1.227 - bo=branch.next();
1.228 + // Try to find itLast in my own childs
1.229 + if (itLast==branch.at(i))
1.230 + {
1.231 + // ok, we come from my own childs
1.232 + //xyz //FIXME need to proceed to NEXT child or up again
1.233 + if (i<branch.size()-1)
1.234 + bo=branch.at(i+1);
1.235 + else
1.236 + bo=NULL;
1.237 + searching=false;
1.238 + i=branch.size();
1.239 + }
1.240 + ++i;
1.241 }
1.242 if (!searching)
1.243 - { // found lastLMO in my childs
1.244 + { // found itLast in my childs
1.245 if (bo)
1.246 {
1.247 // found a brother of lastLMO
1.248 @@ -494,12 +496,11 @@
1.249 }
1.250
1.251 // couldn't find last child, it must be a nephew of mine
1.252 - bo=branch.first();
1.253 - if (bo)
1.254 + if (branch.size()>0)
1.255 {
1.256 // proceed with my first child
1.257 itLast=this;
1.258 - return bo;
1.259 + return branch.first();
1.260 }
1.261 else
1.262 {
1.263 @@ -554,9 +555,8 @@
1.264 void BranchObj::moveBy (double x, double y)
1.265 {
1.266 OrnamentedObj::moveBy (x,y);
1.267 - BranchObj* b;
1.268 - for (b=branch.first(); b;b=branch.next() )
1.269 - b->moveBy (x,y);
1.270 + for (int i=0; i<branch.size(); ++i)
1.271 + branch.at(i)->moveBy (x,y);
1.272 positionBBox();
1.273 }
1.274
1.275 @@ -577,9 +577,8 @@
1.276 frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
1.277
1.278 // Update links to other branches
1.279 - XLinkObj *xlo;
1.280 - for (xlo=xlink.first(); xlo; xlo=xlink.next() )
1.281 - xlo->updateXLink();
1.282 + for (int i=0; i<xlink.size(); ++i)
1.283 + xlink.at(i)->updateXLink();
1.284 }
1.285
1.286 void BranchObj::calcBBoxSize()
1.287 @@ -673,11 +672,10 @@
1.288 LinkableMapObj* BranchObj::findMapObj(QPoint p, LinkableMapObj* excludeLMO)
1.289 {
1.290 // Search branches
1.291 - BranchObj *b;
1.292 LinkableMapObj *lmo;
1.293 - for (b=branch.first(); b; b=branch.next() )
1.294 + for (int i=0; i<branch.size(); ++i)
1.295 {
1.296 - lmo=b->findMapObj(p, excludeLMO);
1.297 + lmo=branch.at(i)->findMapObj(p, excludeLMO);
1.298 if (lmo != NULL) return lmo;
1.299 }
1.300
1.301 @@ -719,9 +717,8 @@
1.302 hidden=false;
1.303 }
1.304
1.305 - BranchObj *bo;
1.306 - for (bo=branch.first(); bo; bo=branch.next() )
1.307 - bo->setHideTmp (mode);
1.308 + for (int i=0; i<branch.size(); ++i)
1.309 + branch.at(i)->setHideTmp (mode);
1.310 }
1.311
1.312 bool BranchObj::hasHiddenExportParent(BranchObj *start)
1.313 @@ -805,17 +802,15 @@
1.314 s+=note.saveToDir();
1.315
1.316 // Save branches
1.317 - BranchObj *bo;
1.318 - for (bo=branch.first(); bo; bo=branch.next() )
1.319 - s+=bo->saveToDir(tmpdir,prefix,offset);
1.320 + for (int i=0; i<branch.size(); ++i)
1.321 + s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
1.322
1.323 // Save XLinks
1.324 - XLinkObj *xlo;
1.325 QString ol; // old link
1.326 QString cl; // current link
1.327 - for (xlo=xlink.first(); xlo; xlo=xlink.next() )
1.328 + for (int i=0; i<xlink.size(); ++i)
1.329 {
1.330 - cl=xlo->saveToDir();
1.331 + cl=xlink.at(i)->saveToDir();
1.332 if (cl!=ol)
1.333 {
1.334 s+=cl;
1.335 @@ -839,7 +834,7 @@
1.336
1.337 void BranchObj::removeXLinkRef (XLinkObj *xlo)
1.338 {
1.339 - xlink.remove (xlo);
1.340 + xlink.removeAt (xlink.indexOf(xlo));
1.341 }
1.342
1.343 void BranchObj::deleteXLink(XLinkObj *xlo)
1.344 @@ -868,10 +863,12 @@
1.345
1.346 BranchObj* BranchObj::XLinkTargetAt (int i)
1.347 {
1.348 - if (xlink.at(i))
1.349 - return xlink.at(i)->otherBranch (this);
1.350 - else
1.351 - return NULL;
1.352 + if (i>=0 && i<xlink.size())
1.353 + {
1.354 + if (xlink.at(i))
1.355 + return xlink.at(i)->otherBranch (this);
1.356 + }
1.357 + return NULL;
1.358 }
1.359
1.360 void BranchObj::setIncludeImagesVer(bool b)
1.361 @@ -975,13 +972,8 @@
1.362 void BranchObj::savePosInAngle ()
1.363 {
1.364 // Save position in angle
1.365 - BranchObj *b;
1.366 - int i=0;
1.367 - for (b=branch.first(); b; b=branch.next() )
1.368 - {
1.369 - b->angle=i;
1.370 - i++;
1.371 - }
1.372 + for (int i=0; i<branch.size(); ++i)
1.373 + branch.at(i)->angle=i;
1.374 }
1.375
1.376 void BranchObj::setDefAttr (BranchModification mod)
1.377 @@ -1055,7 +1047,7 @@
1.378 // Add new bo and resort branches
1.379 BranchObj *newbo=addBranch ();
1.380 newbo->angle=pos-0.5;
1.381 - branch.sort();
1.382 + //FIXME branch.sort();
1.383 return newbo;
1.384 }
1.385
1.386 @@ -1065,7 +1057,7 @@
1.387 // Add new bo and resort branches
1.388 bo->angle=pos-0.5;
1.389 BranchObj *newbo=addBranch (bo);
1.390 - branch.sort();
1.391 + //FIXME branch.sort();
1.392 return newbo;
1.393 }
1.394
1.395 @@ -1080,7 +1072,7 @@
1.396 bo->setDefAttr (MovedBranch);
1.397 if (scrolled) tmpUnscroll();
1.398 setLastSelectedBranch (bo);
1.399 - branch.sort();
1.400 + //FIXME branch.sort();
1.401 return bo;
1.402 }
1.403
1.404 @@ -1109,22 +1101,30 @@
1.405 // if bo is not in branch remove returns false, we
1.406 // don't care...
1.407
1.408 - if (branch.remove (bo))
1.409 + int i=branch.indexOf(bo);
1.410 + if (i>=0)
1.411 + {
1.412 delete (bo);
1.413 - else
1.414 + branch.removeAt (i);
1.415 + } else
1.416 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1.417 requestReposition();
1.418 }
1.419
1.420 void BranchObj::removeBranchPtr(BranchObj* bo)
1.421 {
1.422 - branch.remove (bo);
1.423 + int i=branch.indexOf(bo);
1.424 +
1.425 + if (i>=0)
1.426 + branch.removeAt (i);
1.427 + else
1.428 + qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1.429 requestReposition();
1.430 }
1.431
1.432 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1.433 {
1.434 - lastSelectedBranch=branch.find(bo);
1.435 + lastSelectedBranch=branch.indexOf(bo);
1.436 }
1.437
1.438 BranchObj* BranchObj::getLastSelectedBranch ()
1.439 @@ -1147,9 +1147,12 @@
1.440 return branch.last();
1.441 }
1.442
1.443 -BranchObj* BranchObj::getBranchNum (const uint &i)
1.444 +BranchObj* BranchObj::getBranchNum (int i)
1.445 {
1.446 - return branch.at(i);
1.447 + if (i>=0 && i<branch.size())
1.448 + return branch.at(i);
1.449 + else
1.450 + return NULL;
1.451 }
1.452
1.453 bool BranchObj::canMoveBranchUp()
1.454 @@ -1165,12 +1168,12 @@
1.455 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1.456 {
1.457 savePosInAngle();
1.458 - int i=branch.find(bo1);
1.459 + int i=branch.indexOf(bo1);
1.460 if (i>0)
1.461 { // -1 if bo1 not found
1.462 branch.at(i)->angle--;
1.463 branch.at(i-1)->angle++;
1.464 - branch.sort();
1.465 + //FIXME branch.sort();
1.466 return branch.at(i);
1.467 } else
1.468 return NULL;
1.469 @@ -1189,14 +1192,14 @@
1.470 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1.471 {
1.472 savePosInAngle();
1.473 - int i=branch.find(bo1);
1.474 + int i=branch.indexOf(bo1);
1.475 int j;
1.476 - if (branch.next())
1.477 + if (i <branch.size())
1.478 {
1.479 - j = branch.at();
1.480 + j = i+1;
1.481 branch.at(i)->angle++;
1.482 branch.at(j)->angle--;
1.483 - branch.sort();
1.484 + //FIXME branch.sort();
1.485 return branch.at(i);
1.486 } else
1.487 return NULL;
1.488 @@ -1305,13 +1308,12 @@
1.489 ref2.setY(ref.y() );
1.490
1.491 // Align the childs depending on reference point
1.492 - BranchObj *b;
1.493 - for (b=branch.first(); b; b=branch.next() )
1.494 + for (int i=0; i<branch.size(); ++i)
1.495 {
1.496 - if (!b->isHidden())
1.497 + if (!branch.at(i)->isHidden())
1.498 {
1.499 - b->alignRelativeTo (ref2);
1.500 - ref2.setY(ref2.y() + b->getBBoxSizeWithChilds().height() );
1.501 + branch.at(i)->alignRelativeTo (ref2);
1.502 + ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1.503 }
1.504 }
1.505 }
1.506 @@ -1340,7 +1342,7 @@
1.507
1.508 alignRelativeTo ( QPoint (absPos.x(),
1.509 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1.510 - branch.sort();
1.511 + //FIXME branch.sort();
1.512 positionBBox(); // Reposition bbox and contents
1.513 } else
1.514 {
1.515 @@ -1354,11 +1356,8 @@
1.516 void BranchObj::unsetAllRepositionRequests()
1.517 {
1.518 repositionRequest=false;
1.519 - BranchObj *b;
1.520 - for (b=branch.first(); b; b=branch.next() )
1.521 - {
1.522 - b->unsetAllRepositionRequests();
1.523 - }
1.524 + for (int i=0; i<branch.size(); ++i)
1.525 + branch.at(i)->unsetAllRepositionRequests();
1.526 }
1.527
1.528
1.529 @@ -1368,10 +1367,9 @@
1.530
1.531 if (scrolled) return r;
1.532
1.533 - BranchObj* b;
1.534 - for (b=branch.first();b ;b=branch.next() )
1.535 - if (!b->isHidden())
1.536 - r=addBBox(b->getTotalBBox(),r);
1.537 + for (int i=0; i<branch.size(); ++i)
1.538 + if (!branch.at(i)->isHidden())
1.539 + r=addBBox(branch.at(i)->getTotalBBox(),r);
1.540
1.541 for (int i=0; i<floatimage.size(); ++i)
1.542 if (!floatimage.at(i)->isHidden())
1.543 @@ -1427,13 +1425,12 @@
1.544 // sum of heights
1.545 // maximum of widths
1.546 // minimum of y
1.547 - BranchObj* b;
1.548 - for (b=branch.first();b ;b=branch.next() )
1.549 + for (int i=0; i<branch.size(); ++i)
1.550 {
1.551 - if (!b->isHidden())
1.552 + if (!branch.at(i)->isHidden())
1.553 {
1.554 - b->calcBBoxSizeWithChilds();
1.555 - br=b->getBBoxSizeWithChilds();
1.556 + branch.at(i)->calcBBoxSizeWithChilds();
1.557 + br=branch.at(i)->getBBoxSizeWithChilds();
1.558 r.setWidth( max (br.width(), r.width() ));
1.559 r.setHeight(br.height() + r.height() );
1.560 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1.561 @@ -1478,7 +1475,7 @@
1.562 // Update Toolbar
1.563 updateFlagsToolbar();
1.564
1.565 - // Update actions in mapeditor
1.566 + // Update actions
1.567 mapEditor->updateActions();
1.568 }
1.569