14bbbdcb |
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 | |
0cb512c0 |
16 | #include <inspector/VInspector_ViewModel.hxx> |
14bbbdcb |
17 | |
6822a3be |
18 | #include <inspector/TreeModel_Tools.hxx> |
0cb512c0 |
19 | #include <inspector/VInspector_ItemContext.hxx> |
0cb512c0 |
20 | #include <inspector/VInspector_ItemPresentableObject.hxx> |
14bbbdcb |
21 | |
130eb114 |
22 | #include <Standard_WarningsDisable.hxx> |
14bbbdcb |
23 | #include <QItemSelectionModel> |
24 | #include <QStringList> |
130eb114 |
25 | #include <Standard_WarningsRestore.hxx> |
14bbbdcb |
26 | |
6822a3be |
27 | const int COLUMN_POINTER_WIDTH = 70; |
6822a3be |
28 | |
14bbbdcb |
29 | // ======================================================================= |
30 | // function : Constructor |
31 | // purpose : |
32 | // ======================================================================= |
33 | VInspector_ViewModel::VInspector_ViewModel (QObject* theParent) |
34 | : TreeModel_ModelBase (theParent) |
35 | { |
7e1c1e48 |
36 | } |
37 | |
38 | // ======================================================================= |
39 | // function : InitColumns |
40 | // purpose : |
41 | // ======================================================================= |
42 | void VInspector_ViewModel::InitColumns() |
43 | { |
44 | TreeModel_ModelBase::InitColumns(); |
45 | |
d16ecfe2 |
46 | setHeaderItem (3, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH)); |
47 | setHeaderItem (4, TreeModel_HeaderSection ("SelectedOwners", -1)); |
6822a3be |
48 | } |
49 | |
50 | // ======================================================================= |
51 | // function : createRootItem |
52 | // purpose : |
53 | // ======================================================================= |
7e1c1e48 |
54 | TreeModel_ItemBasePtr VInspector_ViewModel::createRootItem (const int theColumnId) |
6822a3be |
55 | { |
7e1c1e48 |
56 | return VInspector_ItemContext::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId); |
14bbbdcb |
57 | } |
58 | |
59 | // ======================================================================= |
60 | // function : GetContext |
61 | // purpose : |
62 | // ======================================================================= |
6822a3be |
63 | Handle(AIS_InteractiveContext) VInspector_ViewModel::GetContext() const |
14bbbdcb |
64 | { |
6822a3be |
65 | return itemDynamicCast<VInspector_ItemContext> (RootItem (0))->GetContext(); |
14bbbdcb |
66 | } |
67 | |
68 | // ======================================================================= |
69 | // function : SetContext |
70 | // purpose : |
71 | // ======================================================================= |
72 | void VInspector_ViewModel::SetContext (const Handle(AIS_InteractiveContext)& theContext) |
73 | { |
74 | // fill root item by the application |
75 | for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++) |
76 | itemDynamicCast<VInspector_ItemContext>(myRootItems[aColId])->SetContext (theContext); |
7e1c1e48 |
77 | |
78 | UpdateTreeModel(); |
14bbbdcb |
79 | } |
80 | |
81 | // ======================================================================= |
82 | // function : FindPointers |
83 | // purpose : |
84 | // ======================================================================= |
7e1c1e48 |
85 | void VInspector_ViewModel::FindPointers (const QStringList& thePointers, |
86 | const QModelIndex& theParent, |
87 | QModelIndexList& theFoundIndices) |
14bbbdcb |
88 | { |
7e1c1e48 |
89 | (void)thePointers; |
90 | (void)theParent; |
91 | (void)theFoundIndices; |
92 | // should be used after Object of items is improved, as it takes a lot of time on BVH item |
93 | /* |
94 | if (thePointers.isEmpty()) |
95 | return; |
96 | |
97 | QModelIndex aParentIndex = theParent.isValid() ? theParent : index (0, 0); |
14bbbdcb |
98 | TreeModel_ItemBasePtr aParentItem = TreeModel_ModelBase::GetItemByIndex (aParentIndex); // context item |
99 | for (int aRowId = 0, aCount = aParentItem->rowCount(); aRowId < aCount; aRowId++) |
100 | { |
101 | QModelIndex anIndex = index (aRowId, 0, aParentIndex); |
102 | TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex); |
7e1c1e48 |
103 | VInspector_ItemBasePtr aVItem = itemDynamicCast<VInspector_ItemBase>(anItemBase); |
104 | if (!aVItem) |
14bbbdcb |
105 | continue; |
7e1c1e48 |
106 | const Handle(Standard_Transient)& anObject = aVItem->Object(); |
107 | TCollection_AsciiString aPointerInfo = Standard_Dump::GetPointerInfo (anObject); |
108 | if (thePointers.contains (aPointerInfo.ToCString())) |
109 | theFoundIndices.append (anIndex); |
110 | |
111 | FindPointers (thePointers, anIndex, theFoundIndices); |
112 | }*/ |
14bbbdcb |
113 | } |
114 | |
0cb512c0 |
115 | // ======================================================================= |
116 | // function : FindIndex |
117 | // purpose : |
118 | // ======================================================================= |
119 | QModelIndex VInspector_ViewModel::FindIndex (const Handle(AIS_InteractiveObject)& thePresentation) const |
120 | { |
121 | QModelIndex aParentIndex = index (0, 0); |
122 | TreeModel_ItemBasePtr aParentItem = TreeModel_ModelBase::GetItemByIndex (aParentIndex); // context item |
123 | for (int aRowId = 0, aCount = aParentItem->rowCount(); aRowId < aCount; aRowId++) |
124 | { |
125 | QModelIndex anIndex = index (aRowId, 0, aParentIndex); |
126 | TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex); |
127 | VInspector_ItemPresentableObjectPtr anItemPrs = itemDynamicCast<VInspector_ItemPresentableObject>(anItemBase); |
128 | if (!anItemPrs) |
129 | continue; |
130 | if (anItemPrs->GetInteractiveObject() == thePresentation) |
131 | return anIndex; |
132 | } |
133 | return QModelIndex(); |
134 | } |
135 | |
6822a3be |
136 | // ======================================================================= |
137 | // function : UpdateTreeModel |
138 | // purpose : |
139 | // ======================================================================= |
140 | void VInspector_ViewModel::UpdateTreeModel() |
141 | { |
142 | Reset(); |
143 | EmitLayoutChanged(); |
144 | } |