osg::QNodeTreeView Class Reference

#include <OSGQNodeTreeView_qt.h>

List of all members.

Public Slots

void setRoot (const FieldContainerPtr &pRoot)
void setAspect (UInt32 uiAspect)
void setSelectedFC (const FieldContainerPtr &pFC)

Public Member Functions

 QNodeTreeView (QWidget *parent, const char *name=NULL)
virtual ~QNodeTreeView (void)
FieldContainerPtr getRoot (void)
const FieldContainerPtr getRoot (void) const
UInt32 getAspect (void) const
FieldContainerPtr getSelectedFC (void) const
QFCItemrereadTree (void)

Static Public Member Functions

static QNodeTreeViewdcast (QListView *pView)

Private Types

typedef QListView Inherited
typedef std::list
< FieldContainerPtr
BranchType
typedef BranchType::iterator BranchTypeIt
typedef BranchType::const_iterator BranchTypeConstIt

Private Member Functions

void removeChildren (QListViewItem *pItem)
void doSelectFC (const FieldContainerPtr &pFC)
bool getBranch (const FieldContainerPtr &pFromFC, BranchType &branch)
bool getBranchRecursion (const FieldContainerPtr &pFC, BranchType &branch)
void expandBranch (const BranchType &branch)
QListViewItem * findItemInChildren (const FieldContainerPtr &pFC, QListViewItem *pParentItem)

Private Attributes

FieldContainerPtr _pRoot
UInt32 _uiAspect

Detailed Description

Definition at line 151 of file OSGQNodeTreeView_qt.h.


Member Typedef Documentation

typedef QListView osg::QNodeTreeView::Inherited [private]

Definition at line 177 of file OSGQNodeTreeView_qt.h.

typedef std::list<FieldContainerPtr> osg::QNodeTreeView::BranchType [private]

Definition at line 179 of file OSGQNodeTreeView_qt.h.

typedef BranchType::iterator osg::QNodeTreeView::BranchTypeIt [private]

Definition at line 180 of file OSGQNodeTreeView_qt.h.

typedef BranchType::const_iterator osg::QNodeTreeView::BranchTypeConstIt [private]

Definition at line 181 of file OSGQNodeTreeView_qt.h.


Constructor & Destructor Documentation

QNodeTreeView::QNodeTreeView ( QWidget *  parent,
const char *  name = NULL 
)

Definition at line 475 of file OSGQNodeTreeView_qt.cpp.

00476     : Inherited      (parent, name                     ),
00477       _pRoot         (NullFC                           ),
00478       _uiAspect      (Thread::getCurrent()->getAspect())
00479 {
00480     setRootIsDecorated    (true              );
00481     setAllColumnsShowFocus(true              );
00482     setSorting            (-1                );
00483     addColumn             (QString("FC Type"));
00484     addColumn             (QString("FC Name"));
00485 }

QNodeTreeView::~QNodeTreeView ( void   )  [virtual]

Definition at line 487 of file OSGQNodeTreeView_qt.cpp.

00488 {
00489 }


Member Function Documentation

QNodeTreeView * QNodeTreeView::dcast ( QListView *  pView  )  [static]

Definition at line 492 of file OSGQNodeTreeView_qt.cpp.

Referenced by findItemInChildren().

00493 {
00494     return dynamic_cast<QNodeTreeView *>(pView);
00495 }

FieldContainerPtr QNodeTreeView::getRoot ( void   ) 

Definition at line 498 of file OSGQNodeTreeView_qt.cpp.

References _pRoot.

Referenced by getBranchRecursion().

00499 {
00500     return _pRoot;
00501 }

const FieldContainerPtr QNodeTreeView::getRoot ( void   )  const

Definition at line 504 of file OSGQNodeTreeView_qt.cpp.

References _pRoot.

00505 {
00506     return _pRoot;
00507 }

UInt32 QNodeTreeView::getAspect ( void   )  const

Definition at line 510 of file OSGQNodeTreeView_qt.cpp.

References _uiAspect.

Referenced by osg::QSceneGraphItem::getAspect(), and getBranchRecursion().

00511 {
00512     return _uiAspect;
00513 }

FieldContainerPtr QNodeTreeView::getSelectedFC ( void   )  const

Definition at line 516 of file OSGQNodeTreeView_qt.cpp.

References osg::QSceneGraphItem::getFC(), and osg::NullFC.

Referenced by doSelectFC().

