2017-04-27 18:25:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-05-28 21:02:06 +00:00
|
|
|
#ifndef TREEMODEL_H
|
|
|
|
#define TREEMODEL_H
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QCoreApplication>
|
2018-07-25 19:23:19 +00:00
|
|
|
#include <memory>
|
2015-05-28 21:02:06 +00:00
|
|
|
|
|
|
|
struct TreeItem {
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(TreeItemDT)
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~TreeItem();
|
|
|
|
TreeItem();
|
|
|
|
virtual QVariant data(int column, int role) const;
|
|
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
|
|
|
|
int row() const;
|
|
|
|
QList<TreeItem *> children;
|
|
|
|
TreeItem *parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class TreeModel : public QAbstractItemModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
TreeModel(QObject *parent = 0);
|
2018-08-01 09:01:26 +00:00
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
QModelIndex parent(const QModelIndex &child) const;
|
2018-07-25 19:23:19 +00:00
|
|
|
void clear();
|
2015-05-28 21:02:06 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int columns;
|
2018-07-25 19:23:19 +00:00
|
|
|
std::unique_ptr<TreeItem> rootItem;
|
2015-05-28 21:02:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|