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_TDataStdTreeNodeModel.hxx>
17 #include <inspector/DFBrowserPane_TDataStdTreeNodeItem.hxx>
19 #include <TDataStd_TreeNode.hxx>
21 #include <Standard_WarningsDisable.hxx>
22 #include <QAbstractItemModel>
23 #include <Standard_WarningsRestore.hxx>
25 // =======================================================================
26 // function : Constructor
28 // =======================================================================
29 DFBrowserPane_TDataStdTreeNodeModel::DFBrowserPane_TDataStdTreeNodeModel (QObject* theParent)
30 : TreeModel_ModelBase (theParent)
34 // =======================================================================
35 // function : InitColumns
37 // =======================================================================
38 void DFBrowserPane_TDataStdTreeNodeModel::InitColumns()
40 setHeaderItem (0, TreeModel_HeaderSection ("Name"));
43 // =======================================================================
44 // function : createRootItem
46 // =======================================================================
47 TreeModel_ItemBasePtr DFBrowserPane_TDataStdTreeNodeModel::createRootItem (const int theColumnId)
49 return DFBrowserPane_TDataStdTreeNodeItem::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId);
52 // =======================================================================
53 // function : SetAttribute
55 // =======================================================================
56 void DFBrowserPane_TDataStdTreeNodeModel::SetAttribute (const Handle(TDF_Attribute)& theAttribute)
58 DFBrowserPane_TDataStdTreeNodeItemPtr aRootItem = itemDynamicCast<DFBrowserPane_TDataStdTreeNodeItem>(RootItem (0));
60 aRootItem->SetAttribute (theAttribute);
64 // =======================================================================
65 // function : FindIndex
67 // =======================================================================
68 QModelIndex DFBrowserPane_TDataStdTreeNodeModel::FindIndex (const Handle(TDF_Attribute)& theAttribute,
69 const QModelIndex theParentIndex)
71 QModelIndex aParentIndex = theParentIndex;
73 if (!aParentIndex.isValid())
74 aParentIndex = index (0, 0);
76 DFBrowserPane_TDataStdTreeNodeItemPtr aParentItem = itemDynamicCast<DFBrowserPane_TDataStdTreeNodeItem>
77 (TreeModel_ModelBase::GetItemByIndex (aParentIndex));
79 if (aParentItem->GetAttribute() == theAttribute)
82 for (int aChildId = 0, aCount = aParentItem->rowCount(); aChildId < aCount; aChildId++)
84 QModelIndex anIndex = index (aChildId, 0, aParentIndex);
85 TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
86 DFBrowserPane_TDataStdTreeNodeItemPtr anItem = itemDynamicCast<DFBrowserPane_TDataStdTreeNodeItem>(anItemBase);
88 if (anItem->GetAttribute() == theAttribute)
91 QModelIndex aSubIndex = FindIndex (theAttribute, anIndex);
92 if (aSubIndex.isValid())