7 #include "branchitem.h"
8 #include "mapcenteritem.h"
14 TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent):MapItem()
16 //cout << "Constructor TreeItem "<<endl;
24 //cout << "Destructor TreeItem "<<getHeadingStd()<<endl;
26 while (!childItems.isEmpty())
28 ti=childItems.takeFirst();
29 switch (ti->getType() )
31 case TreeItem::MapCenter:
32 delete (MapCenterItem*)ti;
34 case TreeItem::Branch:
35 delete (BranchItem*)ti;
54 lastSelectedBranchNum=-1;
60 // note.setFontHint (textEditor->getFontHintDefault() ); //FIXME-2
61 // isNoteInEditor=false;
69 QString TreeItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
71 cout<< "TreeItem::saveToDir called directly for ("<<getHeadingStd()<<"), instead of inherited type...\n";
77 void TreeItem::copy (OrnamentedObj* other) //FIXME-2 probably need deep copy of branches and data!
80 note.copy (other->note);
87 void TreeItem::setModel (VymModel *m)
92 VymModel* TreeItem::getModel ()
97 void TreeItem::appendChild(TreeItem *item)
99 childItems.append(item);
100 item->parentItem=this;
101 item->setModel (model);
103 if (item->type == Branch || item->type ==MapCenter)
105 if (branchCounter==0)
106 branchOffset=childItems.count()-1;
111 void TreeItem::removeChild(int row)
113 if (row<0 || row > childItems.size()-1)
114 qWarning ("TreeItem::removeChild tried to remove non existing item?!\n");
117 if (childItems.at(row)->isBranchLikeType())
119 childItems.removeAt (row);
123 TreeItem *TreeItem::child(int row)
125 return childItems.value(row);
128 int TreeItem::childCount() const
130 return childItems.count();
133 int TreeItem::childNumber() const
136 return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
141 int TreeItem::columnCount() const
143 return itemData.count();
146 int TreeItem::branchCount() const
148 return branchCounter;
151 int TreeItem::imageCount() const
154 return imageCounter; // FIXME-1 imageCounter needs to be calculated...
157 int TreeItem::xlinkCount() const // FIXME-2 check if xlinks are stored in a different way (global to model?)
160 return xlinkCounter; // FIXME-1 xlinkCounter needs to be calculated...
163 int TreeItem::row() const
166 return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
171 int TreeItem::column() const
176 int TreeItem::depth()
188 TreeItem *TreeItem::parent()
193 int TreeItem::childNum()
195 return parentItem->childItems.indexOf (this);
202 case Undefined: return -1;
203 case MapCenter: return parentItem->childItems.indexOf (this) - branchOffset;
204 case Branch: return parentItem->childItems.indexOf (this) - branchOffset;
205 case Image: return parentItem->childItems.indexOf (this) - imageOffset;
210 int TreeItem::num (TreeItem *item)
212 if (!item) return -1;
213 switch (item->getType())
215 case Undefined: return -1;
216 case MapCenter: return childItems.indexOf (item) - branchOffset;
217 case Branch: return childItems.indexOf (item) - branchOffset;
218 case Image: return parentItem->childItems.indexOf (item) - imageOffset;
222 void TreeItem::setType(const Type t)
225 itemData[1]=getTypeName();
228 TreeItem::Type TreeItem::getType()
233 bool TreeItem::isBranchLikeType() const
235 if (type==Branch ||type==MapCenter) return true;
239 QString TreeItem::getTypeName()
243 case Undefined: return QString ("Undefined");
244 case MapCenter: return QString ("MapCenter");
245 case Branch: return QString ("Branch");
246 case Image: return QString ("Image");
247 default: return QString ("TreeItem::getTypeName no typename defined?!");
252 QVariant TreeItem::data(int column) const
254 return itemData.value(column);
257 void TreeItem::setHeading (const QString s)
262 QString TreeItem::getHeading () const
264 return itemData[0].toString();
267 std::string TreeItem::getHeadingStd () const
269 return itemData[0].toString().toStdString();
272 void TreeItem::setHeadingColor (QColor color)
277 QColor TreeItem::getHeadingColor ()
282 void TreeItem::setURL (const QString &u)
286 systemFlags.activate ("system-url");
288 systemFlags.deactivate ("system-url");
291 QString TreeItem::getURL ()
296 void TreeItem::setVymLink (const QString &vl)
300 // We need the relative (from loading)
301 // or absolute path (from User event)
302 // and build the absolute path.
303 // Note: If we have relative, use path of
304 // current map to build absolute path
306 if (!d.path().startsWith ("/"))
308 QString p=model->getDestPath();
309 int i=p.findRev("/",-1);
310 d.setPath(p.left(i)+"/"+vl);
314 systemFlags.activate("system-vymLink");
318 systemFlags.deactivate("system-vymLink");
323 QString TreeItem::getVymLink ()
328 void TreeItem::setNote(const QString &s)
332 setNoteObj (n,false);
335 void TreeItem::clearNote()
338 systemFlags.deactivate ("system-note");
341 void TreeItem::setNoteObj(const NoteObj &n, bool updateNoteEditor) //FIXME-1 setNoteObj is called for every select or so???
344 if (!note.isEmpty() && !systemFlags.isActive ("system-note"))
345 systemFlags.activate ("system-note");
346 if (note.isEmpty() && systemFlags.isActive ("system-note"))
347 systemFlags.deactivate ("system-note");
350 QString TreeItem::getNote()
352 return note.getNote();
355 bool TreeItem::hasEmptyNote()
357 return note.isEmpty();
360 NoteObj TreeItem::getNoteObj()
365 QString TreeItem::getNoteASCII(const QString &indent, const int &width)
367 return note.getNoteASCII(indent,width);
370 QString TreeItem::getNoteASCII()
372 return note.getNoteASCII();
375 QString TreeItem::getNoteOpenDoc()
377 return note.getNoteOpenDoc();
380 void TreeItem::activateStandardFlag (const QString &name)
382 standardFlags.activate (name);
383 model->emitDataHasChanged(this);
386 void TreeItem::deactivateStandardFlag (const QString &name)
388 standardFlags.deactivate (name);
389 model->emitDataHasChanged(this);
392 void TreeItem::deactivateAllStandardFlags ()
394 standardFlags.deactivateAll ();
395 model->emitDataHasChanged(this);
398 void TreeItem::toggleStandardFlag(const QString &name, FlagRow *master)
400 standardFlags.toggle (name,master);
401 model->emitDataHasChanged(this);
404 bool TreeItem::isActiveStandardFlag (const QString &name)
406 return standardFlags.isActive (name);
409 QStringList TreeItem::activeStandardFlagNames ()
411 return standardFlags.activeFlagNames();
414 FlagRow* TreeItem::getStandardFlagRow()
416 return &standardFlags;
420 void TreeItem::updateToolBar()
422 standardFlags.updateToolBar();
425 QStringList TreeItem::activeSystemFlagNames () //FIXME-1 missing: scrolled-tmp,hideInExport
427 return systemFlags.activeFlagNames();
430 bool TreeItem::canMoveDown()
434 case Undefined: return false;
437 if (!parentItem) return false;
438 if (parentItem->num (this) < parentItem->branchCount()-1)
443 case Image: return false;
444 default: return false;
448 bool TreeItem::canMoveUp()
452 case Undefined: return false;
455 if (!parentItem) return false;
456 if (parentItem->num (this) > 0)
461 case Image: return false;
462 default: return false;
466 void TreeItem::setID (const QString &s)
471 QString TreeItem::getID()
477 TreeItem* TreeItem::getChildNum(const int &n)
479 if (n>=0 && n<childItems.count() )
480 return childItems.at(n);
485 BranchItem* TreeItem::getFirstBranch()
488 return getBranchNum (branchOffset);
493 BranchItem* TreeItem::getLastBranch()
496 return getBranchNum (branchOffset + branchCounter-1);
501 BranchItem* TreeItem::getNextBranch(BranchItem *currentBranch)
503 if (!currentBranch) return NULL;
504 int n=num (currentBranch)+1;
506 return getBranchNum (branchOffset + n);
512 BranchItem* TreeItem::getBranchNum(const int &n)
515 return (BranchItem*)getChildNum (branchOffset + n);
520 BranchObj* TreeItem::getBranchObjNum(const int &n)
524 return (BranchObj*)(getChildNum (branchOffset+n)->lmo);
529 void TreeItem::setLastSelectedBranch()
532 parentItem->lastSelectedBranchNum=parentItem->childItems.indexOf(this);
535 void TreeItem::setLastSelectedBranch(int i)
537 lastSelectedBranchNum=i;
540 TreeItem* TreeItem::getLastSelectedBranch()
542 return getBranchNum (lastSelectedBranchNum);
546 void TreeItem::setHideTmp (HideTmpMode mode)
548 if (isBranchLikeType() )
549 ((BranchItem*)this)->updateVisibility();
552 //updateVisibility();
557 if (mode==HideExport && (hideExport || hasHiddenExportParent() ) )
559 // Hide stuff according to hideExport flag and parents
560 //setVisibility (false);
562 //FIXME-2 hidden=true;
565 // Do not hide, but still take care of scrolled status
568 XXXXXXXX treeItem should be THIS
570 move visible to TreeItem???
572 BranchObj now has updateContents
574 maybe also start "bool TreeItem::branchlikeType"
578 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem))
579 setVisibility (false);
581 setVisibility (true);
582 //FIXME-2 hidden=false;
586 // And take care of my children
587 for (int i=0; i<branchCount(); ++i)
588 getBranchNum(i)->setHideTmp (mode);
591 bool TreeItem::hasHiddenExportParent()
593 // Calls parents recursivly to
594 // find out, if we or parents are temp. hidden
596 if (hidden || hideExport) return true;
599 return parentItem->hasHiddenExportParent();
605 void TreeItem::setHideInExport(bool b)
607 if (isBranchLikeType() )
610 /* FIXME-1 call setVis and updateContentsSize...
612 systemFlags->activate("hideInExport");
614 systemFlags->deactivate("hideInExport");
622 bool TreeItem::hideInExport()
627 bool TreeItem::isHidden()