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_TreeLevelViewModel_H
17 #define DFBrowser_TreeLevelViewModel_H
19 #include <Standard.hxx>
20 #include <Standard_Macro.hxx>
22 #include <Standard_WarningsDisable.hxx>
23 #include <QAbstractTableModel>
25 #include <Standard_WarningsRestore.hxx>
29 //! \class DFBrowser_TreeLevelViewModel
30 //! Tree Model of one level of OCAF tree view model. It is initialized by tree view index and
31 //! contains children and attributes of this label.
32 class DFBrowser_TreeLevelViewModel : public QAbstractTableModel
37 DFBrowser_TreeLevelViewModel (QObject* theParent) : QAbstractTableModel (theParent), myRowCount (0) {}
40 virtual ~DFBrowser_TreeLevelViewModel() Standard_OVERRIDE {}
42 //! Reset OCAF tree model index
43 void Reset() { myIndex = QModelIndex(); }
45 //! Fills OCAF tree model index
46 //! \param theTreeIndex an index
47 Standard_EXPORT void Init (const QModelIndex& theTreeIndex);
49 //! Returns true if the index is filled
50 bool IsInitialized() const { return myIndex.isValid(); }
52 //! Return OCAF tree view model index on level defined by column of the parameter index
53 //! \param theIndex a tree level view model index
54 //! \return model index
55 Standard_EXPORT QModelIndex GetTreeViewIndex (const QModelIndex& theIndex) const;
57 //! Emits the layoutChanged signal from outside of this class
58 void EmitLayoutChanged() { emit layoutChanged(); }
60 //! It returns value only for DisplayRole for column = 1
61 //! \param theSection an index of value in the container
62 //! \param theIndex a model index
63 //! \param theRole a view role
64 //! \return value intepreted depending on the given role
65 Standard_EXPORT virtual QVariant headerData (int theSection, Qt::Orientation theOrientation,
66 int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
68 //! Creates new model index
69 //! \param theRow the index row position
70 //! \param theColummn the index column position
71 //! \param theParent the parent index
72 //! \return the model index
73 Standard_EXPORT virtual QModelIndex index (int theRow, int theColumn,
74 const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE;
76 //! Returns item information(short) for display role.
77 //! \param theIndex a model index
78 //! \param theRole a view role
79 //! \return value intepreted depending on the given role
80 Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex,
81 int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
83 //! Returns Enabled and Selectable item for any index
84 //! \param theIndex a model index
86 Standard_EXPORT virtual Qt::ItemFlags flags (const QModelIndex& theIndex) const Standard_OVERRIDE;
88 //! Returns number of rows
89 virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
90 { (void)theParent; return myRowCount; }
93 virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
94 { (void)theParent; return 2; }
98 QModelIndex myIndex; //!< OCAF tree view model index
99 int myRowCount; //!< number of rows of item of treeview model index