Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
ObjectHierarchyModel.h
Go to the documentation of this file.
1#pragma once
2
4#include <QAbstractItemModel>
5#include <QIcon>
6
7namespace sf
8{
9
13class ObjectHierarchyModel :public QAbstractItemModel
14{
15 public:
19 explicit ObjectHierarchyModel(bool multi, QObject* parent);
20
25
29 [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
30
34 [[nodiscard]] int columnCount(const QModelIndex& parent) const override;
35
39 [[nodiscard]] int rowCount(const QModelIndex& parent) const override;
40
44 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
45
49 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex& index) const override;
50
54 [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex& parent) const override;
55
59 [[nodiscard]] QModelIndex parent(const QModelIndex& child) const override;
60
64 void toggleSelection(const QModelIndex& index);
65
71 [[nodiscard]] QObject* getObject(QModelIndex index) const;
72
76 void updateList(QObject* root);
77
85 bool insertItemAt(const QModelIndex& parent, QObject* obj);
86
90 void removeItem(const QModelIndex& index);
91
95 bool isRoot(QModelIndex index) const;
96
100 QModelIndex getObjectIndex(QObject* obj);
101
102 private:
103
107 struct TreeItem
108 {
109
113 explicit TreeItem(ObjectHierarchyModel* owner, TreeItem* parent, QObject* obj);
114
118 ~TreeItem();
119
124 int getRow();
125
129 bool _selected{false};
130
134 ObjectHierarchyModel* _owner{nullptr};
138 QObject* _object{nullptr};
142 TreeItem* _parentItem{nullptr};
146 QList<TreeItem*> _childItems;
147 };
148
155 void addChild(QObject* obj, TreeItem* parent);
156
160 bool _multi;
164 TreeItem* _rootItem;
168 QList<TreeItem*> _items;
172 QList<TreeItem*> _selected;
173
174 QIcon _iconForm;
175 QIcon _iconContainer;
176 QIcon _iconWidget;
177
178};
179
180}
Item model for viewing Variables in a tree view.
Definition ObjectHierarchyModel.h:14
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Overridden from base class to provide column display names.
~ObjectHierarchyModel() override
Overridden destructor.
ObjectHierarchyModel(bool multi, QObject *parent)
Constructor.
QVariant data(const QModelIndex &index, int role) const override
Overridden from base class to provide the data to present.
int rowCount(const QModelIndex &parent) const override
Overridden from base class to provide the amount of rows.
QModelIndex index(int row, int column, const QModelIndex &parent) const override
Overridden from base class.
Qt::ItemFlags flags(const QModelIndex &index) const override
Overridden from base class to provide flags on an item by index.
void removeItem(const QModelIndex &index)
removes item at passed index.
bool isRoot(QModelIndex index) const
Determines if this is the root item.
void updateList(QObject *root)
Updates the list data using the passed object as root.
void toggleSelection(const QModelIndex &index)
Toggle the selection of the item at the passed index.
bool insertItemAt(const QModelIndex &parent, QObject *obj)
Inserts an object at the index.
int columnCount(const QModelIndex &parent) const override
Overridden from base class to provide the amount of columns.
QObject * getObject(QModelIndex index) const
Gets the current item from the tree.
QModelIndex getObjectIndex(QObject *obj)
Gets the model-index from the passed object.
QModelIndex parent(const QModelIndex &child) const override
Overridden from base class.
Definition Application.h:10