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::setURL (const QString &u)
285 systemFlags.activate ("system-url");
287 systemFlags.deactivate ("system-url");
290 QString TreeItem::getURL ()
295 void TreeItem::setVymLink (const QString &vl)
299 // We need the relative (from loading)
300 // or absolute path (from User event)
301 // and build the absolute path.
302 // Note: If we have relative, use path of
303 // current map to build absolute path
305 if (!d.path().startsWith ("/"))
307 QString p=model->getDestPath();
308 int i=p.findRev("/",-1);
309 d.setPath(p.left(i)+"/"+vl);
313 systemFlags.activate("system-vymLink");
317 systemFlags.deactivate("system-vymLink");
322 QString TreeItem::getVymLink ()
327 void TreeItem::setNote(const QString &s)
331 setNoteObj (n,false);
334 void TreeItem::clearNote()
337 systemFlags.deactivate ("system-note");
340 void TreeItem::setNoteObj(const NoteObj &n, bool updateNoteEditor)
343 if (!note.isEmpty() && !systemFlags.isActive ("system-note"))
344 systemFlags.activate ("system-note");
345 if (note.isEmpty() && systemFlags.isActive ("system-note"))
346 systemFlags.deactivate ("system-note");
349 QString TreeItem::getNote()
351 return note.getNote();
354 NoteObj TreeItem::getNoteObj()
359 QString TreeItem::getNoteASCII(const QString &indent, const int &width)
361 return note.getNoteASCII(indent,width);
364 QString TreeItem::getNoteASCII()
366 return note.getNoteASCII();
369 QString TreeItem::getNoteOpenDoc()
371 return note.getNoteOpenDoc();
374 void TreeItem::activateStandardFlag (const QString &name)
376 standardFlags.activate (name);
377 model->emitDataHasChanged(this);
380 void TreeItem::deactivateStandardFlag (const QString &name)
382 standardFlags.deactivate (name);
383 model->emitDataHasChanged(this);
386 void TreeItem::deactivateAllStandardFlags ()
388 standardFlags.deactivateAll ();
389 model->emitDataHasChanged(this);
392 void TreeItem::toggleStandardFlag(const QString &name, FlagRow *master)
394 standardFlags.toggle (name,master);
395 model->emitDataHasChanged(this);
398 bool TreeItem::isActiveStandardFlag (const QString &name)
400 return standardFlags.isActive (name);
403 QStringList TreeItem::activeStandardFlagNames ()
405 return standardFlags.activeFlagNames();
408 QStringList TreeItem::activeSystemFlagNames () //FIXME-1 missing: scrolled-tmp,hideInExport
410 return systemFlags.activeFlagNames();
413 bool TreeItem::canMoveDown()
417 case Undefined: return false;
420 if (!parentItem) return false;
421 if (parentItem->num (this) < parentItem->branchCount()-1)
426 case Image: return false;
427 default: return false;
431 bool TreeItem::canMoveUp()
435 case Undefined: return false;
438 if (!parentItem) return false;
439 if (parentItem->num (this) > 0)
444 case Image: return false;
445 default: return false;
449 void TreeItem::setID (const QString &s)
454 QString TreeItem::getID()
460 TreeItem* TreeItem::getChildNum(const int &n)
462 if (n>=0 && n<childItems.count() )
463 return childItems.at(n);
468 BranchItem* TreeItem::getFirstBranch()
471 return getBranchNum (branchOffset);
476 BranchItem* TreeItem::getLastBranch()
479 return getBranchNum (branchOffset + branchCounter-1);
484 BranchItem* TreeItem::getNextBranch(BranchItem *currentBranch)
486 if (!currentBranch) return NULL;
487 int n=num (currentBranch)+1;
489 return getBranchNum (branchOffset + n);
495 BranchItem* TreeItem::getBranchNum(const int &n)
498 return (BranchItem*)getChildNum (branchOffset + n);
503 BranchObj* TreeItem::getBranchObjNum(const int &n)
507 return (BranchObj*)(getChildNum (branchOffset+n)->lmo);
512 void TreeItem::setLastSelectedBranch()
515 parentItem->lastSelectedBranchNum=parentItem->childItems.indexOf(this);
518 void TreeItem::setLastSelectedBranch(int i)
520 lastSelectedBranchNum=i;
523 TreeItem* TreeItem::getLastSelectedBranch()
525 return getBranchNum (lastSelectedBranchNum);
529 void TreeItem::setHideTmp (HideTmpMode mode)
531 if (isBranchLikeType() )
532 ((BranchItem*)this)->updateVisibility();
535 //updateVisibility();
540 if (mode==HideExport && (hideExport || hasHiddenExportParent() ) )
542 // Hide stuff according to hideExport flag and parents
543 //setVisibility (false);
545 //FIXME-2 hidden=true;
548 // Do not hide, but still take care of scrolled status
551 XXXXXXXX treeItem should be THIS
553 move visible to TreeItem???
555 BranchObj now has updateContents
557 maybe also start "bool TreeItem::branchlikeType"
561 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem))
562 setVisibility (false);
564 setVisibility (true);
565 //FIXME-2 hidden=false;
569 // And take care of my children
570 for (int i=0; i<branchCount(); ++i)
571 getBranchNum(i)->setHideTmp (mode);
574 bool TreeItem::hasHiddenExportParent()
576 // Calls parents recursivly to
577 // find out, if we or parents are temp. hidden
579 if (hidden || hideExport) return true;
582 return parentItem->hasHiddenExportParent();
588 void TreeItem::setHideInExport(bool b)
590 if (isBranchLikeType() )
593 /* FIXME-1 call setVis and updateContentsSize...
595 systemFlags->activate("hideInExport");
597 systemFlags->deactivate("hideInExport");
605 bool TreeItem::hideInExport()
610 bool TreeItem::isHidden()