9 #include "branchitem.h"
12 TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
22 lastSelectedBranchNum=-1;
25 // note.setFontHint (textEditor->getFontHintDefault() ); //FIXME-2
26 // isNoteInEditor=false;
33 qDeleteAll(childItems);
36 QString TreeItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
38 qWarning ("TreeItem::saveToDir called directly");
44 void TreeItem::copy (OrnamentedObj* other) //FIXME-2 probably need deep copy of branches and data!
47 note.copy (other->note);
49 hideExport=other->hideExport;
53 void TreeItem::setModel (VymModel *m)
58 VymModel* TreeItem::getModel ()
63 void TreeItem::appendChild(TreeItem *item)
65 childItems.append(item);
66 item->setModel (model);
68 if (item->type == Branch || item->type ==MapCenter)
71 branchOffset=childItems.count()-1;
76 void TreeItem::removeChild(int row)
78 if (row<0 || row > childItems.size()-1)
79 qWarning ("TreeItem::removeChild tried to remove non existing item?!\n");
82 cout << "TI::removeChild this="<<this<<" row="<<row<<endl;
83 delete childItems.takeAt (row);
87 TreeItem *TreeItem::child(int row)
89 return childItems.value(row);
92 int TreeItem::childCount() const
94 return childItems.count();
97 int TreeItem::childNumber() const
100 return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
105 int TreeItem::columnCount() const
107 return itemData.count();
110 int TreeItem::branchCount() const
112 return branchCounter;
115 int TreeItem::imageCount() const
118 return imageCounter; // FIXME-1 imageCounter needs to be calculated...
121 int TreeItem::xlinkCount() const // FIXME-2 check if xlinks are stored in a different way (global to model?)
124 return xlinkCounter; // FIXME-1 xlinkCounter needs to be calculated...
127 int TreeItem::row() const
130 return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
135 int TreeItem::column() const
140 int TreeItem::depth()
152 TreeItem *TreeItem::parent()
161 case Undefined: return -1;
162 case MapCenter: return parentItem->childItems.indexOf (this) - branchOffset;
163 case Branch: return parentItem->childItems.indexOf (this) - branchOffset;
164 case Image: return -1; // FIXME-2
169 int TreeItem::num (TreeItem *item)
171 if (!item) return -1;
172 switch (item->getType())
174 case Undefined: return -1;
175 case MapCenter: return childItems.indexOf (this) - branchOffset;
176 case Branch: return childItems.indexOf (this) - branchOffset;
177 case Image: return -1; // FIXME-2
182 QVariant TreeItem::data(int column) const
184 return itemData.value(column);
187 void TreeItem::setHeading (const QString s)
192 QString TreeItem::getHeading () const
194 return itemData[0].toString();
197 std::string TreeItem::headingStd () const
199 return itemData[0].toString().toStdString();
202 void TreeItem::setNote(const QString s)
205 // updateNoteFlag(); FIXME-2 needed?
207 model->emitNoteHasChanged (this);
210 void TreeItem::setNoteObj(const NoteObj &n, bool updateNoteEditor)
213 // updateNoteFlag(); FIXME-2 needed?
214 if (model && updateNoteEditor)
215 model->emitNoteHasChanged (this);
218 QString TreeItem::getNote()
220 return note.getNote();
223 NoteObj TreeItem::getNoteObj()
228 QString TreeItem::getNoteASCII(const QString &indent, const int &width)
230 return note.getNoteASCII(indent,width);
233 QString TreeItem::getNoteASCII()
235 return note.getNoteASCII();
238 QString TreeItem::getNoteOpenDoc()
240 return note.getNoteOpenDoc();
243 void TreeItem::setType(const Type t)
246 itemData[1]=getTypeName();
249 TreeItem::Type TreeItem::getType()
254 bool TreeItem::isBranchLikeType() const
256 if (type==Branch ||type==MapCenter) return true;
260 QString TreeItem::getTypeName()
264 case Undefined: return QString ("Undefined");
265 case MapCenter: return QString ("MapCenter");
266 case Branch: return QString ("Branch");
267 case Image: return QString ("Image");
268 default: return QString ("TreeItem::getTypeName no typename defined?!");
272 TreeItem* TreeItem::getChildNum(const int &n)
274 if (n>=0 && n<childItems.count() )
275 return childItems.at(n);
280 BranchItem* TreeItem::getFirstBranch()
283 return getBranchNum (branchOffset);
288 BranchItem* TreeItem::getLastBranch()
291 return getBranchNum (branchOffset + branchCounter-1);
297 BranchItem* TreeItem::getBranchNum(const int &n)
300 return (BranchItem*)getChildNum (branchOffset + n);
305 BranchObj* TreeItem::getBranchObjNum(const int &n)
309 return (BranchObj*)(getChildNum (branchOffset+n)->lmo);
314 void TreeItem::setLastSelectedBranch()
317 parentItem->lastSelectedBranchNum=parentItem->childItems.indexOf(this);
320 TreeItem* TreeItem::getLastSelectedBranch()
322 return getBranchNum (lastSelectedBranchNum);
326 void TreeItem::setHideTmp (HideTmpMode mode)
328 if (isBranchLikeType() )
329 ((BranchItem*)this)->updateVisibility();
332 //updateVisibility();
337 if (mode==HideExport && (hideExport || hasHiddenExportParent() ) )
339 // Hide stuff according to hideExport flag and parents
340 //setVisibility (false);
342 //FIXME-2 hidden=true;
345 // Do not hide, but still take care of scrolled status
348 XXXXXXXX treeItem should be THIS
350 move visible to TreeItem???
352 BranchObj now has updateContents
354 maybe also start "bool TreeItem::branchlikeType"
358 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem))
359 setVisibility (false);
361 setVisibility (true);
362 //FIXME-2 hidden=false;
366 // And take care of my children
367 for (int i=0; i<branchCount(); ++i)
368 getBranchNum(i)->setHideTmp (mode);
371 bool TreeItem::hasHiddenExportParent()
373 // Calls parents recursivly to
374 // find out, if we or parents are temp. hidden
376 if (hidden || hideExport) return true;
379 return parentItem->hasHiddenExportParent();
385 void TreeItem::setHideInExport(bool b)
387 if (isBranchLikeType() )
390 /* FIXME-1 call setVis and updateContentsSize...
392 systemFlags->activate("hideInExport");
394 systemFlags->deactivate("hideInExport");
402 bool TreeItem::hideInExport()
407 bool TreeItem::isHidden()
413 LinkableMapObj* TreeItem::getLMO() // FIXME-3 VM should be unnecessary in the end
418 void TreeItem::setLMO(LinkableMapObj *l)