0027398: Integrate Qt Browser Widget to Open CASCADE Technology
[occt.git] / tools / ShapeView / ShapeView_ItemRoot.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 ShapeView_ItemRoot_H
17 #define ShapeView_ItemRoot_H
18
19 #include <NCollection_List.hxx>
20 #include <ShapeView_ItemBase.hxx>
21 #include <Standard.hxx>
22 #include <TopoDS_Shape.hxx>
23
24 class ShapeView_ItemRoot;
25 typedef QExplicitlySharedDataPointer<ShapeView_ItemRoot> ShapeView_ItemRootPtr;
26
27 //! \class ShapeView_ItemRoot
28 //! Collects shapes that should be visualized in tree view. Shapes are cached and if shapes are not needed,
29 //! cache should be cleared using RemoveAllShapes.
30 //! Parent is NULL, children are ShapeView_ItemShape items.
31 class ShapeView_ItemRoot : public ShapeView_ItemBase
32 {
33 public:
34
35   //! Creates an item wrapped by a shared pointer
36   static ShapeView_ItemRootPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
37     { return ShapeView_ItemRootPtr (new ShapeView_ItemRoot (theParent, theRow, theColumn)); }
38
39   //! Destructor
40   virtual ~ShapeView_ItemRoot() Standard_OVERRIDE {};
41
42   //! Appends new shape
43   //! \param theShape a shape instance
44   void AddShape (const TopoDS_Shape& theShape) { myShapes.Append (theShape); }
45
46   //! Clears internal container of added shapes
47   void RemoveAllShapes() { myShapes.Clear(); }
48
49   //! Returns shape by the number
50   //! \param theRowId an index of the shape in the internal container.
51   Standard_EXPORT const TopoDS_Shape& GetShape (const int theRowId);
52
53 protected:
54
55   //! Return data value for the role.
56   //! \param theItemRole a value role
57   //! \return the value
58   virtual QVariant initValue(const int theItemRole) const;
59
60   //! \return number of children.
61   virtual int initRowCount() const Standard_OVERRIDE { return myShapes.Size(); }
62
63   //! Creates a child item in the given position.
64   //! \param theRow the child row position
65   //! \param theColumn the child column position
66   //! \return the created item
67   virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
68
69 private:
70
71   //! Constructor
72   //! param theParent a parent item
73   ShapeView_ItemRoot(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
74   : ShapeView_ItemBase (theParent, theRow, theColumn) {}
75
76 private:
77
78   NCollection_List<TopoDS_Shape> myShapes; //!< shapes presented in tree view
79 };
80
81 #endif