1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <inspector/DFBrowser_ItemDocument.hxx>
18 #include <inspector/DFBrowser_Item.hxx>
19 #include <inspector/DFBrowser_ItemApplication.hxx>
20 #include <inspector/DFBrowser_ItemDocument.hxx>
21 #include <inspector/DFBrowser_Tools.hxx>
23 #include <inspector/DFBrowserPane_AttributePane.hxx>
24 #include <inspector/DFBrowserPane_ItemRole.hxx>
30 // =======================================================================
31 // function : GetLabel
33 // =======================================================================
34 TDF_Label DFBrowser_ItemDocument::GetLabel() const
37 if (myDocument.IsNull())
40 if (!myDocument.IsNull())
41 aLabel = myDocument->Main().Root();
44 aLabel = aLabel.Root();
49 // =======================================================================
50 // function : getDocument
52 // =======================================================================
53 const Handle(TDocStd_Document)& DFBrowser_ItemDocument::getDocument() const
59 // =======================================================================
60 // function : initValue
62 // =======================================================================
63 QVariant DFBrowser_ItemDocument::initValue (const int theItemRole) const
65 if (theItemRole == Qt::DisplayRole ||
66 theItemRole == Qt::EditRole ||
67 theItemRole == DFBrowserPane_ItemRole_DisplayExtended ||
68 theItemRole == DFBrowserPane_ItemRole_ToolTipExtended)
69 return DFBrowser_Tools::GetLabelInfo (GetLabel());
70 if (theItemRole == Qt::DecorationRole)
71 return DFBrowser_Tools::GetLabelIcon (GetLabel());
76 // =======================================================================
77 // function : createChild
79 // =======================================================================
80 TreeModel_ItemBasePtr DFBrowser_ItemDocument::createChild (int theRow, int theColumn)
82 TreeModel_ItemBasePtr anItem = DFBrowser_Item::CreateItem (currentItem(), theRow, theColumn);
83 DFBrowser_ItemBasePtr aBaseItem = itemDynamicCast<DFBrowser_ItemBase> (anItem);
84 aBaseItem->SetModule (GetModule());
89 // =======================================================================
92 // =======================================================================
93 void DFBrowser_ItemDocument::Init()
95 DFBrowser_ItemApplicationPtr aParentItem = itemDynamicCast<DFBrowser_ItemApplication> (Parent());
99 const Handle(TDocStd_Application)& anApplication = aParentItem->GetApplication();
100 // items can exist only by items with not empty label
101 if (anApplication.IsNull())
106 int aDocumentId = -1;
107 for (Standard_Integer aDocId = 1, aNbDoc = anApplication->NbDocuments(); aDocId <= aNbDoc && aDocumentId < 0; aDocId++)
109 if (aDocId - 1 == aRowId)
110 aDocumentId = aDocId;
114 Handle(TDocStd_Document) aDocument;
115 anApplication->GetDocument (aDocumentId, aDocument);
116 setDocument (aDocument);
119 setDocument (Handle(TDocStd_Document)());
121 TreeModel_ItemBase::Init();
124 // =======================================================================
127 // =======================================================================
128 void DFBrowser_ItemDocument::Reset()
130 Handle(TDocStd_Document) aDocument;
131 setDocument (aDocument);
133 DFBrowser_ItemBase::Reset();
136 // =======================================================================
137 // function : initItem
139 // =======================================================================
140 void DFBrowser_ItemDocument::initItem() const
145 const_cast<DFBrowser_ItemDocument*>(this)->Init();