00517 {
00518     if(!selectedItem())
00519         return NullFC;
00520 
00521     QSceneGraphItem *pSGItem = dynamic_cast<QSceneGraphItem *>(selectedItem());
00522 
00523     if(pSGItem)
00524         return pSGItem->getFC();
00525     else
00526         return NullFC;
00527 }

QFCItem * QNodeTreeView::rereadTree ( void   ) 

Definition at line 530 of file OSGQNodeTreeView_qt.cpp.

References _pRoot, and removeChildren().

Referenced by osg::QSceneGraphView::onUpdateClicked(), setAspect(), and setRoot().

00531 {
00532     removeChildren(firstChild());
00533     
00534     delete firstChild();
00535 
00536     return new QFCItem(this, _pRoot);
00537 }

void QNodeTreeView::setRoot ( const FieldContainerPtr pRoot  )  [slot]

Definition at line 540 of file OSGQNodeTreeView_qt.cpp.

References _pRoot, and rereadTree().

00541 {
00542     if(_pRoot != pRoot)
00543     {
00544         _pRoot = pRoot;
00545 
00546         QFCItem *pRootItem = rereadTree();
00547  
00548         setSelected(pRootItem, true);
00549     }
00550 }

void QNodeTreeView::setAspect ( UInt32  uiAspect  )  [slot]

Definition at line 553 of file OSGQNodeTreeView_qt.cpp.

References _uiAspect, and rereadTree().

Referenced by osg::QSceneGraphView::createChildWidgets().

00554 {
00555     _uiAspect = uiAspect;
00556 
00557     QFCItem *pRootItem = rereadTree();
00558 
00559     setSelected(pRootItem, true);
00560 }

void QNodeTreeView::setSelectedFC ( const FieldContainerPtr pFC  )  [slot]
void QNodeTreeView::removeChildren ( QListViewItem *  pItem  )  [private]

Definition at line 569 of file OSGQNodeTreeView_qt.cpp.

Referenced by rereadTree().

00570 {
00571     if(!pItem)
00572         return;
00573     
00574     for(QListViewItem *pChild = pItem->firstChild(); pChild; 
00575         pChild = pItem->firstChild())
00576     {
00577         delete pChild;
00578     }
00579 }

void QNodeTreeView::doSelectFC ( const FieldContainerPtr pFC  )  [private]

Definition at line 582 of file OSGQNodeTreeView_qt.cpp.

References expandBranch(), findItemInChildren(), getBranch(), and getSelectedFC().

Referenced by setSelectedFC().

00583 {
00584     if(pFC == getSelectedFC())
00585         return;
00586 
00587     BranchType         branch;
00588     QListViewItem     *pSelectedItem = this->selectedItem ();
00589 
00590     if(getBranch(pFC, branch))
00591     {
00592         expandBranch(branch);
00593     }
00594     else
00595     {
00596         QListViewItem *pItem = findItemInChildren(pFC, pSelectedItem);
00597 
00598         if(pItem)
00599         {
00600             this->setSelected      (pItem, true);
00601             this->ensureItemVisible(pItem      );
00602         }
00603     }
00604 }

bool QNodeTreeView::getBranch ( const FieldContainerPtr pFromFC,
BranchType branch 
) [private]

Definition at line 607 of file OSGQNodeTreeView_qt.cpp.

References getBranchRecursion(), and osg::NullFC.

Referenced by doSelectFC().

00608 {
00609     branch.clear();
00610 
00611     if(pFromFC == NullFC)
00612         return false;
00613 
00614     return getBranchRecursion(pFromFC, branch);
00615 }

bool QNodeTreeView::getBranchRecursion ( const FieldContainerPtr pFC,
BranchType branch 
) [private]

Definition at line 618 of file OSGQNodeTreeView_qt.cpp.

References osg::MField< FieldTypeT, fieldNameSpace >::begin(), osg::MField< FieldTypeT, fieldNameSpace >::end(), getAspect(), osg::Field::getCardinality(), osg::getParentsField(), getRoot(), osg::SField< FieldTypeT, fieldNameSpace >::getValue(), osg::NullFC, and osg::FieldType::SINGLE_FIELD.

Referenced by getBranch().

