diff -r d85834ad8c54 -r 133e2ed6b9c5 xlinkobj.cpp --- a/xlinkobj.cpp Mon Aug 24 14:39:07 2009 +0000 +++ b/xlinkobj.cpp Thu Sep 03 08:52:00 2009 +0000 @@ -1,31 +1,28 @@ #include "xlinkobj.h" + #include "branchobj.h" +#include "branchitem.h" +#include "xlinkitem.h" +#include +using namespace std; ///////////////////////////////////////////////////////////////// // XLinkObj ///////////////////////////////////////////////////////////////// -int XLinkObj::arrowSize=10; // make instances +int XLinkObj::arrowSize=10; // make instances -XLinkObj::XLinkObj ():MapObj() +XLinkObj::XLinkObj (QGraphicsScene* scene, TreeItem* ti):MapObj(scene,ti) { - // cout << "Const XLinkObj ()\n"; + //cout << "Const XLinkObj (s)\n"; init(); } -XLinkObj::XLinkObj (QGraphicsScene* s):MapObj(s) -{ - // cout << "Const XLinkObj (s) called from MapCenterObj (s)\n"; - init(); -} - XLinkObj::~XLinkObj () { -// cout << "Destr XLinkObj\n"; - if (xLinkState!=undefinedXLink) - deactivate(); + //cout << "Destr XLinkObj\n"; delete (line); delete (poly); } @@ -33,87 +30,17 @@ void XLinkObj::init () { - beginBranch=NULL; - endBranch=NULL; + XLinkItem *xli=(XLinkItem*)treeItem; visBranch=NULL; - xLinkState=undefinedXLink; - color=QColor (180,180,180); - width=1; - pen.setColor (color); - pen.setWidth (width); + pen.setColor ( xli->getColor() ); + pen.setWidth ( xli->getWidth() ); pen.setCapStyle ( Qt::RoundCap ); line=scene->addLine(QLineF(1,1,1,1),pen); line->setZValue (Z_XLINK); - poly=scene->addPolygon(QPolygonF(),pen,color); + poly=scene->addPolygon(QPolygonF(),pen, xli->getColor()); poly->setZValue (Z_XLINK); - setVisibility (false); -} - -void XLinkObj::copy (XLinkObj* other) -{ - // TODO copy not used yet - MapObj::copy (other); - setVisibility (other->visible); - beginBranch=other->beginBranch; - endBranch=other->endBranch; - width=other->width; - -} - -void XLinkObj::setBegin (BranchObj *bo) -{ - if (bo) - { - xLinkState=initXLink; - beginBranch=bo; - beginPos=beginBranch->getChildPos(); - } -} - -BranchObj* XLinkObj::getBegin () -{ - return beginBranch; -} - -void XLinkObj::setEnd (BranchObj *bo) -{ - if (bo) - { - xLinkState=initXLink; - endBranch=bo; - endPos=endBranch->getChildPos(); - } -} - -BranchObj* XLinkObj::getEnd() -{ - return endBranch; -} - -void XLinkObj::setWidth (int w) -{ - width=w; - pen.setWidth (w); - setColor (color); -} - -int XLinkObj::getWidth() -{ - return pen.width(); -} - -void XLinkObj::setColor(QColor c) -{ - color=c; - pen.setColor (c); - line->setPen (pen); - poly->setBrush( color ); -} - -QColor XLinkObj::getColor() -{ - return pen.color(); + setVisibility (true); } void XLinkObj::setEnd (QPointF p) @@ -121,41 +48,6 @@ endPos=p; } -bool XLinkObj::activate () -{ - if (beginBranch && endBranch) - { - if (beginBranch==endBranch) return false; - xLinkState=activeXLink; - beginBranch->addXLink (this); - endBranch->addXLink (this); - setVisibility (); - return true; - } else - return false; -} - -void XLinkObj::deactivate () -{ - if (beginBranch) - beginBranch->removeXLinkRef (this); - beginBranch=NULL; - if (endBranch) - endBranch->removeXLinkRef (this); - endBranch=NULL; - visBranch=NULL; - xLinkState=undefinedXLink; - - line->hide(); -} - -bool XLinkObj::isUsed() -{ - if (beginBranch || endBranch || xLinkState!=undefinedXLink) - return true; - else - return false; -} void XLinkObj::updateXLink() { @@ -164,8 +56,11 @@ if (visBranch) { // Only one of the linked branches is visible - a=b=visBranch->getChildPos(); - if (visBranch->getOrientation()==LinkableMapObj::RightOfCenter) + BranchObj *bo=(BranchObj*)(visBranch->getLMO()); + if (!bo) return; + + a=b=bo->getChildPos(); + if (bo->getOrientation()==LinkableMapObj::RightOfCenter) { b.setX (b.x()+25); @@ -186,43 +81,43 @@ } else { // Both linked branches are visible - if (beginBranch) + BranchItem *bi=((XLinkItem*)treeItem)->getBegin(); + if ( bi) + { // If a link is just drawn in the editor, // we have already a beginBranch - a=beginBranch->getChildPos(); + BranchObj *bo=(BranchObj*)(bi->getLMO()); + if (bo) + a=bo->getChildPos(); + else + return; + } else // This shouldn't be reached normally... a=beginPos; - if (xLinkState==activeXLink && endBranch) - b=endBranch->getChildPos(); + + // FIXME-3 try to get rid of xLinkstate if (xLinkState==activeXLink && endBranch) + bi=((XLinkItem*)treeItem)->getEnd(); + if (bi) + { + BranchObj *bo=(BranchObj*)(bi->getLMO()); + if (bo) + b=bo->getChildPos(); + else + return; + } else b=endPos; } - - if (line->line().p1()==a && line->line().p2()==b && !visBranch) - { - // update is called from both branches, so only - // update if something has changed - return; - } - else - { - beginPos=a; - endPos=b; - line->setPen (pen); - line->setLine(a.x(), a.y(), b.x(), b.y()); - } -} - -BranchObj* XLinkObj::otherBranch(BranchObj* thisBranch) -{ - if (!beginBranch && !endBranch) - return NULL; - if (thisBranch==beginBranch) - return endBranch; - else - return beginBranch; + beginPos=a; + endPos=b; + XLinkItem *xli=(XLinkItem*)treeItem; + pen.setColor ( xli->getColor() ); + pen.setWidth ( xli->getWidth() ); + poly->setBrush (xli->getColor() ); + line->setPen (pen); + line->setLine(a.x(), a.y(), b.x(), b.y()); } void XLinkObj::positionBBox() @@ -253,49 +148,36 @@ void XLinkObj::setVisibility () { - if (beginBranch && endBranch) + BranchItem* beginBI=((XLinkItem*)treeItem)->getBegin(); + BranchObj* beginBO=NULL; + if (beginBI) beginBO=(BranchObj*)(beginBI->getLMO()); + + BranchObj* endBO=NULL; + BranchItem* endBI=((XLinkItem*)treeItem)->getEnd(); + if (endBI) endBO=(BranchObj*)(endBI->getLMO()); + if (beginBO && endBO) { - if(beginBranch->isVisibleObj() && endBranch->isVisibleObj()) + if(beginBO->isVisibleObj() && endBO->isVisibleObj()) { // Both ends are visible visBranch=NULL; setVisibility (true); } else { - if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj()) + if(!beginBO->isVisibleObj() && !endBO->isVisibleObj()) { //None of the ends is visible visBranch=NULL; setVisibility (false); } else { // Just one end is visible, draw a symbol that shows // that there is a link to a scrolled branch - if (beginBranch->isVisibleObj()) - visBranch=beginBranch; + if (beginBO->isVisibleObj()) + visBranch=beginBI; else - visBranch=endBranch; + visBranch=endBI; setVisibility (true); } } } } -QString XLinkObj::saveToDir () -{ - QString s=""; - if (beginBranch && endBranch &&xLinkState==activeXLink) - { - if (beginBranch==endBranch && xLinkState) - s=""; - else - { - QString colAttr=attribut ("color",color.name()); - QString widAttr=attribut ("width",QString().setNum(width,10)); - QString begSelAttr=attribut ("beginID",beginBranch->getSelectString()); - QString endSelAttr=attribut ("endID", endBranch->getSelectString()); - s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr); - s+=endElement ("xlink"); - } - } - return s; -} -