0029571: Samples: build qt samples together with OCCT
[occt.git] / tools / DFBrowserPane / DFBrowserPane_TDataStdTreeNodeItem.hxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #ifndef DFBrowserPane_TDataStdTreeNodeItem_H
17 #define DFBrowserPane_TDataStdTreeNodeItem_H
18
19 #include <inspector/TreeModel_ItemBase.hxx>
20
21 #include <Standard.hxx>
22 #include <TDF_Attribute.hxx>
23
24 #include <Standard_WarningsDisable.hxx>
25 #include <QList>
26 #include <QMap>
27 #include <QVariant>
28 #include <Standard_WarningsRestore.hxx>
29
30 class DFBrowserPane_TDataStdTreeNodeItem;
31 typedef QExplicitlySharedDataPointer<DFBrowserPane_TDataStdTreeNodeItem> DFBrowserPane_TDataStdTreeNodeItemPtr;
32
33 //! \class DFBrowserPane_TDataStdTreeNodeItem
34 //! An item connected to TDataStd_TreeNode attribute. Parent is NULL or tree node item.
35 //! Childrens are items for children of tree node attribute. 
36 class DFBrowserPane_TDataStdTreeNodeItem : public TreeModel_ItemBase
37 {
38
39 public:
40
41   //! Creates an item wrapped by a shared pointer
42   //! \param theRow the item row positition in the parent item
43   //! \param theColumn the item column positition in the parent item
44   //! \return the pointer to the created item
45   static DFBrowserPane_TDataStdTreeNodeItemPtr CreateItem (TreeModel_ItemBasePtr theParent,
46                                                            const int theRow, const int theColumn)
47   { return DFBrowserPane_TDataStdTreeNodeItemPtr (new DFBrowserPane_TDataStdTreeNodeItem (theParent, theRow, theColumn)); }
48
49   //!Destructor
50   virtual ~DFBrowserPane_TDataStdTreeNodeItem() Standard_OVERRIDE {};
51
52   //! Store a current attribute
53   //! \param theAttribute an attribute
54   void SetAttribute (const Handle(TDF_Attribute)& theAttribute) { myAttribute = theAttribute; }
55
56   //! Returns the current attribute
57   //! \return an attribute
58   Handle(TDF_Attribute) GetAttribute () const { initItem(); return myAttribute; }
59
60   //! Set state if the attribute is current(corresponds to the selected attribute in tree)
61   //! \param theCurrent boolean state
62   void setCurrentAttribute (const bool theCurrent) { Reset(); myIsCurrentItem = theCurrent; }
63
64   //! Returns child attribute of the current attribute
65   //! \param theChildRow an index of a child attribute
66   //! \returns an attribute
67   Standard_EXPORT Handle(TDF_Attribute) getChildAttribute (const int theChildRow) const;
68
69   //! Inits the item, fills internal containers
70   Standard_EXPORT virtual void Init() Standard_OVERRIDE;
71
72   //! Resets the cached item values. Throws down the initialized state of the item.
73   Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
74
75 protected:
76
77   //! Returns the data stored under the given role for the current item.
78   //! \param theRole an enumeration value of role for data obtaining
79   virtual QVariant initValue (const int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
80
81   //! \return number of children.
82   virtual int initRowCount() const Standard_OVERRIDE { return getRowCount(); }
83
84   //! Creates a child item in the given position.
85   //! \param theRow the child row position
86   //! \param theColumn the child column position
87   //! \return the created item
88   virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
89
90 protected:
91
92   //! Constructor
93   //! param theParent a parent item
94   //! \param theRow the item row positition in the parent item
95   //! \param theColumn the item column positition in the parent item
96   DFBrowserPane_TDataStdTreeNodeItem(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
97     : TreeModel_ItemBase (theParent, theRow, theColumn), myIsCurrentItem (false) {}
98
99   //! Initialize the current item. It creates a backup of the specific item information
100   void initItem() const;
101
102   //! Returns number of children attributes, initializes item is necessary
103   int getRowCount() const;
104
105   //! Returns entry of the label of the current attribute tree node
106   QString getName() const { return myLabelName; }
107
108 private:
109
110   Handle(TDF_Attribute) myAttribute; //! current attribute in tree node hierarchy
111   bool myIsCurrentItem; //! state whether this attribute is active in DFBrowser selected attribute in tree
112
113   int myRowCount; //! cached value of rows count
114   QString myLabelName; //! cached value of label name of the label of the current tree node attribute
115 };
116
117 #endif