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