Radium Engine  1.5.20
Loading...
Searching...
No Matches
TreeModel.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Gui/RaGui.hpp>
4
5#include <memory>
6#include <vector>
7
8#include <QAbstractItemModel>
9#include <QVariant>
10
21
22namespace Ra {
23namespace Gui {
24
30class RA_GUI_API TreeItem
31{
32 public:
33 TreeItem() {}
34 virtual ~TreeItem() {}
35
37 TreeItem( const TreeItem& ) = delete;
38 TreeItem& operator=( const TreeItem& ) = delete;
39
44 virtual std::string getName() const = 0;
45
47 virtual bool isValid() const = 0;
48
50 virtual bool isSelectable() const = 0;
52
55
58 int getIndexInParent() const;
59
60 bool isChecked() const { return m_checked; }
61 void setChecked( bool checked = true ) { m_checked = checked; }
63 public:
67 TreeItem* m_parent { nullptr };
68
72 private:
73 bool m_checked { true };
74};
75
78class RA_GUI_API TreeModel : public QAbstractItemModel
79{
80 Q_OBJECT
81
82 public:
83 TreeModel( QObject* parent = nullptr ) : QAbstractItemModel( parent ) {}
84
87
92 int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
93
99 int columnCount( const QModelIndex& parent = QModelIndex() ) const override {
100 CORE_UNUSED( parent );
101 return 1;
102 }
103
110 QVariant data( const QModelIndex& index, int role ) const override;
111
112 bool setData( const QModelIndex& index, const QVariant& value, int role ) override;
113
121 QVariant headerData( int section,
122 Qt::Orientation orientation,
123 int role = Qt::DisplayRole ) const override;
124
132 QModelIndex
133 index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override;
134
140 QModelIndex parent( const QModelIndex& child ) const override;
141
147 Qt::ItemFlags flags( const QModelIndex& index ) const override;
148
150
153 void rebuildModel();
154
155 signals:
158
159 protected:
160 virtual std::string getHeaderString() const = 0;
161
164 virtual void buildModel() = 0;
165
167 TreeItem* getItem( const QModelIndex& index ) const;
168
170 bool findInTree( const TreeItem* item ) const;
171
173 void printModel() const;
174
176 void setAllItemsChecked( bool checked = true );
177
179 void setItemChecked( const QModelIndex& index, bool checked = true );
180
181 protected:
184};
185} // namespace Gui
186} // namespace Ra
Base class for element of the tree representation.
Definition TreeModel.hpp:31
TreeItem(const TreeItem &)=delete
TreeItems are non-copyable.
std::vector< std::unique_ptr< TreeItem > > m_children
Children of item in the tree.
Definition TreeModel.hpp:70
virtual bool isValid() const =0
Return true if the represented object is valid.
virtual bool isSelectable() const =0
Return true if the represented object can be selected.
void modelRebuilt()
Emitted when the model has been rebuilt.
virtual void buildModel()=0
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition TreeModel.hpp:99
std::unique_ptr< TreeItem > m_rootItem
Root of the tree.
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3