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 #ifndef DFBrowser_TreeModel_H
17 #define DFBrowser_TreeModel_H
19 #include <inspector/DFBrowser_ItemBase.hxx>
20 #include <inspector/TreeModel_ModelBase.hxx>
22 #include <NCollection_List.hxx>
23 #include <Standard.hxx>
24 #include <TDF_Label.hxx>
25 #include <TDocStd_Application.hxx>
27 #include <Standard_WarningsDisable.hxx>
31 #include <Standard_WarningsRestore.hxx>
33 class DFBrowser_Module;
34 class DFBrowser_TreeModel;
36 //! \class DFBrowser_TreeModel
37 //! Tree model that has items described TDocStd_Application. The structure of items is the following:
38 //! - <DFBrowser_ItemApplication>: for TDocStd_Application
39 //! - <DFBrowser_ItemDocument>: for TDocStd_Document
40 //!- <DFBrowser_Item>: for either TDF_Label or TDF_Attribute
41 //! It is possible to visualize some items as highlighted.
42 class DFBrowser_TreeModel : public TreeModel_ModelBase
48 Standard_EXPORT DFBrowser_TreeModel (QObject* theParent, DFBrowser_Module* theModule);
51 virtual ~DFBrowser_TreeModel() Standard_OVERRIDE {};
53 //! Fills the root item by the application
54 Standard_EXPORT void Init (const Handle(TDocStd_Application)& theApplication);
56 //! Returns an OCAF application or NULL
57 //! \return an application instance
58 Standard_EXPORT Handle(TDocStd_Application) GetTDocStdApplication() const;
60 //! Returns true if the tree view model contains highlighted items. This highlight is set manually.
61 bool HasHighlighted() { return !myHighlightedIndices.isEmpty(); }
63 //! Sets items of the indices highlighted in the model.
64 //! \param theIndices a list of tree model indices
65 void SetHighlighted (const QModelIndexList& theIndices = QModelIndexList()) { myHighlightedIndices = theIndices; }
67 //! Returns tree model index of the label item. It creates container of the label fathers and
68 //! starting from the rools label it descends by the found labels till the parameter label.
69 //! \param theLabel an OCAF label
70 //! \return model index if the value is found or Null model index
71 Standard_EXPORT QModelIndex FindIndex (const TDF_Label& theLabel) const;
73 //! Returns tree model index by list of label entries and (possible) attribute name.
74 //! \param theLabelEntries a container of label entries starting from root till searched label
75 //! \param theValue a label entry or attribute name
76 //! \return model index if the value is found or Null model index
77 Standard_EXPORT QModelIndex FindIndexByPath (const QStringList& theLabelEntries, const QString& theValue) const;
79 //! Returns tree model index of the attribute item. It gets the attributes label, find index of the label
80 //! and after find under this item attribute child item.
81 //! \param theAttribute an OCAF attribute
82 //! \return model index if the value is found or Null model index
83 Standard_EXPORT QModelIndex FindIndexByAttribute (Handle(TDF_Attribute) theAttribute) const;
85 //! Returns tree model indices for the labels.
86 Standard_EXPORT void ConvertToIndices (const NCollection_List<TDF_Label>& theReferences, QModelIndexList& theIndices);
88 //! Returns tree model indices of references
89 Standard_EXPORT void ConvertToIndices (const NCollection_List<Handle(TDF_Attribute)>& theReferences,
90 QModelIndexList& theIndices);
92 //! Returns the data stored under the given role for the current item
93 //! \param theIndex the item model index
94 //! \param theRole the item model role
95 Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex,
96 int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
100 //! \param theColumnId index of a column
101 virtual void createRootItem (const int theColumnId);
105 QModelIndexList myHighlightedIndices; //!< tree model indices that should be visualized as highlighted