7 #include "branchitem.h"
8 #include "mapcenteritem.h"
14 TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent):MapItem()
23 //cout << "Destructor TreeItem "<<getHeadingStd()<<endl;
25 while (!childItems.isEmpty())
27 ti=childItems.takeFirst();
28 switch (ti->getType() )
30 case TreeItem::MapCenter:
31 delete (MapCenterItem*)ti;
33 case TreeItem::Branch:
34 delete (BranchItem*)ti;
53 lastSelectedBranchNum=-1;
59 // note.setFontHint (textEditor->getFontHintDefault() ); //FIXME-2
60 // isNoteInEditor=false;
68 QString TreeItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
70 cout << "TreeItem::saveToDir called directly for ("<<getHeadingStd()<<"), instead of inherited type...\n"; //FIXME-1 triggered on save
76 void TreeItem::copy (OrnamentedObj* other) //FIXME-2 probably need deep copy of branches and data!
79 note.copy (other->note);
86 void TreeItem::setModel (VymModel *m)
91 VymModel* TreeItem::getModel ()
96 void TreeItem::appendChild(TreeItem *item)
98 childItems.append(item);
99 item->parentItem=this;
100 item->setModel (model);
102 if (item->type == Branch || item->type ==MapCenter)
104 if (branchCounter==0)
105 branchOffset=childItems.count()-1;
110 void TreeItem::removeChild(int row)
112 if (row<0 || row > childItems.size()-1)
113 qWarning ("TreeItem::removeChild tried to remove non existing item?!\n");
116 if (childItems.at(row)->isBranchLikeType())
118 childItems.removeAt (row);
122 TreeItem *TreeItem::child(int row)
124 return childItems.value(row);
127 int TreeItem::childCount() const
129 return childItems.count();
132 int TreeItem::childNumber() const
135 return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
140 int TreeItem::columnCount() const
142 return itemData.count();
145 int TreeItem::branchCount() const
147 return branchCounter;
150 int TreeItem::imageCount() const
153 return imageCounter; // FIXME-1 imageCounter needs to be calculated...
156 int TreeItem::xlinkCount() const // FIXME-2 check if xlinks are stored in a different way (global to model?)
159 return xlinkCounter; // FIXME-1 xlinkCounter needs to be calculated...
162 int TreeItem::row() const
165 return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
170 int TreeItem::column() const
175 int TreeItem::depth()
187 TreeItem *TreeItem::parent()
192 int TreeItem::childNum()
194 return parentItem->childItems.indexOf (this);
201 case Undefined: return -1;
202 case MapCenter: return parentItem->childItems.indexOf (this) - branchOffset;
203 case Branch: return parentItem->childItems.indexOf (this) - branchOffset;
204 case Image: return parentItem->childItems.indexOf (this) - imageOffset;
209 int TreeItem::num (TreeItem *item)
211 if (!item) return -1;
212 switch (item->getType())
214 case Undefined: return -1;
215 case MapCenter: return childItems.indexOf (item) - branchOffset;
216 case Branch: return childItems.indexOf (item) - branchOffset;
217 case Image: return parentItem->childItems.indexOf (item) - imageOffset;
221 void TreeItem::setType(const Type t)
224 itemData[1]=getTypeName();
227 TreeItem::Type TreeItem::getType()
232 bool TreeItem::isBranchLikeType() const
234 if (type==Branch ||type==MapCenter) return true;
238 QString TreeItem::getTypeName()
242 case Undefined: return QString ("Undefined");
243 case MapCenter: return QString ("MapCenter");
244 case Branch: return QString ("Branch");
245 case Image: return QString ("Image");
246 default: return QString ("TreeItem::getTypeName no typename defined?!");
251 QVariant TreeItem::data(int column) const
253 return itemData.value(column);
256 void TreeItem::setHeading (const QString s)
261 QString TreeItem::getHeading () const
263 return itemData[0].toString();
266 std::string TreeItem::getHeadingStd () const
268 return itemData[0].toString().toStdString();
271 void TreeItem::setHeadingColor (QColor color)
276 QColor TreeItem::getHeadingColor ()
281 void TreeItem::setNote(const QString s)
284 // updateNoteFlag(); FIXME-2 needed?
286 model->emitNoteHasChanged (this);
289 void TreeItem::setNoteObj(const NoteObj &n, bool updateNoteEditor)
292 // updateNoteFlag(); FIXME-2 needed?
293 if (model && updateNoteEditor)
294 model->emitNoteHasChanged (this);
297 QString TreeItem::getNote()
299 return note.getNote();
302 NoteObj TreeItem::getNoteObj()
307 QString TreeItem::getNoteASCII(const QString &indent, const int &width)
309 return note.getNoteASCII(indent,width);
312 QString TreeItem::getNoteASCII()
314 return note.getNoteASCII();
317 QString TreeItem::getNoteOpenDoc()
319 return note.getNoteOpenDoc();
322 void TreeItem::activateStandardFlag (const QString &name)
324 cout << "TI::activateStandardFlag "<<name.toStdString()<<" for item "<<getHeadingStd()<<endl;
325 cout << " lmo="<<lmo<< " "<<isBranchLikeType()<<endl;
326 standardFlags.activate (name);
327 if (lmo &&isBranchLikeType() )
328 ((BranchObj*)lmo)->activateStandardFlag (name);
331 void TreeItem::deactivateStandardFlag (const QString &name)
333 cout << "TI::deactivateStandardFlag "<<name.toStdString()<<" for item "<<getHeadingStd()<<endl;
334 standardFlags.deactivate (name);
335 if (lmo &&isBranchLikeType() )
336 ((BranchObj*)lmo)->deactivateStandardFlag (name);
339 void TreeItem::toggleStandardFlag(const QString &name)
341 cout << "TI::toggleStandardFlag "<<name.toStdString()<<" for item "<<getHeadingStd()<<endl;
342 if (standardFlags.isActive (name))
343 deactivateStandardFlag (name);
345 activateStandardFlag (name);
348 bool TreeItem::isActiveStandardFlag (const QString &name)
350 return standardFlags.isActive (name);
353 void TreeItem::setID (const QString &s)
358 QString TreeItem::getID()
364 TreeItem* TreeItem::getChildNum(const int &n)
366 if (n>=0 && n<childItems.count() )
367 return childItems.at(n);
372 BranchItem* TreeItem::getFirstBranch()
375 return getBranchNum (branchOffset);
380 BranchItem* TreeItem::getLastBranch()
383 return getBranchNum (branchOffset + branchCounter-1);
388 BranchItem* TreeItem::getNextBranch(BranchItem *currentBranch)
390 if (!currentBranch) return NULL;
391 int n=num (currentBranch)+1;
393 return getBranchNum (branchOffset + n);
399 BranchItem* TreeItem::getBranchNum(const int &n)
402 return (BranchItem*)getChildNum (branchOffset + n);
407 BranchObj* TreeItem::getBranchObjNum(const int &n)
411 return (BranchObj*)(getChildNum (branchOffset+n)->lmo);
416 void TreeItem::setLastSelectedBranch()
419 parentItem->lastSelectedBranchNum=parentItem->childItems.indexOf(this);
422 void TreeItem::setLastSelectedBranch(int i)
424 lastSelectedBranchNum=i;
427 TreeItem* TreeItem::getLastSelectedBranch()
429 return getBranchNum (lastSelectedBranchNum);
433 void TreeItem::setHideTmp (HideTmpMode mode)
435 if (isBranchLikeType() )
436 ((BranchItem*)this)->updateVisibility();
439 //updateVisibility();
444 if (mode==HideExport && (hideExport || hasHiddenExportParent() ) )
446 // Hide stuff according to hideExport flag and parents
447 //setVisibility (false);
449 //FIXME-2 hidden=true;
452 // Do not hide, but still take care of scrolled status
455 XXXXXXXX treeItem should be THIS
457 move visible to TreeItem???
459 BranchObj now has updateContents
461 maybe also start "bool TreeItem::branchlikeType"
465 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem))
466 setVisibility (false);
468 setVisibility (true);
469 //FIXME-2 hidden=false;
473 // And take care of my children
474 for (int i=0; i<branchCount(); ++i)
475 getBranchNum(i)->setHideTmp (mode);
478 bool TreeItem::hasHiddenExportParent()
480 // Calls parents recursivly to
481 // find out, if we or parents are temp. hidden
483 if (hidden || hideExport) return true;
486 return parentItem->hasHiddenExportParent();
492 void TreeItem::setHideInExport(bool b)
494 if (isBranchLikeType() )
497 /* FIXME-1 call setVis and updateContentsSize...
499 systemFlags->activate("hideInExport");
501 systemFlags->deactivate("hideInExport");
509 bool TreeItem::hideInExport()
514 bool TreeItem::isHidden()