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_TreeLevelLineModel_H |
17 | #define DFBrowser_TreeLevelLineModel_H |
18 | |
0cb512c0 |
19 | #include <inspector/TreeModel_ItemBase.hxx> |
20 | |
14bbbdcb |
21 | #include <Standard.hxx> |
14bbbdcb |
22 | |
130eb114 |
23 | #include <Standard_WarningsDisable.hxx> |
14bbbdcb |
24 | #include <QAbstractTableModel> |
25 | #include <QObject> |
26 | #include <QList> |
130eb114 |
27 | #include <Standard_WarningsRestore.hxx> |
14bbbdcb |
28 | |
29 | //! \class DFBrowser_TreeLevelLineModel |
30 | //! Tree Model of tree line items. It is initialized by OCAF tree model index. Each element of the current model |
31 | //! is an item of hierarchy of OCAF tree model index. So, on each level a label is presented, the last element may be |
32 | //! an attribute. Information, presented for the item has no additional information (not as in OCAF tree model) |
33 | class DFBrowser_TreeLevelLineModel : public QAbstractTableModel |
34 | { |
35 | public: |
36 | |
37 | //! Constructor |
38 | DFBrowser_TreeLevelLineModel (QObject* theParent = 0) : QAbstractTableModel (theParent) {} |
39 | |
40 | //! Destructor |
41 | virtual ~DFBrowser_TreeLevelLineModel() {} |
42 | |
7e1c1e48 |
43 | //! Resets the cached values |
14bbbdcb |
44 | void Reset() { myLevelItems.clear(); } |
45 | |
46 | //! Inits the model by the index |
47 | //! \param theTreeIndex an OCAF tree model index |
48 | Standard_EXPORT void Init (const QModelIndex& theTreeIndex); |
49 | |
50 | //! Returns true if the tree model index is filled |
51 | bool IsInitialized() const { return myTreeIndex.isValid(); } |
52 | |
7e1c1e48 |
53 | //! Returns OCAF tree view model index on level defined by column of the parameter index |
14bbbdcb |
54 | //! \param theIndex a tree level view model index |
55 | //! \return model index |
56 | const QModelIndex& GetTreeViewIndex (const QModelIndex& theIndex) const |
57 | { return myLevelItems[theIndex.column()]; } |
58 | |
59 | //! Returns item information(short) for display role. |
60 | //! \param theIndex a model index |
61 | //! \param theRole a view role |
a110c4a3 |
62 | //! \return value interpreted depending on the given role |
14bbbdcb |
63 | Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex, |
64 | int theRole = Qt::DisplayRole) const Standard_OVERRIDE; |
65 | |
66 | //! Returns the header data for the given role and section in the header with the specified orientation. |
67 | //! \param theSection the header section. For horizontal headers - column number, for vertical headers - row number. |
68 | //! \param theOrientation a header orientation |
69 | //! \param theRole a data role |
70 | //! \return the header data |
71 | Standard_EXPORT virtual QVariant headerData (int theSection, Qt::Orientation theOrientation, |
72 | int theRole = Qt::DisplayRole) const Standard_OVERRIDE; |
73 | |
a110c4a3 |
74 | //! Returns number of tree level line items = columns in table view |
14bbbdcb |
75 | virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE |
76 | { (void)theParent; return myLevelItems.size(); } |
77 | |
a110c4a3 |
78 | //! Returns only one row in table view |
14bbbdcb |
79 | virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE |
80 | { (void)theParent; return 1; } |
81 | |
82 | private: |
83 | |
84 | QModelIndex myTreeIndex; //!< the current OCAF tree view model index |
7e1c1e48 |
85 | QList<QModelIndex> myLevelItems; //!< cached parent indices of myTreeIndex for quick access to item information |
14bbbdcb |
86 | }; |
87 | |
88 | #endif |