further speedup during load. positions of branches are saved (again)
1 #include "branchitem.h"
10 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):TreeItem (data,parent)
12 //cout << "Constr. BranchItem\n";
19 BranchItem::~BranchItem()
21 // cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
29 void BranchItem::copy (BranchItem *other)
31 scrolled=other->scrolled;
32 tmpUnscrolled=other->tmpUnscrolled;
35 void BranchItem::insertBranch (int pos, BranchItem *branch)
38 if (pos>branchCounter) pos=branchCounter;
39 childItems.insert(pos+branchOffset,branch);
40 branch->parentItem=this;
41 branch->setModel (model);
44 branchOffset=childItems.count()-1;
48 QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) //FIXME-1
50 cout << "BI::saveToDir: "<<getHeadingStd()<<endl;
51 // Cloudy stuff can be hidden during exports
52 if (hidden) return QString();
55 BranchObj *bo=(BranchObj*)lmo;
58 // Update of note is usually done while unselecting a branch
59 if (isNoteInEditor) getNoteFromTextEditor();
63 scrolledAttr=attribut ("scrolled","yes");
67 // save area, if not scrolled
69 if (!((BranchObj*)(parObj))->isScrolled() )
72 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
73 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
74 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
75 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
80 // Providing an ID for a branch makes export to XHTML easier
83 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
88 s=beginElement ("branch"
94 // +getIncludeImageAttr()
99 s+=valueElement("heading", getHeading(),
100 attribut ("textColor",QColor( bo->getColor()).name()));
104 if (frame->getFrameType()!=FrameObj::NoFrame)
105 s+=frame->saveToDir ();
107 // save names of flags set
108 s+=standardFlags->saveToDir(tmpdir,prefix,0);
111 for (int i=0; i<floatimage.size(); ++i)
112 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
116 if (!note.isEmpty() )
121 TreeItem *ti=getBranchNum(i);
124 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
131 QString ol; // old link
132 QString cl; // current link
133 for (int i=0; i<xlink.size(); ++i)
135 cl=xlink.at(i)->saveToDir();
142 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
148 s+=endElement ("branch");
152 void BranchItem::updateVisibility() // FIXME-1
156 void BranchItem::setVymLink(QString s)
160 // We need the relative (from loading)
161 // or absolute path (from User event)
162 // and build the absolute path.
163 // Note: If we have relative, use path of
164 // current map to build absolute path
166 if (!d.path().startsWith ("/"))
168 QString p=model->getDestPath();
169 int i=p.findRev("/",-1);
170 d.setPath(p.left(i)+"/"+s);
174 //FIXME-2 systemFlags->activate("vymLink");
178 //FIXME-2 systemFlags->deactivate("vymLink");
182 calcBBoxSize(); // recalculate bbox
183 positionBBox(); // rearrange contents
188 QString BranchItem::getVymLink()
193 void BranchItem::setHeadingColor (QColor color)
195 TreeItem::setHeadingColor (color);
196 if (lmo) ((BranchObj*)lmo)->setColor (color);
199 void BranchItem::unScroll()
201 if (tmpUnscrolled) resetTmpUnscroll();
202 if (scrolled) toggleScroll();
205 void BranchItem::toggleScroll()
210 //FIXME-1 systemFlags->deactivate("scrolledright");
212 for (int i=0; i<branch.size(); ++i)
213 branch.at(i)->setVisibility(true);
219 //FIXME-1 systemFlags->activate("scrolledright");
220 for (int i=0; i<branch.size(); ++i)
221 branch.at(i)->setVisibility(false);
227 move (absPos.x(), absPos.y() );
232 bool BranchItem::isScrolled()
237 bool BranchItem::hasScrolledParent(BranchItem *start)
239 // Calls parents recursivly to
240 // find out, if we are scrolled at all.
241 // But ignore myself, just look at parents.
243 if (this !=start && scrolled) return true;
245 BranchItem* bi=(BranchItem*)parentItem;
247 return bi->hasScrolledParent(start);
252 void BranchItem::tmpUnscroll()
254 // Unscroll parent (recursivly)
255 BranchItem * bi=(BranchItem*)parentItem;
256 if (bi) bi->tmpUnscroll();
262 // FIXME-1 systemFlags->activate("tmpUnscrolledright");
267 void BranchItem::resetTmpUnscroll()
269 // Unscroll parent (recursivly)
270 BranchItem * bi=(BranchItem*)parentItem;
271 if (bi) bi->resetTmpUnscroll();
277 // FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
282 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
286 for (int i=0; i<branchCount(); ++i)
288 ti=getBranchNum(i)->findMapItem(p, excludeTI);
289 if (ti != NULL) return ti;
294 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
297 /* FIXME-2 // Search float images
298 for (int i=0; i<floatimage.size(); ++i )
299 if (floatimage.at(i)->isInClickBox(p) &&
300 (floatimage.at(i) != excludeTI) &&
301 floatimage.at(i)->getParObj()!= excludeTI &&
302 floatimage.at(i)->isVisibleObj()
303 ) return floatimage.at(i)->getTreeItem();
308 TreeItem* BranchItem::findID (QString sid)
312 for (int i=0; i<branchCount(); ++i)
314 ti=getBranchNum(i)->findID (sid);
315 if (ti != NULL) return ti;
319 if (sid==objID) return this;
323 // Search float images
324 for (int i=0; i<floatimage.size(); ++i )
325 if (floatimage.at(i)->inBox(p) &&
326 (floatimage.at(i) != excludeLMO) &&
327 floatimage.at(i)->getParObj()!= excludeLMO &&
328 floatimage.at(i)->isVisibleObj()
329 ) return floatimage.at(i);
335 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
337 return (BranchObj*)lmo;
340 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
342 // Initialize BranchObj, order of things is important...
343 BranchObj* newbo=new BranchObj(scene);
345 newbo->setParObj(parent()->getLMO() );
346 newbo->setTreeItem (this);
347 newbo->setDefAttr(BranchObj::NewBranch);
351 if (!getHeading().isEmpty() )
353 newbo->updateHeading();
354 newbo->setColor (headingColor);
358 //newbo->updateLink(); //FIXME-3