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 <DFBrowser_ItemDocument.hxx>
18 #include <DFBrowser_Item.hxx>
19 #include <DFBrowser_ItemApplication.hxx>
20 #include <DFBrowser_ItemDocument.hxx>
21 #include <DFBrowser_Tools.hxx>
23 #include <DFBrowserPane_AttributePane.hxx>
24 #include <DFBrowserPane_ItemRole.hxx>
30 //#define REQUIRE_OCAF_REVIEW:22
32 // =======================================================================
33 // function : GetLabel
35 // =======================================================================
36 TDF_Label DFBrowser_ItemDocument::GetLabel() const
39 if (myDocument.IsNull())
42 if (!myDocument.IsNull())
43 aLabel = myDocument->Main().Root();
46 aLabel = aLabel.Root();
51 // =======================================================================
52 // function : getDocument
54 // =======================================================================
55 const Handle(TDocStd_Document)& DFBrowser_ItemDocument::getDocument() const
61 // =======================================================================
62 // function : initValue
64 // =======================================================================
65 QVariant DFBrowser_ItemDocument::initValue (const int theItemRole) const
67 if (theItemRole == Qt::DisplayRole ||
68 theItemRole == Qt::EditRole ||
69 theItemRole == DFBrowserPane_ItemRole_DisplayExtended ||
70 theItemRole == DFBrowserPane_ItemRole_ToolTipExtended)
71 return DFBrowser_Tools::GetLabelInfo (GetLabel());
72 if (theItemRole == Qt::DecorationRole)
73 return DFBrowser_Tools::GetLabelIcon (GetLabel());
78 // =======================================================================
79 // function : createChild
81 // =======================================================================
82 TreeModel_ItemBasePtr DFBrowser_ItemDocument::createChild (int theRow, int theColumn)
84 TreeModel_ItemBasePtr anItem = DFBrowser_Item::CreateItem (currentItem(), theRow, theColumn);
85 DFBrowser_ItemBasePtr aBaseItem = itemDynamicCast<DFBrowser_ItemBase> (anItem);
86 aBaseItem->SetModule (GetModule());
91 // =======================================================================
94 // =======================================================================
95 void DFBrowser_ItemDocument::Init()
97 DFBrowser_ItemApplicationPtr aParentItem = itemDynamicCast<DFBrowser_ItemApplication> (Parent());
101 const Handle(TDocStd_Application)& anApplication = aParentItem->GetApplication();
102 // items can exist only by items with not empty label
103 if (anApplication.IsNull())
108 int aDocumentId = -1;
109 for (Standard_Integer aDocId = 1, aNbDoc = anApplication->NbDocuments(); aDocId <= aNbDoc && aDocumentId < 0; aDocId++)
111 if (aDocId - 1 == aRowId)
112 aDocumentId = aDocId;
116 Handle(TDocStd_Document) aDocument;
117 anApplication->GetDocument (aDocumentId, aDocument);
118 setDocument (aDocument);
121 setDocument (Handle(TDocStd_Document)());
123 TreeModel_ItemBase::Init();
126 // =======================================================================
129 // =======================================================================
130 void DFBrowser_ItemDocument::Reset()
132 Handle(TDocStd_Document) aDocument;
133 setDocument (aDocument);
135 DFBrowser_ItemBase::Reset();
138 // =======================================================================
139 // function : initItem
141 // =======================================================================
142 void DFBrowser_ItemDocument::initItem() const
147 const_cast<DFBrowser_ItemDocument*>(this)->Init();