00620 {
00621     if(pFromFC == NullFC)
00622     {
00623         return false;
00624     }
00625     else if(pFromFC == getRoot())
00626     {
00627         return true;
00628     }
00629     else
00630     {
00631         branch.push_front(pFromFC);
00632 
00633         Field *pParentsField = getParentsField(pFromFC, getAspect());
00634 
00635         if(!pParentsField)
00636         {
00637             return false;
00638         }
00639 
00640         if(pParentsField->getCardinality() == FieldType::SINGLE_FIELD)
00641         {
00642             SFFieldContainerPtr *pSFParent =
00643                 reinterpret_cast<SFFieldContainerPtr *>(pParentsField);
00644             
00645             if(getBranchRecursion(pSFParent->getValue(), branch))
00646             {
00647                 return true;
00648             }
00649             else
00650             {
00651                 branch.pop_front();
00652 
00653                 return false;
00654             }
00655         }
00656         else
00657         {
00658             MFFieldContainerPtr *pMFParent =
00659                 reinterpret_cast<MFFieldContainerPtr *>(pParentsField);
00660             
00661             MFFieldContainerPtr::iterator mfIter = pMFParent->begin();
00662             MFFieldContainerPtr::iterator mfEnd  = pMFParent->end();
00663 
00664             for(; mfIter != mfEnd; ++mfIter)
00665             {
00666                 if(getBranchRecursion(*mfIter, branch))
00667                 {
00668                     return true;
00669                 }
00670                 else
00671                 {
00672                     branch.pop_front();
00673                 }
00674             }
00675         }
00676     }
00677 
00678     return false;
00679 }

void QNodeTreeView::expandBranch ( const BranchType branch  )  [private]

Definition at line 682 of file OSGQNodeTreeView_qt.cpp.

References osg::endLog(), findItemInChildren(), and SWARNING.

Referenced by doSelectFC().

00683 {
00684     BranchTypeConstIt  bIter = branch.begin();
00685     BranchTypeConstIt  bEnd  = branch.end  ();
00686 
00687     QListViewItem     *pPrevItem = NULL;
00688     QListViewItem     *pCurrItem = this->firstChild();
00689 
00690     for(; bIter != bEnd; ++bIter)
00691     {
00692         pPrevItem = pCurrItem;
00693         pCurrItem = findItemInChildren(*bIter, pCurrItem);
00694 
00695         if(!pCurrItem)
00696         {
00697             SWARNING << "QNodeTreeView::expandBranch(): FAILED. " 
00698                      << "Expanding as far as possible. "
00699                      << endLog;
00700 
00701             break;
00702         }
00703     }
00704 
00705     if(pCurrItem)
00706     {
00707         this->setSelected      (pCurrItem, true);
00708         this->ensureItemVisible(pCurrItem      );
00709     }
00710     else if(pPrevItem)
00711     {
00712         this->setSelected      (pPrevItem, true);
00713         this->ensureItemVisible(pPrevItem      );
00714     }
00715 }

QListViewItem * QNodeTreeView::findItemInChildren ( const FieldContainerPtr pFC,
QListViewItem *  pParentItem 
) [private]

Definition at line 718 of file OSGQNodeTreeView_qt.cpp.

References dcast(), osg::QSceneGraphItem::expand(), osg::QSceneGraphItem::getFC(), and osg::NullFC.

Referenced by doSelectFC(), and expandBranch().

00720 {
00721     if(!pParentItem || (pFC == NullFC))
00722         return NULL;
00723 
00724     QSceneGraphItem *pParentSGItem = QSceneGraphItem::dcast(pParentItem);
00725 
00726     if(pParentSGItem)
00727         pParentSGItem->expand(); // make sure children are created
00728 
00729     for(QListViewItem *pChild = pParentItem->firstChild(); 
00730         pChild;        pChild = pChild->nextSibling()     )
00731     {
00732         QSceneGraphItem *pSGItem = QSceneGraphItem::dcast(pChild);
00733         QHeaderItem     *pHItem  = QHeaderItem::dcast    (pChild);
00734 
00735         if(pSGItem && pSGItem->getFC() == pFC)
00736             return pSGItem;
00737 
00738         if(pHItem && (pHItem->childCount() > 0))
00739         {
00740             for(QListViewItem *pHChild = pHItem->firstChild();
00741                 pHChild;       pHChild = pHChild->nextSibling())
00742             {
00743                 QSceneGraphItem *pHSGItem = QSceneGraphItem::dcast(pHChild);
00744 
00745                 if(pHSGItem && (pHSGItem->getFC() == pFC))
00746                     return pHSGItem;
00747             }
00748         }
00749     }
00750 
00751     return NULL;
00752 }


Member Data Documentation

Definition at line 196 of file OSGQNodeTreeView_qt.h.

Referenced by getRoot(), rereadTree(), and setRoot().

Definition at line 197 of file OSGQNodeTreeView_qt.h.

Referenced by getAspect(), and setAspect().


The documentation for this class was generated from the following files:

Generated on 8 Feb 2010 for OpenSG by  doxygen 1.6.1