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/DFBrowserPane_TDataStdTreeNode.hxx>
18 #include <inspector/DFBrowserPane_AttributePaneModel.hxx>
19 #include <inspector/DFBrowserPane_TableView.hxx>
20 #include <inspector/DFBrowserPane_TDataStdTreeNodeItem.hxx>
21 #include <inspector/DFBrowserPane_TDataStdTreeNodeModel.hxx>
22 #include <inspector/DFBrowserPane_Tools.hxx>
24 #include <TDataStd_TreeNode.hxx>
29 #include <QVBoxLayout>
31 #include <QItemSelectionModel>
33 // =======================================================================
34 // function : Constructor
36 // =======================================================================
37 DFBrowserPane_TDataStdTreeNode::DFBrowserPane_TDataStdTreeNode()
38 : DFBrowserPane_AttributePane()
40 myModel = new DFBrowserPane_TDataStdTreeNodeModel (0);
41 mySelectionModels.clear(); // do not use selection model of parent pane
42 mySelectionModels.push_back (new QItemSelectionModel (myModel));
45 // =======================================================================
46 // function : CreateWidget
48 // =======================================================================
49 QWidget* DFBrowserPane_TDataStdTreeNode::CreateWidget (QWidget* theParent)
51 QWidget* aMainWidget = new QWidget (theParent);
52 aMainWidget->setVisible (false);
54 myTableView = new DFBrowserPane_TableView (aMainWidget, getTableColumnWidths());
55 DFBrowserPane_TableView::SetFixedRowCount (1, myTableView->GetTableView());
56 myTableView->SetModel (myPaneModel);
58 QVBoxLayout* aLay = new QVBoxLayout (aMainWidget);
59 aLay->setContentsMargins (0, 0, 0, 0);
60 aLay->addWidget (myTableView);
62 myTreeNodeView = new QTreeView (theParent);
63 myTreeNodeView->setModel (myModel);
64 myTreeNodeView->setSelectionModel (mySelectionModels.front());
65 myTreeNodeView->setSelectionBehavior (QAbstractItemView::SelectRows);
67 aLay->addWidget (myTreeNodeView);
71 // =======================================================================
74 // =======================================================================
75 void DFBrowserPane_TDataStdTreeNode::Init (const Handle(TDF_Attribute)& theAttribute)
77 Handle(TDataStd_TreeNode) aTreeNode = Handle(TDataStd_TreeNode)::DownCast (theAttribute);
79 bool aDefaultGUID = aTreeNode->ID() != aTreeNode->GetDefaultTreeID();
80 myTableView->setVisible (!aDefaultGUID);
82 QList<QVariant> aValues;
84 aTreeNode->ID().ToCString (aStr);
85 TCollection_AsciiString aString(aStr);
86 aValues.append (DFBrowserPane_Tools::ToString(aString));
87 getPaneModel()->Init (aValues);
91 DFBrowserPane_TDataStdTreeNodeModel* aModel = dynamic_cast<DFBrowserPane_TDataStdTreeNodeModel*> (myModel);
94 if (!aTreeNode.IsNull())
96 Handle(TDataStd_TreeNode) aRootItem = aTreeNode->Root();
97 aModel->SetAttribute (aRootItem);
99 QModelIndex anIndex = aModel->FindIndex (theAttribute);
100 if (anIndex.isValid())
102 myTreeNodeView->setExpanded (anIndex.parent(), true);
103 myTreeNodeView->scrollTo (anIndex);
105 TreeModel_ItemBasePtr anAttributeItem = TreeModel_ModelBase::GetItemByIndex (anIndex);
106 DFBrowserPane_TDataStdTreeNodeItemPtr anAttributeNodeItem =
107 itemDynamicCast<DFBrowserPane_TDataStdTreeNodeItem>(anAttributeItem);
108 anAttributeNodeItem->setCurrentAttribute (true);
111 aModel->EmitLayoutChanged();
114 // =======================================================================
115 // function : GetShortAttributeInfo
117 // =======================================================================
118 void DFBrowserPane_TDataStdTreeNode::GetShortAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
119 QList<QVariant>& theValues)
121 Handle(TDataStd_TreeNode) aTNAttribute = Handle(TDataStd_TreeNode)::DownCast (theAttribute);
122 bool aDefaultGUID = aTNAttribute->ID() != aTNAttribute->GetDefaultTreeID();
125 QList<QVariant> aValues;
127 aTNAttribute->ID().ToCString (aStr);
128 TCollection_AsciiString aString(aStr);
129 aGUIDPrefix = DFBrowserPane_Tools::ToString(aString);
132 if (aTNAttribute->HasFather())
134 TDF_Label aLabel = aTNAttribute->Father()->Label();
135 theValues.append (QString ("%1 ==> %2").arg(aGUIDPrefix).arg (DFBrowserPane_Tools::GetEntry (aLabel).ToCString()));
139 Handle(TDataStd_TreeNode) aFirstChild = aTNAttribute->First();
141 while (! aFirstChild.IsNull() )
143 TDF_Label aLabel = aFirstChild->Label();
144 aRefs.append (DFBrowserPane_Tools::GetEntry (aLabel).ToCString());
145 aFirstChild = aFirstChild->Next();
147 theValues.append (QString ("%1 <== (%2)").arg(aGUIDPrefix).arg (aRefs.join (", ")));
151 // =======================================================================
152 // function : GetReferences
154 // =======================================================================
155 void DFBrowserPane_TDataStdTreeNode::GetReferences (const Handle(TDF_Attribute)& theAttribute,
156 NCollection_List<TDF_Label>& theRefLabels,
157 Handle(Standard_Transient)&)
159 Handle(TDataStd_TreeNode) anAttribute = Handle(TDataStd_TreeNode)::DownCast (theAttribute);
160 if (anAttribute.IsNull())
163 theRefLabels.Append (anAttribute->Label());