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/ShapeView_TreeModel.hxx> |
17 | #include <inspector/ShapeView_ItemRoot.hxx> |
18 | #include <inspector/ShapeView_TreeModel.hxx> |
19 | #include <inspector/ShapeView_ItemRoot.hxx> |
20 | #include <inspector/ShapeView_ItemShape.hxx> |
14bbbdcb |
21 | |
22 | // ======================================================================= |
23 | // function : Constructor |
24 | // purpose : |
25 | // ======================================================================= |
26 | ShapeView_TreeModel::ShapeView_TreeModel (QObject* theParent) |
27 | : TreeModel_ModelBase (theParent) |
28 | { |
29 | for (int aColumnId = 0, aNbColumns = columnCount(); aColumnId < aNbColumns; aColumnId++) |
30 | myRootItems.insert(aColumnId, ShapeView_ItemRoot::CreateItem(TreeModel_ItemBasePtr(), 0, aColumnId)); |
31 | |
32 | m_pRootItem = myRootItems[0]; |
33 | } |
34 | |
35 | // ======================================================================= |
36 | // function : AddShape |
37 | // purpose : |
38 | // ======================================================================= |
39 | void ShapeView_TreeModel::AddShape(const TopoDS_Shape& theShape) |
40 | { |
41 | for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++) |
42 | { |
43 | ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot>(RootItem (aColId)); |
44 | aRootItem->AddShape(theShape); |
45 | } |
46 | |
47 | Reset(); |
48 | EmitLayoutChanged(); |
49 | } |
50 | |
51 | // ======================================================================= |
52 | // function : RemoveAllShapes |
53 | // purpose : |
54 | // ======================================================================= |
55 | void ShapeView_TreeModel::RemoveAllShapes() |
56 | { |
57 | for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++) |
58 | { |
59 | ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot>(RootItem (aColId)); |
60 | aRootItem->RemoveAllShapes(); |
61 | } |
62 | Reset(); |
63 | EmitLayoutChanged(); |
64 | } |
65 | |
66 | // ======================================================================= |
67 | // function : headerData |
68 | // purpose : |
69 | // ======================================================================= |
70 | QVariant ShapeView_TreeModel::headerData (int theSection, Qt::Orientation theOrientation, int theRole) const |
71 | { |
72 | if (theOrientation != Qt::Horizontal || theRole != Qt::DisplayRole) |
73 | return QVariant(); |
74 | { |
75 | switch (theSection) |
76 | { |
77 | case 0: return "Name"; |
78 | case 1: return "Size"; |
79 | case 2: return "Pointer"; |
80 | case 3: return "Orientation"; |
81 | case 4: return "Location"; |
82 | case 5: return "Flags"; // Checked/Closed/Infinite/Locked/Modified/Orientable |
83 | case 7: return "Other"; |
84 | //Auto Triangulation |
85 | default: break; |
86 | } |
87 | } |
88 | return QVariant(); |
89 | } |
0cb512c0 |
90 | |
91 | // ======================================================================= |
92 | // function : FindIndex |
93 | // purpose : |
94 | // ======================================================================= |
95 | QModelIndex ShapeView_TreeModel::FindIndex (const TopoDS_Shape& theShape) const |
96 | { |
97 | QModelIndex aParentIndex = index (0, 0); |
98 | TreeModel_ItemBasePtr aParentItem = TreeModel_ModelBase::GetItemByIndex (aParentIndex); // application item |
99 | for (int aChildId = 0, aCount = aParentItem->rowCount(); aChildId < aCount; aChildId++) |
100 | { |
101 | QModelIndex anIndex = index (aChildId, 0, aParentIndex); |
102 | ShapeView_ItemShapePtr anItem = itemDynamicCast<ShapeView_ItemShape> (TreeModel_ModelBase::GetItemByIndex (anIndex)); |
103 | if (anItem && anItem->GetItemShape() == theShape) |
104 | return anIndex; |
105 | } |
106 | return QModelIndex(); |
107 | } |
108 | |
109 | // ======================================================================= |
110 | // function : SingleSelected |
111 | // purpose : |
112 | // ======================================================================= |
113 | QModelIndex ShapeView_TreeModel::SingleSelected (const QModelIndexList& theIndices, const int theCellId, |
114 | const Qt::Orientation theOrientation) |
115 | { |
116 | QModelIndexList aFirstColumnSelectedIndices; |
117 | for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin(); anIndicesIt != theIndices.end(); anIndicesIt++) |
118 | { |
119 | QModelIndex anIndex = *anIndicesIt; |
120 | if ((theOrientation == Qt::Horizontal && anIndex.column() == theCellId) || |
121 | (theOrientation == Qt::Vertical && anIndex.row() == theCellId)) |
122 | aFirstColumnSelectedIndices.append (anIndex); |
123 | } |
124 | return aFirstColumnSelectedIndices.size() == 1 ? aFirstColumnSelectedIndices.first() : QModelIndex(); |
125 | } |