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 | |
27 | #include <QByteArray> |
28 | #include <QHash> |
29 | #include <QObject> |
30 | |
31 | class DFBrowser_Module; |
32 | class DFBrowser_TreeModel; |
33 | |
34 | //! \class DFBrowser_TreeModel |
35 | //! Tree model that has items described TDocStd_Application. The structure of items is the following: |
36 | //! - <DFBrowser_ItemApplication>: for TDocStd_Application |
37 | //! - <DFBrowser_ItemDocument>: for TDocStd_Document |
38 | //!- <DFBrowser_Item>: for either TDF_Label or TDF_Attribute |
39 | //! It is possible to visualize some items as highlighted. |
40 | class DFBrowser_TreeModel : public TreeModel_ModelBase |
41 | { |
42 | Q_OBJECT |
43 | public: |
44 | |
45 | //! Constructor |
46 | Standard_EXPORT DFBrowser_TreeModel (QObject* theParent, DFBrowser_Module* theModule); |
47 | |
48 | //! Destructor |
49 | virtual ~DFBrowser_TreeModel() Standard_OVERRIDE {}; |
50 | |
51 | //! Fills the root item by the application |
52 | Standard_EXPORT void Init (const Handle(TDocStd_Application)& theApplication); |
53 | |
54 | //! Returns an OCAF application or NULL |
55 | //! \return an application instance |
56 | Standard_EXPORT Handle(TDocStd_Application) GetTDocStdApplication() const; |
57 | |
58 | //! Returns true if the tree view model contains highlighted items. This highlight is set manually. |
59 | bool HasHighlighted() { return !myHighlightedIndices.isEmpty(); } |
60 | |
61 | //! Sets items of the indices highlighted in the model. |
62 | //! \param theIndices a list of tree model indices |
63 | void SetHighlighted (const QModelIndexList& theIndices = QModelIndexList()) { myHighlightedIndices = theIndices; } |
64 | |
65 | //! Returns tree model index of the label item. It creates container of the label fathers and |
66 | //! starting from the rools label it descends by the found labels till the parameter label. |
67 | //! \param theLabel an OCAF label |
68 | //! \return model index if the value is found or Null model index |
69 | Standard_EXPORT QModelIndex FindIndex (const TDF_Label& theLabel) const; |
70 | |
71 | //! Returns tree model index by list of label entries and (possible) attribute name. |
72 | //! \param theLabelEntries a container of label entries starting from root till searched label |
73 | //! \param theValue a label entry or attribute name |
74 | //! \return model index if the value is found or Null model index |
75 | Standard_EXPORT QModelIndex FindIndexByPath (const QStringList& theLabelEntries, const QString& theValue) const; |
76 | |
77 | //! Returns tree model index of the attribute item. It gets the attributes label, find index of the label |
78 | //! and after find under this item attribute child item. |
79 | //! \param theAttribute an OCAF attribute |
80 | //! \return model index if the value is found or Null model index |
81 | Standard_EXPORT QModelIndex FindIndexByAttribute (Handle(TDF_Attribute) theAttribute) const; |
82 | |
83 | //! Returns tree model indices for the labels. |
84 | Standard_EXPORT void ConvertToIndices (const NCollection_List<TDF_Label>& theReferences, QModelIndexList& theIndices); |
85 | |
86 | //! Returns tree model indices of references |
87 | Standard_EXPORT void ConvertToIndices (const NCollection_List<Handle(TDF_Attribute)>& theReferences, |
88 | QModelIndexList& theIndices); |
89 | |
90 | //! Returns the data stored under the given role for the current item |
91 | //! \param theIndex the item model index |
92 | //! \param theRole the item model role |
93 | Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex, |
94 | int theRole = Qt::DisplayRole) const Standard_OVERRIDE; |
95 | |
96 | //! Returns count of columns in the model |
97 | //! \param theParent an index of the parent item |
98 | //! \return integer value |
99 | virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE |
100 | { (void)theParent; return 1; } |
101 | |
102 | private: |
103 | |
104 | QModelIndexList myHighlightedIndices; //!< tree model indices that should be visualized as highlighted |
105 | }; |
106 | |
107 | #endif |