1.1 --- a/xlinkitem.cpp Tue Apr 06 13:30:07 2010 +0000
1.2 +++ b/xlinkitem.cpp Wed Jun 09 13:14:08 2010 +0000
1.3 @@ -19,205 +19,51 @@
1.4
1.5 XLinkItem::~XLinkItem ()
1.6 {
1.7 - qDebug() << "Destr XLinkItem "<<this<<" lmo="<<lmo;
1.8 - if (lmo)
1.9 + //qDebug() << "Destr XLinkItem begin "<<this<<" pI="<<parentItem<<" link="<<link;
1.10 + if (link)
1.11 {
1.12 - qDebug() <<" calling delete (lmo)";
1.13 - delete (lmo);
1.14 - }
1.15 - if (partnerXLink)
1.16 - {
1.17 - // Also delete partner
1.18 - qDebug() << " deleting partner="<<partnerXLink;
1.19 - partnerXLink->partnerXLink=NULL; // avoid endless recusion
1.20 - model->deleteItem (partnerXLink);
1.21 - }
1.22 + // tell the model to remove the link later
1.23 + // (and then remove partner link in VymModel::cleanupLinks)
1.24 + model->deleteLink (link);
1.25 + link->removeXLinkItem (this);
1.26 + link->deactivate();
1.27 + }
1.28 + //qDebug() << "Destr XLinkItem end"<<this;
1.29 }
1.30
1.31
1.32 void XLinkItem::init ()
1.33 {
1.34 setType (XLink);
1.35 - beginBranch=NULL;
1.36 - endBranch=NULL;
1.37 - partnerXLink=NULL;
1.38 - isBeginXLink=true;
1.39 - xLinkState=XLinkItem::undefinedXLink;
1.40 -
1.41 - color=QColor (180,180,180);
1.42 - width=1;
1.43 + link=NULL;
1.44 }
1.45
1.46 -void XLinkItem::setBegin (BranchItem *bi)
1.47 +void XLinkItem::setLink (Link *l)
1.48 {
1.49 - if (bi)
1.50 - {
1.51 - xLinkState=initXLink;
1.52 - beginBranch=bi;
1.53 - }
1.54 + link=l;
1.55 }
1.56
1.57 -BranchItem* XLinkItem::getBegin ()
1.58 +Link* XLinkItem::getLink ()
1.59 {
1.60 - return beginBranch;
1.61 -}
1.62 -
1.63 -void XLinkItem::setEnd (BranchItem *bi)
1.64 -{
1.65 - if (bi)
1.66 - {
1.67 - xLinkState=initXLink;
1.68 - endBranch=bi;
1.69 - }
1.70 -}
1.71 -
1.72 -BranchItem* XLinkItem::getEnd()
1.73 -{
1.74 - return endBranch;
1.75 -}
1.76 -
1.77 -void XLinkItem::setWidth (int w)
1.78 -{
1.79 - if (isBeginXLink)
1.80 - {
1.81 - width=w;
1.82 - if (lmo) ((XLinkObj*)lmo)->updateXLink();
1.83 - return;
1.84 - }
1.85 - if (partnerXLink)
1.86 - partnerXLink->setWidth (w);
1.87 -}
1.88 -
1.89 -int XLinkItem::getWidth()
1.90 -{
1.91 - if (isBeginXLink) return width;
1.92 - if (partnerXLink)
1.93 - return partnerXLink->getWidth();
1.94 - else
1.95 - return -1;
1.96 -}
1.97 -
1.98 -void XLinkItem::setColor(QColor c)
1.99 -{
1.100 - if (isBeginXLink)
1.101 - {
1.102 - color=c;
1.103 - if (lmo) ((XLinkObj*)lmo)->updateXLink();
1.104 - return;
1.105 - }
1.106 - if (partnerXLink)
1.107 - partnerXLink->setColor (c);
1.108 -}
1.109 -
1.110 -QColor XLinkItem::getColor()
1.111 -{
1.112 - if (isBeginXLink) return color;
1.113 - if (partnerXLink)
1.114 - return partnerXLink->getColor();
1.115 - else
1.116 - return QColor();
1.117 -}
1.118 -
1.119 -void XLinkItem::setEnd (QPointF p)
1.120 -{
1.121 - if (lmo) ((XLinkObj*)lmo)->setEnd (p);
1.122 -}
1.123 -
1.124 -bool XLinkItem::activate ()
1.125 -{
1.126 - if (beginBranch && endBranch)
1.127 - {
1.128 - if (beginBranch==endBranch) return false;
1.129 -
1.130 - partnerXLink=model->createXLink (endBranch);
1.131 - partnerXLink->setBegin (beginBranch);
1.132 - partnerXLink->setEnd (endBranch);
1.133 - partnerXLink->partnerXLink=this;
1.134 - partnerXLink->isBeginXLink=false;
1.135 -
1.136 - xLinkState=activeXLink;
1.137 - partnerXLink->xLinkState=activeXLink;
1.138 - partnerXLink->setHeading ("xLink to: "+beginBranch->getHeading());
1.139 - setHeading ("xLink to: "+endBranch->getHeading());
1.140 -
1.141 - model->updateActions();
1.142 - return true;
1.143 - } else
1.144 - return false;
1.145 -}
1.146 -
1.147 -bool XLinkItem::isBegin()
1.148 -{
1.149 - return isBeginXLink;
1.150 + return link;
1.151 }
1.152
1.153 void XLinkItem::updateXLink()
1.154 {
1.155 - if(lmo && isBeginXLink)
1.156 - ((XLinkObj*)lmo)->updateXLink();
1.157 - else
1.158 - if (partnerXLink) partnerXLink->updateXLink();
1.159 -}
1.160 -
1.161 -void XLinkItem::updateVisibility()
1.162 -{
1.163 - if (lmo) lmo->updateVisibility();
1.164 + qDebug()<<"XLI::updateXLink";
1.165 + if (link)
1.166 + link->updateLink();
1.167 }
1.168
1.169 BranchItem* XLinkItem::getPartnerBranch()
1.170 {
1.171 - if (!beginBranch && !endBranch)
1.172 - return NULL;
1.173 - if (isBeginXLink)
1.174 - return endBranch;
1.175 - else
1.176 - return beginBranch;
1.177 + if (link && link->getBeginBranch() && link->getEndBranch())
1.178 + {
1.179 + if (parentItem==link->getBeginBranch())
1.180 + return link->getEndBranch();
1.181 + else
1.182 + return link->getBeginBranch();
1.183 + }
1.184 + return NULL;
1.185 }
1.186
1.187 -BranchItem* XLinkItem::getOtherBranch(TreeItem *ti)
1.188 -{
1.189 - BranchItem *pb=getPartnerBranch();
1.190 - if (!pb) return NULL;
1.191 -
1.192 - if (ti==beginBranch)
1.193 - return endBranch;
1.194 - else
1.195 - return beginBranch;
1.196 -}
1.197 -
1.198 -
1.199 -
1.200 -XLinkItem* XLinkItem::getPartnerXLink()
1.201 -{
1.202 - return partnerXLink;
1.203 -}
1.204 -
1.205 -
1.206 -QString XLinkItem::saveToDir ()
1.207 -{
1.208 - QString s="";
1.209 - if (beginBranch && endBranch && xLinkState==activeXLink)
1.210 - {
1.211 - if (beginBranch==endBranch )
1.212 - qWarning ("XLI::saveToDir beginBranch==endBranch"); //FIXME-3 s=""
1.213 - else
1.214 - {
1.215 - QString colAttr=attribut ("color",color.name());
1.216 - QString widAttr=attribut ("width",QString().setNum(width,10));
1.217 - QString begSelAttr=attribut ("beginID",model->getSelectString(beginBranch));
1.218 - QString endSelAttr=attribut ("endID", model->getSelectString(endBranch));
1.219 - s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
1.220 -
1.221 - s+=endElement ("xlink");
1.222 - }
1.223 - }
1.224 - return s;
1.225 -}
1.226 -
1.227 -XLinkObj* XLinkItem::createMapObj(QGraphicsScene *scene)
1.228 -{
1.229 - XLinkObj* xlo=new XLinkObj (scene,this);
1.230 - lmo=(LinkableMapObj*)xlo;
1.231 - return xlo;
1.232 -}
1.233 -