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 | |
16 | #ifndef DFBrowser_TreeModel_H |
17 | #define DFBrowser_TreeModel_H |
18 | |
0cb512c0 |
19 | #include <inspector/DFBrowser_ItemBase.hxx> |
20 | #include <inspector/TreeModel_ModelBase.hxx> |
21 | |
14bbbdcb |
22 | #include <NCollection_List.hxx> |
23 | #include <Standard.hxx> |
24 | #include <TDF_Label.hxx> |
25 | #include <TDocStd_Application.hxx> |
14bbbdcb |
26 | |
130eb114 |
27 | #include <Standard_WarningsDisable.hxx> |
14bbbdcb |
28 | #include <QByteArray> |
29 | #include <QHash> |
30 | #include <QObject> |
130eb114 |
31 | #include <Standard_WarningsRestore.hxx> |
14bbbdcb |
32 | |
33 | class DFBrowser_Module; |
34 | class DFBrowser_TreeModel; |
35 | |
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 |
43 | { |
44 | Q_OBJECT |
45 | public: |
46 | |
47 | //! Constructor |
7e1c1e48 |
48 | Standard_EXPORT DFBrowser_TreeModel (QObject* theParent); |
14bbbdcb |
49 | |
50 | //! Destructor |
7e1c1e48 |
51 | virtual ~DFBrowser_TreeModel() {} |
52 | |
53 | //! Creates model columns and root items. |
54 | Standard_EXPORT virtual void InitColumns() Standard_OVERRIDE; |
14bbbdcb |
55 | |
56 | //! Fills the root item by the application |
57 | Standard_EXPORT void Init (const Handle(TDocStd_Application)& theApplication); |
58 | |
7e1c1e48 |
59 | //! Fills root item by the module |
60 | Standard_EXPORT void SetModule (DFBrowser_Module* theModule); |
61 | |
14bbbdcb |
62 | //! Returns an OCAF application or NULL |
63 | //! \return an application instance |
64 | Standard_EXPORT Handle(TDocStd_Application) GetTDocStdApplication() const; |
65 | |
66 | //! Returns true if the tree view model contains highlighted items. This highlight is set manually. |
67 | bool HasHighlighted() { return !myHighlightedIndices.isEmpty(); } |
68 | |
69 | //! Sets items of the indices highlighted in the model. |
70 | //! \param theIndices a list of tree model indices |
71 | void SetHighlighted (const QModelIndexList& theIndices = QModelIndexList()) { myHighlightedIndices = theIndices; } |
72 | |
73 | //! Returns tree model index of the label item. It creates container of the label fathers and |
74 | //! starting from the rools label it descends by the found labels till the parameter label. |
75 | //! \param theLabel an OCAF label |
76 | //! \return model index if the value is found or Null model index |
77 | Standard_EXPORT QModelIndex FindIndex (const TDF_Label& theLabel) const; |
78 | |
79 | //! Returns tree model index by list of label entries and (possible) attribute name. |
80 | //! \param theLabelEntries a container of label entries starting from root till searched label |
81 | //! \param theValue a label entry or attribute name |
82 | //! \return model index if the value is found or Null model index |
83 | Standard_EXPORT QModelIndex FindIndexByPath (const QStringList& theLabelEntries, const QString& theValue) const; |
84 | |
85 | //! Returns tree model index of the attribute item. It gets the attributes label, find index of the label |
86 | //! and after find under this item attribute child item. |
87 | //! \param theAttribute an OCAF attribute |
88 | //! \return model index if the value is found or Null model index |
89 | Standard_EXPORT QModelIndex FindIndexByAttribute (Handle(TDF_Attribute) theAttribute) const; |
90 | |
91 | //! Returns tree model indices for the labels. |
92 | Standard_EXPORT void ConvertToIndices (const NCollection_List<TDF_Label>& theReferences, QModelIndexList& theIndices); |
93 | |
94 | //! Returns tree model indices of references |
95 | Standard_EXPORT void ConvertToIndices (const NCollection_List<Handle(TDF_Attribute)>& theReferences, |
96 | QModelIndexList& theIndices); |
97 | |
98 | //! Returns the data stored under the given role for the current item |
99 | //! \param theIndex the item model index |
100 | //! \param theRole the item model role |
101 | Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex, |
102 | int theRole = Qt::DisplayRole) const Standard_OVERRIDE; |
103 | |
6822a3be |
104 | protected: |
105 | //! Creates root item |
106 | //! \param theColumnId index of a column |
7e1c1e48 |
107 | Standard_EXPORT virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE; |
14bbbdcb |
108 | |
109 | private: |
110 | |
111 | QModelIndexList myHighlightedIndices; //!< tree model indices that should be visualized as highlighted |
112 | }; |
113 | |
114 | #endif |