4 #include "attributeitem.h"
6 #include "branchitem.h"
14 extern FlagRow* standardFlagsMaster;
18 cout << "Constr. TI this="<<this<<endl;
25 TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
27 //cout << "Constructor TreeItem this="<<this<<" parent="<<parent<<endl;
34 rootItem=parentItem->rootItem;
39 //cout << "Destructor TreeItem "<<getHeadingStd()<<endl;
41 while (!childItems.isEmpty())
43 ti=childItems.takeFirst();
66 // note.setFontHint (textEditor->getFontHintDefault() ); //FIXME-3
67 // isNoteInEditor=false;
75 standardFlags.setMasterRow (standardFlagsMaster);
79 void TreeItem::setModel (VymModel *m)
84 VymModel* TreeItem::getModel ()
89 int TreeItem::getRowNumAppend (TreeItem *item)
93 case Attribute: return attributeOffset + attributeCounter;
94 case XLink: return xlinkOffset + xlinkCounter;
95 case Image: return imageOffset + imageCounter;
96 case MapCenter: return branchOffset + branchCounter;
97 case Branch: return branchOffset + branchCounter;
102 void TreeItem::appendChild(TreeItem *item)
104 item->parentItem=this;
105 item->rootItem=rootItem;
106 item->setModel (model);
108 if (item->type == Attribute)
110 // attribute are on top of list
111 childItems.insert (attributeCounter,item);
118 if (item->type == XLink)
120 childItems.insert (xlinkCounter+xlinkOffset,item);
126 if (item->type == Image)
128 childItems.insert (imageCounter+imageOffset,item);
133 if (item->isBranchLikeType())
135 // branches are on bottom of list
136 childItems.append(item);
139 // Set correct type //FIXME-3 DUP in constr branchitem
141 item->setType(MapCenter);
143 item->setType (Branch);
147 void TreeItem::removeChild(int row)
149 if (row<0 || row > childItems.size()-1)
150 qWarning ("TreeItem::removeChild tried to remove non existing item?!\n");
153 if (childItems.at(row)->type==Attribute)
160 if (childItems.at(row)->type==XLink)
166 if (childItems.at(row)->type==Image)
171 if (childItems.at(row)->isBranchLikeType())
174 childItems.removeAt (row);
179 void TreeItem::clear() // FIXME-2 used in vymmodel addMapInsert, but needs to be used via model and emit layout changes...
181 cout << "TI::clear\n";
182 while ( childItems.size()>0)
185 childItems.removeAt (0);
190 TreeItem *TreeItem::child(int row)
192 return childItems.value(row);
195 int TreeItem::childCount() const
197 return childItems.count();
200 int TreeItem::childNumber() const
203 return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
208 int TreeItem::columnCount() const
213 int TreeItem::branchCount() const
215 return branchCounter;
218 int TreeItem::imageCount() const
223 int TreeItem::xlinkCount() const
228 int TreeItem::attributeCount() const
230 return attributeCounter;
233 int TreeItem::row() const
236 return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
238 cout << "TI::row() pI=NULL this="<<this<<" ***************\n";
242 int TreeItem::depth()
256 TreeItem *TreeItem::parent()
258 //cout << "TI::parent of "<<getHeadingStd()<<" is "<<parentItem<<endl;
262 int TreeItem::childNum()
264 return parentItem->childItems.indexOf (this);
269 if (!parentItem) return -1;
270 return parentItem->num (this);
273 int TreeItem::num (TreeItem *item)
275 if (!item) return -1;
276 if (!childItems.contains(item)) return -1;
277 switch (item->getType())
279 case MapCenter: return childItems.indexOf (item) - branchOffset;
280 case Branch: return childItems.indexOf (item) - branchOffset;
281 case Image: return parentItem->childItems.indexOf (item) - imageOffset;
282 case Attribute: return parentItem->childItems.indexOf (item) - attributeOffset;
283 case XLink: return parentItem->childItems.indexOf (item) - xlinkOffset;
287 void TreeItem::setType(const Type t)
290 itemData[1]=getTypeName();
293 TreeItem::Type TreeItem::getType()
295 if (type==Branch && depth()==0) return MapCenter; //FIXME-3 should not be necesssary
299 bool TreeItem::isBranchLikeType() const
301 if (type==Branch ||type==MapCenter) return true;
305 QString TreeItem::getTypeName()
309 case Undefined: return QString ("Undefined");
310 case MapCenter: return QString ("MapCenter");
311 case Branch: return QString ("Branch");
312 case Image: return QString ("Image");
313 case Attribute: return QString ("Attribute");
314 case XLink: return QString ("XLink");
315 default: return QString ("TreeItem::getTypeName no typename defined?!");
320 QVariant TreeItem::data(int column) const
322 return itemData.value(column);
325 void TreeItem::setHeading (const QString s)
330 QString TreeItem::getHeading () const
332 return itemData[0].toString();
335 std::string TreeItem::getHeadingStd () const
337 return itemData[0].toString().toStdString();
340 void TreeItem::setHeadingColor (QColor color)
345 QColor TreeItem::getHeadingColor ()
350 void TreeItem::setURL (const QString &u)
354 systemFlags.activate ("system-url");
356 systemFlags.deactivate ("system-url");
359 QString TreeItem::getURL ()
364 void TreeItem::setVymLink (const QString &vl)
368 // We need the relative (from loading)
369 // or absolute path (from User event)
370 // and build the absolute path.
371 // Note: If we have relative, use path of
372 // current map to build absolute path
374 if (!d.path().startsWith ("/"))
376 QString p=model->getDestPath();
377 int i=p.findRev("/",-1);
378 d.setPath(p.left(i)+"/"+vl);
382 systemFlags.activate("system-vymLink");
386 systemFlags.deactivate("system-vymLink");
391 QString TreeItem::getVymLink ()
396 void TreeItem::setNote(const QString &s)
403 void TreeItem::clearNote()
406 systemFlags.deactivate ("system-note");
409 void TreeItem::setNoteObj(const NoteObj &n){
411 if (!note.isEmpty() && !systemFlags.isActive ("system-note"))
412 systemFlags.activate ("system-note");
413 if (note.isEmpty() && systemFlags.isActive ("system-note"))
414 systemFlags.deactivate ("system-note");
417 QString TreeItem::getNote()
419 return note.getNote();
422 bool TreeItem::hasEmptyNote()
424 return note.isEmpty();
427 NoteObj TreeItem::getNoteObj()
432 QString TreeItem::getNoteASCII(const QString &indent, const int &width)
434 return note.getNoteASCII(indent,width);
437 QString TreeItem::getNoteASCII()
439 return note.getNoteASCII();
442 QString TreeItem::getNoteOpenDoc()
444 return note.getNoteOpenDoc();
447 void TreeItem::activateStandardFlag (const QString &name)
449 standardFlags.activate (name);
450 model->emitDataHasChanged(this);
453 void TreeItem::deactivateStandardFlag (const QString &name)
455 standardFlags.deactivate (name);
456 model->emitDataHasChanged(this);
459 void TreeItem::deactivateAllStandardFlags ()
461 standardFlags.deactivateAll ();
462 model->emitDataHasChanged(this);
465 void TreeItem::toggleStandardFlag(const QString &name, FlagRow *master)
467 standardFlags.toggle (name,master);
468 model->emitDataHasChanged(this);
471 bool TreeItem::isActiveStandardFlag (const QString &name)
473 return standardFlags.isActive (name);
476 QStringList TreeItem::activeStandardFlagNames ()
478 return standardFlags.activeFlagNames();
481 FlagRow* TreeItem::getStandardFlagRow()
483 return &standardFlags;
486 QStringList TreeItem::activeSystemFlagNames ()
488 return systemFlags.activeFlagNames();
491 bool TreeItem::canMoveDown()
495 case Undefined: return false;
498 if (!parentItem) return false;
499 if (parentItem->num (this) < parentItem->branchCount()-1)
504 case Image: return false;
505 default: return false;
509 bool TreeItem::canMoveUp()
515 if (!parentItem) return false;
516 if (parentItem->num (this) > 0)
521 default: return false;
525 void TreeItem::setID (const QString &s)
530 QString TreeItem::getID()
536 TreeItem* TreeItem::getChildNum(const int &n)
538 if (n>=0 && n<childItems.count() )
539 return childItems.at(n);
544 BranchItem* TreeItem::getFirstBranch()
547 return getBranchNum (branchOffset);
552 BranchItem* TreeItem::getLastBranch()
555 return getBranchNum (branchOffset + branchCounter-1);
560 BranchItem* TreeItem::getNextBranch(BranchItem *currentBranch)
562 if (!currentBranch) return NULL;
563 int n=num (currentBranch)+1;
565 return getBranchNum (branchOffset + n);
571 BranchItem* TreeItem::getBranchNum(const int &n)
573 if (n>=0 && n<branchCounter)
574 return (BranchItem*)getChildNum (branchOffset + n);
579 BranchObj* TreeItem::getBranchObjNum(const int &n)
581 if (n>=0 && n<branchCounter)
583 return (BranchObj*)(getBranchNum(n)->getLMO());
588 ImageItem* TreeItem::getImageNum (const int &n)
590 if (n>=0 && n<imageCounter)
591 return (ImageItem*)getChildNum (imageOffset + n);
596 FloatImageObj* TreeItem::getImageObjNum (const int &n) // FIXME-5 what about SVGs later?
599 return (FloatImageObj*)(getImageNum(n)->getLMO());
604 XLinkItem* TreeItem::getXLinkNum (const int &n)
606 if (n>=0 && n<xlinkCounter )
607 return (XLinkItem*)getChildNum (xlinkOffset +n);
613 XLinkObj* TreeItem::getXLinkObjNum (const int &n)
617 XLinkItem *xli=getXLinkNum (n);
618 if (!xli) return NULL;
620 return (XLinkObj*)(xli->getLMO());
623 xli=xli->getPartnerXLink();
624 if (!xli) return NULL;
625 return (XLinkObj*)(xli->getLMO());
632 void TreeItem::setHideTmp (HideTmpMode mode) //FIXME-2 update visibility in derived objects...
636 ((ImageItem*)this)->updateVisibility();
639 if (mode==HideExport && (hideExport || hasHiddenExportParent() ) )
641 // Hide stuff according to hideExport flag and parents
642 // if (lmo) lmo->setVisibility (false);
646 // Do not hide, but still take care of scrolled status
649 XXXXXXXX treeItem should be THIS
651 move visible to TreeItem???
653 BranchObj now has updateContents
656 if (isBranchLikeType() )
657 ((BranchItem*)this)->updateVisibility();
659 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem))
660 setVisibility (false);
662 setVisibility (true);
667 // And take care of my children
668 for (int i=0; i<branchCount(); ++i)
669 getBranchNum(i)->setHideTmp (mode); // FIXME-4 maybe also consider images and other types
673 bool TreeItem::hasHiddenExportParent()
675 // Calls parents recursivly to
676 // find out, if we or parents are temp. hidden
678 if (hidden || hideExport) return true;
681 return parentItem->hasHiddenExportParent();
687 void TreeItem::setHideInExport(bool b)
689 if (type==Branch || type==Image)
693 systemFlags.activate("system-hideInExport");
695 systemFlags.deactivate("system-hideInExport");
699 bool TreeItem::hideInExport()
704 void TreeItem::updateVisibility()
706 // overloaded in derived objects
709 bool TreeItem::isHidden()
714 QString TreeItem::getGeneralAttr()
718 s+=attribut("hideInExport","true");
720 s+=attribut ("url",url);
721 if (!vymLink.isEmpty())
722 s+=attribut ("vymLink",vymLink);