| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
|---|---|
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #ifndef TREEMODEL_H |
| 6 | #define TREEMODEL_H |
| 7 | |
| 8 | #include "debug.h" |
| 9 | #include "variable.h" |
| 10 | |
| 11 | #include <QAbstractItemModel> |
| 12 | #include <QModelIndex> |
| 13 | #include <QVariant> |
| 14 | |
| 15 | class LocalTreeItem; |
| 16 | class LocalTreeModel : public QAbstractItemModel |
| 17 | { |
| 18 | Q_OBJECT |
| 19 | |
| 20 | public: |
| 21 | explicit LocalTreeModel(QObject *parent = nullptr); |
| 22 | ~LocalTreeModel() override; |
| 23 | |
| 24 | void setHeaders(const QList<QString> &headers); |
| 25 | QVariant data(const QModelIndex &index, int role) const override; |
| 26 | Qt::ItemFlags flags(const QModelIndex &index) const override; |
| 27 | QVariant headerData(int section, Qt::Orientation orientation, |
| 28 | int role = Qt::DisplayRole) const override; |
| 29 | QModelIndex index(int row, int column, |
| 30 | const QModelIndex &parent = QModelIndex()) const override; |
| 31 | QModelIndex parent(const QModelIndex &index) const override; |
| 32 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 33 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
| 34 | |
| 35 | // Custumize functions. |
| 36 | void setDatas(IVariables &datas); |
| 37 | void clear(); |
| 38 | |
| 39 | QModelIndex indexForItem(const LocalTreeItem *needle) const; |
| 40 | |
| 41 | private: |
| 42 | void appendItem(LocalTreeItem* parent, IVariables &vars); |
| 43 | |
| 44 | LocalTreeItem *rootItem = nullptr; |
| 45 | QList<LocalTreeItem *> items; |
| 46 | QStringList headers; |
| 47 | }; |
| 48 | |
| 49 | #endif // TREEMODEL_H |
| 50 |