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/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>
22 // =======================================================================
23 // function : Constructor
25 // =======================================================================
26 ShapeView_TreeModel::ShapeView_TreeModel (QObject* theParent)
27 : TreeModel_ModelBase (theParent)
29 for (int aColumnId = 0, aNbColumns = columnCount(); aColumnId < aNbColumns; aColumnId++)
30 myRootItems.insert(aColumnId, ShapeView_ItemRoot::CreateItem(TreeModel_ItemBasePtr(), 0, aColumnId));
32 m_pRootItem = myRootItems[0];
35 // =======================================================================
36 // function : AddShape
38 // =======================================================================
39 void ShapeView_TreeModel::AddShape(const TopoDS_Shape& theShape)
41 for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
43 ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot>(RootItem (aColId));
44 aRootItem->AddShape(theShape);
51 // =======================================================================
52 // function : RemoveAllShapes
54 // =======================================================================
55 void ShapeView_TreeModel::RemoveAllShapes()
57 for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
59 ShapeView_ItemRootPtr aRootItem = itemDynamicCast<ShapeView_ItemRoot>(RootItem (aColId));
60 aRootItem->RemoveAllShapes();
66 // =======================================================================
67 // function : headerData
69 // =======================================================================
70 QVariant ShapeView_TreeModel::headerData (int theSection, Qt::Orientation theOrientation, int theRole) const
72 if (theOrientation != Qt::Horizontal || theRole != Qt::DisplayRole)
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";
91 // =======================================================================
92 // function : FindIndex
94 // =======================================================================
95 QModelIndex ShapeView_TreeModel::FindIndex (const TopoDS_Shape& theShape) const
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++)
101 QModelIndex anIndex = index (aChildId, 0, aParentIndex);
102 ShapeView_ItemShapePtr anItem = itemDynamicCast<ShapeView_ItemShape> (TreeModel_ModelBase::GetItemByIndex (anIndex));
103 if (anItem && anItem->GetItemShape() == theShape)
106 return QModelIndex();
109 // =======================================================================
110 // function : SingleSelected
112 // =======================================================================
113 QModelIndex ShapeView_TreeModel::SingleSelected (const QModelIndexList& theIndices, const int theCellId,
114 const Qt::Orientation theOrientation)
116 QModelIndexList aFirstColumnSelectedIndices;
117 for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin(); anIndicesIt != theIndices.end(); anIndicesIt++)
119 QModelIndex anIndex = *anIndicesIt;
120 if ((theOrientation == Qt::Horizontal && anIndex.column() == theCellId) ||
121 (theOrientation == Qt::Vertical && anIndex.row() == theCellId))
122 aFirstColumnSelectedIndices.append (anIndex);
124 return aFirstColumnSelectedIndices.size() == 1 ? aFirstColumnSelectedIndices.first() : QModelIndex();