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);
178 TreeItem *TreeItem::child(int row)
180 return childItems.value(row);
183 int TreeItem::childCount() const
185 return childItems.count();
188 int TreeItem::childNumber() const
191 return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
196 int TreeItem::columnCount() const
201 int TreeItem::branchCount() const
203 return branchCounter;
206 int TreeItem::imageCount() const
211 int TreeItem::xlinkCount() const
216 int TreeItem::attributeCount() const
218 return attributeCounter;
221 int TreeItem::row() const
224 return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
226 cout << "TI::row() pI=NULL this="<<this<<" ***************\n";
230 int TreeItem::depth()
244 TreeItem *TreeItem::parent()
246 //cout << "TI::parent of "<<getHeadingStd()<<" is "<<parentItem<<endl;
250 int TreeItem::childNum()
252 return parentItem->childItems.indexOf (this);
257 if (!parentItem) return -1;
258 return parentItem->num (this);
261 int TreeItem::num (TreeItem *item)
263 if (!item) return -1;
264 if (!childItems.contains(item)) return -1;
265 switch (item->getType())
267 case MapCenter: return childItems.indexOf (item) - branchOffset;
268 case Branch: return childItems.indexOf (item) - branchOffset;
269 case Image: return childItems.indexOf (item) - imageOffset;
270 case Attribute: return childItems.indexOf (item) - attributeOffset;
271 case XLink: return childItems.indexOf (item) - xlinkOffset;
275 void TreeItem::setType(const Type t)
278 itemData[1]=getTypeName();
281 TreeItem::Type TreeItem::getType()
283 if (type==Branch && depth()==0) return MapCenter; //FIXME-3 should not be necesssary
287 bool TreeItem::isBranchLikeType() const
289 if (type==Branch ||type==MapCenter) return true;
293 QString TreeItem::getTypeName()
297 case Undefined: return QString ("Undefined");
298 case MapCenter: return QString ("MapCenter");
299 case Branch: return QString ("Branch");
300 case Image: return QString ("Image");
301 case Attribute: return QString ("Attribute");
302 case XLink: return QString ("XLink");
303 default: return QString ("TreeItem::getTypeName no typename defined?!");
308 QVariant TreeItem::data(int column) const
310 return itemData.value(column);
313 void TreeItem::setHeading (const QString s)
318 QString TreeItem::getHeading () const
320 return itemData[0].toString();
323 std::string TreeItem::getHeadingStd () const
325 return itemData[0].toString().toStdString();
328 void TreeItem::setHeadingColor (QColor color)
333 QColor TreeItem::getHeadingColor ()
338 void TreeItem::setURL (const QString &u)
342 systemFlags.activate ("system-url");
344 systemFlags.deactivate ("system-url");
347 QString TreeItem::getURL ()
352 void TreeItem::setVymLink (const QString &vl)
356 // We need the relative (from loading)
357 // or absolute path (from User event)
358 // and build the absolute path.
359 // Note: If we have relative, use path of
360 // current map to build absolute path
362 if (!d.path().startsWith ("/"))
364 QString p=model->getDestPath();
365 int i=p.findRev("/",-1);
366 d.setPath(p.left(i)+"/"+vl);
370 systemFlags.activate("system-vymLink");
374 systemFlags.deactivate("system-vymLink");
379 QString TreeItem::getVymLink ()
384 void TreeItem::setNote(const QString &s)
391 void TreeItem::clearNote()
394 systemFlags.deactivate ("system-note");
397 void TreeItem::setNoteObj(const NoteObj &n){
399 if (!note.isEmpty() && !systemFlags.isActive ("system-note"))
400 systemFlags.activate ("system-note");
401 if (note.isEmpty() && systemFlags.isActive ("system-note"))
402 systemFlags.deactivate ("system-note");
405 QString TreeItem::getNote()
407 return note.getNote();
410 bool TreeItem::hasEmptyNote()
412 return note.isEmpty();
415 NoteObj TreeItem::getNoteObj()
420 QString TreeItem::getNoteASCII(const QString &indent, const int &width)
422 return note.getNoteASCII(indent,width);
425 QString TreeItem::getNoteASCII()
427 return note.getNoteASCII();
430 QString TreeItem::getNoteOpenDoc()
432 return note.getNoteOpenDoc();
435 void TreeItem::activateStandardFlag (const QString &name)
437 standardFlags.activate (name);
438 model->emitDataHasChanged(this);
441 void TreeItem::deactivateStandardFlag (const QString &name)
443 standardFlags.deactivate (name);
444 model->emitDataHasChanged(this);
447 void TreeItem::deactivateAllStandardFlags ()
449 standardFlags.deactivateAll ();
450 model->emitDataHasChanged(this);
453 void TreeItem::toggleStandardFlag(const QString &name, FlagRow *master)
455 standardFlags.toggle (name,master);
456 model->emitDataHasChanged(this);
459 bool TreeItem::isActiveStandardFlag (const QString &name)
461 return standardFlags.isActive (name);
464 QStringList TreeItem::activeStandardFlagNames ()
466 return standardFlags.activeFlagNames();
469 FlagRow* TreeItem::getStandardFlagRow()
471 return &standardFlags;
474 QStringList TreeItem::activeSystemFlagNames ()
476 return systemFlags.activeFlagNames();
479 bool TreeItem::canMoveDown()
483 case Undefined: return false;
486 if (!parentItem) return false;
487 if (parentItem->num (this) < parentItem->branchCount()-1)
492 case Image: return false;
493 default: return false;
497 bool TreeItem::canMoveUp()
503 if (!parentItem) return false;
504 if (parentItem->num (this) > 0)
509 default: return false;
513 void TreeItem::setID (const QString &s)
518 QString TreeItem::getID()
524 TreeItem* TreeItem::getChildNum(const int &n)
526 if (n>=0 && n<childItems.count() )
527 return childItems.at(n);
532 BranchItem* TreeItem::getFirstBranch()
535 return getBranchNum (0);
540 BranchItem* TreeItem::getLastBranch()
543 return getBranchNum (branchCounter-1);
548 BranchItem* TreeItem::getNextBranch(BranchItem *currentBranch)
550 if (!currentBranch) return NULL;
551 int n=num (currentBranch)+1;
553 return getBranchNum (branchOffset + n);
559 BranchItem* TreeItem::getBranchNum(const int &n)
561 if (n>=0 && n<branchCounter)
562 return (BranchItem*)getChildNum (branchOffset + n);
567 BranchObj* TreeItem::getBranchObjNum(const int &n)
569 if (n>=0 && n<branchCounter)
571 return (BranchObj*)(getBranchNum(n)->getLMO());
576 ImageItem* TreeItem::getImageNum (const int &n)
578 if (n>=0 && n<imageCounter)
579 return (ImageItem*)getChildNum (imageOffset + n);
584 FloatImageObj* TreeItem::getImageObjNum (const int &n) // FIXME-5 what about SVGs later?
587 return (FloatImageObj*)(getImageNum(n)->getLMO());
592 AttributeItem* TreeItem::getAttributeNum (const int &n)
594 if (n>=0 && n<attributeCounter)
595 return (AttributeItem*)getChildNum (attributeOffset + n);
600 XLinkItem* TreeItem::getXLinkNum (const int &n)
602 if (n>=0 && n<xlinkCounter )
603 return (XLinkItem*)getChildNum (xlinkOffset +n);
609 XLinkObj* TreeItem::getXLinkObjNum (const int &n)
613 XLinkItem *xli=getXLinkNum (n);
614 if (!xli) return NULL;
616 return (XLinkObj*)(xli->getLMO());
619 xli=xli->getPartnerXLink();
620 if (!xli) return NULL;
621 return (XLinkObj*)(xli->getLMO());
628 void TreeItem::setHideTmp (HideTmpMode mode) //FIXME-2 update visibility in derived objects...
632 ((ImageItem*)this)->updateVisibility();
635 if (mode==HideExport && (hideExport || hasHiddenExportParent() ) )
637 // Hide stuff according to hideExport flag and parents
638 // if (lmo) lmo->setVisibility (false);
642 // Do not hide, but still take care of scrolled status
645 XXXXXXXX treeItem should be THIS
647 move visible to TreeItem???
649 BranchObj now has updateContents
652 if (isBranchLikeType() )
653 ((BranchItem*)this)->updateVisibility();
655 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem))
656 setVisibility (false);
658 setVisibility (true);
663 // And take care of my children
664 for (int i=0; i<branchCount(); ++i)
665 getBranchNum(i)->setHideTmp (mode); // FIXME-4 maybe also consider images and other types
669 bool TreeItem::hasHiddenExportParent()
671 // Calls parents recursivly to
672 // find out, if we or parents are temp. hidden
674 if (hidden || hideExport) return true;
677 return parentItem->hasHiddenExportParent();
683 void TreeItem::setHideInExport(bool b)
685 if (type==Branch || type==Image)
689 systemFlags.activate("system-hideInExport");
691 systemFlags.deactivate("system-hideInExport");
695 bool TreeItem::hideInExport()
700 void TreeItem::updateVisibility()
702 // overloaded in derived objects
705 bool TreeItem::isHidden()
710 QString TreeItem::getGeneralAttr()
714 s+=attribut("hideInExport","true");
716 s+=attribut ("url",url);
717 if (!vymLink.isEmpty())
718 s+=attribut ("vymLink",convertToRel (model->getDestPath(),vymLink));