4 #include "attributeitem.h"
6 #include "branchitem.h"
14 extern FlagRow* standardFlagsMaster;
16 uint TreeItem::idLast=0; // Create instance
20 cout << "Constr. TI this="<<this<<endl;
27 TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
29 //cout << "Constructor TreeItem this="<<this<<" parent="<<parent<<endl;
36 rootItem=parentItem->rootItem;
41 //cout << "Destructor TreeItem "<<getHeadingStd()<<endl;
43 while (!childItems.isEmpty())
45 ti=childItems.takeFirst();
72 // note.setFontHint (textEditor->getFontHintDefault() ); //FIXME-3
73 // isNoteInEditor=false;
78 standardFlags.setMasterRow (standardFlagsMaster);
82 void TreeItem::setModel (VymModel *m)
87 VymModel* TreeItem::getModel ()
92 int TreeItem::getRowNumAppend (TreeItem *item)
96 case Attribute: return attributeOffset + attributeCounter;
97 case XLink: return xlinkOffset + xlinkCounter;
98 case Image: return imageOffset + imageCounter;
99 case MapCenter: return branchOffset + branchCounter;
100 case Branch: return branchOffset + branchCounter;
105 void TreeItem::appendChild(TreeItem *item)
107 item->parentItem=this;
108 item->rootItem=rootItem;
109 item->setModel (model);
111 if (item->type == Attribute)
113 // attribute are on top of list
114 childItems.insert (attributeCounter,item);
121 if (item->type == XLink)
123 childItems.insert (xlinkCounter+xlinkOffset,item);
129 if (item->type == Image)
131 childItems.insert (imageCounter+imageOffset,item);
136 if (item->isBranchLikeType())
138 // branches are on bottom of list
139 childItems.append(item);
142 // Set correct type //FIXME-3 DUP in constr branchitem
144 item->setType(MapCenter);
146 item->setType (Branch);
150 void TreeItem::removeChild(int row)
152 if (row<0 || row > childItems.size()-1)
153 qWarning ("TreeItem::removeChild tried to remove non existing item?!\n");
156 if (childItems.at(row)->type==Attribute)
163 if (childItems.at(row)->type==XLink)
169 if (childItems.at(row)->type==Image)
174 if (childItems.at(row)->isBranchLikeType())
177 childItems.removeAt (row);
181 TreeItem *TreeItem::child(int row)
183 return childItems.value(row);
186 int TreeItem::childCount() const
188 return childItems.count();
191 int TreeItem::childNumber() const
194 return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
199 int TreeItem::columnCount() const
204 int TreeItem::branchCount() const
206 return branchCounter;
209 int TreeItem::imageCount() const
214 int TreeItem::xlinkCount() const
219 int TreeItem::attributeCount() const
221 return attributeCounter;
224 int TreeItem::row() const
227 return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
229 cout << "TI::row() pI=NULL this="<<this<<" ***************\n";
233 int TreeItem::depth()
247 TreeItem *TreeItem::parent()
249 //cout << "TI::parent of "<<getHeadingStd()<<" is "<<parentItem<<endl;
253 int TreeItem::childNum()
255 return parentItem->childItems.indexOf (this);
260 if (!parentItem) return -1;
261 return parentItem->num (this);
264 int TreeItem::num (TreeItem *item)
266 if (!item) return -1;
267 if (!childItems.contains(item)) return -1;
268 switch (item->getType())
270 case MapCenter: return childItems.indexOf (item) - branchOffset;
271 case Branch: return childItems.indexOf (item) - branchOffset;
272 case Image: return childItems.indexOf (item) - imageOffset;
273 case Attribute: return childItems.indexOf (item) - attributeOffset;
274 case XLink: return childItems.indexOf (item) - xlinkOffset;
278 void TreeItem::setType(const Type t)
281 itemData[1]=getTypeName();
284 TreeItem::Type TreeItem::getType()
286 if (type==Branch && depth()==0) return MapCenter; //FIXME-3 should not be necesssary
290 bool TreeItem::isBranchLikeType() const
292 if (type==Branch ||type==MapCenter) return true;
296 QString TreeItem::getTypeName()
300 case Undefined: return QString ("Undefined");
301 case MapCenter: return QString ("MapCenter");
302 case Branch: return QString ("Branch");
303 case Image: return QString ("Image");
304 case Attribute: return QString ("Attribute");
305 case XLink: return QString ("XLink");
306 default: return QString ("TreeItem::getTypeName no typename defined?!");
311 QVariant TreeItem::data(int column) const
313 return itemData.value(column);
316 void TreeItem::setHeading (const QString s)
321 QString TreeItem::getHeading () const
323 return itemData[0].toString();
326 std::string TreeItem::getHeadingStd () const
328 return itemData[0].toString().toStdString();
331 void TreeItem::setHeadingColor (QColor color)
336 QColor TreeItem::getHeadingColor ()
341 void TreeItem::setURL (const QString &u)
346 if (url.contains ("bugzilla.novell.com"))
348 systemFlags.activate ("system-url-bugzilla-novell");
349 if (systemFlags.isActive ("system-url"))
350 systemFlags.deactivate ("system-url");
353 systemFlags.activate ("system-url");
354 if (systemFlags.isActive ("system-url-bugzilla-novell"))
355 systemFlags.deactivate ("system-url-bugzilla-novell");
360 if (systemFlags.isActive ("system-url"))
361 systemFlags.deactivate ("system-url");
362 if (systemFlags.isActive ("system-url-bugzilla-novell"))
363 systemFlags.deactivate ("system-url-bugzilla-novell");
367 QString TreeItem::getURL ()
372 void TreeItem::setVymLink (const QString &vl)
376 // We need the relative (from loading)
377 // or absolute path (from User event)
378 // and build the absolute path.
379 // Note: If we have relative, use path of
380 // current map to build absolute path
382 if (!d.path().startsWith ("/"))
384 QString p=model->getDestPath();
385 int i=p.findRev("/",-1);
386 d.setPath(p.left(i)+"/"+vl);
390 systemFlags.activate("system-vymLink");
394 systemFlags.deactivate("system-vymLink");
399 QString TreeItem::getVymLink ()
404 void TreeItem::setNote(const QString &s)
411 void TreeItem::clearNote()
414 systemFlags.deactivate ("system-note");
417 void TreeItem::setNoteObj(const NoteObj &n){
419 if (!note.isEmpty() && !systemFlags.isActive ("system-note"))
420 systemFlags.activate ("system-note");
421 if (note.isEmpty() && systemFlags.isActive ("system-note"))
422 systemFlags.deactivate ("system-note");
425 QString TreeItem::getNote()
427 return note.getNote();
430 bool TreeItem::hasEmptyNote()
432 return note.isEmpty();
435 NoteObj TreeItem::getNoteObj()
440 QString TreeItem::getNoteASCII(const QString &indent, const int &width)
442 return note.getNoteASCII(indent,width);
445 QString TreeItem::getNoteASCII()
447 return note.getNoteASCII();
450 QString TreeItem::getNoteOpenDoc()
452 return note.getNoteOpenDoc();
455 void TreeItem::activateStandardFlag (const QString &name)
457 standardFlags.activate (name);
458 model->emitDataHasChanged(this);
461 void TreeItem::deactivateStandardFlag (const QString &name)
463 standardFlags.deactivate (name);
464 model->emitDataHasChanged(this);
467 void TreeItem::deactivateAllStandardFlags ()
469 standardFlags.deactivateAll ();
470 model->emitDataHasChanged(this);
473 void TreeItem::toggleStandardFlag(const QString &name, FlagRow *master)
475 standardFlags.toggle (name,master);
476 model->emitDataHasChanged(this);
479 bool TreeItem::isActiveStandardFlag (const QString &name)
481 return standardFlags.isActive (name);
484 QStringList TreeItem::activeStandardFlagNames ()
486 return standardFlags.activeFlagNames();
489 FlagRow* TreeItem::getStandardFlagRow()
491 return &standardFlags;
494 QStringList TreeItem::activeSystemFlagNames ()
496 return systemFlags.activeFlagNames();
499 bool TreeItem::canMoveDown()
503 case Undefined: return false;
506 if (!parentItem) return false;
507 if (parentItem->num (this) < parentItem->branchCount()-1)
512 case Image: return false;
513 default: return false;
517 bool TreeItem::canMoveUp()
523 if (!parentItem) return false;
524 if (parentItem->num (this) > 0)
529 default: return false;
533 uint TreeItem::getID()
538 TreeItem* TreeItem::findID (const uint &n)
540 for (int i=0;i<childItems.count(); i++)
541 if (n==childItems.at(i)->id)
542 return childItems.at(n);
547 TreeItem* TreeItem::getChildNum(const int &n)
549 if (n>=0 && n<childItems.count() )
550 return childItems.at(n);
555 BranchItem* TreeItem::getFirstBranch()
558 return getBranchNum (0);
563 BranchItem* TreeItem::getLastBranch()
566 return getBranchNum (branchCounter-1);
571 BranchItem* TreeItem::getNextBranch(BranchItem *currentBranch)
573 if (!currentBranch) return NULL;
574 int n=num (currentBranch)+1;
576 return getBranchNum (branchOffset + n);
582 BranchItem* TreeItem::getBranchNum(const int &n)
584 if (n>=0 && n<branchCounter)
585 return (BranchItem*)getChildNum (branchOffset + n);
590 BranchObj* TreeItem::getBranchObjNum(const int &n)
592 if (n>=0 && n<branchCounter)
594 return (BranchObj*)(getBranchNum(n)->getLMO());
599 ImageItem* TreeItem::getImageNum (const int &n)
601 if (n>=0 && n<imageCounter)
602 return (ImageItem*)getChildNum (imageOffset + n);
607 FloatImageObj* TreeItem::getImageObjNum (const int &n) // FIXME-5 what about SVGs later?
610 return (FloatImageObj*)(getImageNum(n)->getLMO());
615 AttributeItem* TreeItem::getAttributeNum (const int &n)
617 if (n>=0 && n<attributeCounter)
618 return (AttributeItem*)getChildNum (attributeOffset + n);
623 XLinkItem* TreeItem::getXLinkNum (const int &n)
625 if (n>=0 && n<xlinkCounter )
626 return (XLinkItem*)getChildNum (xlinkOffset +n);
632 XLinkObj* TreeItem::getXLinkObjNum (const int &n)
636 XLinkItem *xli=getXLinkNum (n);
637 if (!xli) return NULL;
639 return (XLinkObj*)(xli->getLMO());
642 xli=xli->getPartnerXLink();
643 if (!xli) return NULL;
644 return (XLinkObj*)(xli->getLMO());
651 void TreeItem::setHideTmp (HideTmpMode mode) //FIXME-3 update visibility in derived objects
653 if (type==Image || type==Branch || type==MapCenter)
654 // ((ImageItem*)this)->updateVisibility();
656 LinkableMapObj* lmo=((MapItem*)this)->getLMO();
658 if (mode==HideExport && (hideExport || hasHiddenExportParent() ) ) // FIXME-3 try to avoid calling hasScrolledParent repeatedly
661 // Hide stuff according to hideExport flag and parents
663 //if (lmo) lmo->setVisibility (false);
664 updateVisibility(); // FIXME-3 missing for images
667 // Do not hide, but still take care of scrolled status
671 // And take care of my children
672 for (int i=0; i<branchCount(); ++i)
673 getBranchNum(i)->setHideTmp (mode);
677 bool TreeItem::hasHiddenExportParent()
679 // Calls parents recursivly to
680 // find out, if we or parents are temp. hidden
682 if (hidden || hideExport) return true;
685 return parentItem->hasHiddenExportParent();
691 void TreeItem::setHideInExport(bool b)
693 if (type==MapCenter ||type==Branch || type==Image)
697 systemFlags.activate("system-hideInExport");
699 systemFlags.deactivate("system-hideInExport");
703 bool TreeItem::hideInExport()
708 void TreeItem::updateVisibility()
710 // overloaded in derived objects
713 bool TreeItem::isHidden()
718 QString TreeItem::getGeneralAttr()
722 s+=attribut("hideInExport","true");
724 s+=attribut ("url",url);
725 if (!vymLink.isEmpty())
726 s+=attribut ("vymLink",convertToRel (model->getDestPath(),vymLink));