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 DFBrowser_ItemDocument_H
17 #define DFBrowser_ItemDocument_H
18 
19 #include <inspector/DFBrowser_ItemBase.hxx>
20 
21 #include <Standard.hxx>
22 #include <TDocStd_Document.hxx>
23 
24 class DFBrowser_ItemDocument;
25 typedef QExplicitlySharedDataPointer<DFBrowser_ItemDocument> DFBrowser_ItemDocumentPtr;
26 
27 //! \class DFBrowser_ItemDocument
28 //! \brief Declaration of the tree model document item.
29 //! This item is connected to the OCAF document. Parent item is application, children are either labels or attributes
30 class DFBrowser_ItemDocument : public DFBrowser_ItemBase
31 {
32 public:
33 
34   //! Creates an item wrapped by a shared pointer
35   //! \param theRow the item row position in the parent item
36   //! \param theColumn the item column position in the parent item
37   //! \return the pointer to the created item
CreateItem(TreeModel_ItemBasePtr theParent,const int theRow,const int theColumn)38   static DFBrowser_ItemDocumentPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
39   { return DFBrowser_ItemDocumentPtr (new DFBrowser_ItemDocument (theParent, theRow, theColumn)); }
40 
41   //! Destructor
~DFBrowser_ItemDocument()42   virtual ~DFBrowser_ItemDocument() {}
43 
44   //! Returns the current label
45   //! \return a label
46   Standard_EXPORT virtual TDF_Label GetLabel() const Standard_OVERRIDE;
47 
48   //! Sets the item document
49   //! \param theLabel an object where the child items structure is found
setDocument(const Handle (TDocStd_Document)& theDocument)50   void setDocument (const Handle(TDocStd_Document)& theDocument) { myDocument = theDocument; }
51 
52   //! Returns true if the current document is not null
53   //! \return a boolean value
hasDocument() const54   bool hasDocument() const { return !getDocument().IsNull(); }
55 
56   //! Returns the current document
57   //! \return a label
58   Standard_EXPORT const Handle(TDocStd_Document)& getDocument() const;
59 
60   //! Inits the item, fills internal containers
61   Standard_EXPORT virtual void Init() Standard_OVERRIDE;
62 
63   //! Resets the cached item values
64   Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
65 
66 protected:
67 
68   //! Initializes the current item. It is empty because Reset() is also empty.
69   virtual void initItem() const Standard_OVERRIDE;
70 
71   //! Initializes the current item. It creates a backup of the specific item information
72   virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE;
73 
74 protected:
75 
76   //! Creates a child item in the given position.
77   //! \param theRow the child row position
78   //! \param theColumn the child column position
79   //! \return the created item
80   virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
81 
82 private:
83 
84   //! Constructor
85   //! \param theParent a parent item
DFBrowser_ItemDocument(TreeModel_ItemBasePtr theParent,const int theRow,const int theColumn)86   DFBrowser_ItemDocument(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
87     : DFBrowser_ItemBase (theParent, theRow, theColumn) {}
88 
89 private:
90 
91   Handle(TDocStd_Document) myDocument; //!< cached application document by the row index of the item
92 };
93 
94 #endif
95