OGS
TreeModel.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <QAbstractItemModel>
18
19class QVariant;
20class QModelIndex;
21class TreeItem;
22
29class TreeModel : public QAbstractItemModel
30{
31 Q_OBJECT
32
33public:
34 explicit TreeModel(QObject* parent = nullptr);
35 ~TreeModel() override;
36
37 QVariant data(const QModelIndex& index, int role) const override;
38 bool setData(const QModelIndex& index, const QVariant& value,
39 int role /* = Qt::EditRole */) override;
40 Qt::ItemFlags flags(const QModelIndex& index) const override;
41 TreeItem* getItem(const QModelIndex &index) const;
42 QVariant headerData(int section, Qt::Orientation orientation,
43 int role = Qt::DisplayRole) const override;
44 QModelIndex index(int row, int column,
45 const QModelIndex& parent = QModelIndex()) const override;
46 QModelIndex parent(const QModelIndex& index) const override;
47 bool removeRows(int position, int count,
48 const QModelIndex& parent) override;
49 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
50 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
51
52 TreeItem* rootItem() const;
53
54public slots:
55 void updateData();
56
57protected:
59
60private:
61 void setupModelData(const QStringList &lines, TreeItem* parent);
62};
Objects nodes for the TreeModel.
Definition TreeItem.h:28
A hierarchical model for a tree implemented as a double-linked list.
Definition TreeModel.h:30
~TreeModel() override
Definition TreeModel.cpp:37
void setupModelData(const QStringList &lines, TreeItem *parent)
bool removeRows(int position, int count, const QModelIndex &parent) override
TreeItem * getItem(const QModelIndex &index) const
void updateData()
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition TreeModel.cpp:50
QVariant data(const QModelIndex &index, int role) const override
QModelIndex parent(const QModelIndex &index) const override
Definition TreeModel.cpp:81
TreeItem * rootItem() const
TreeModel(QObject *parent=nullptr)
Definition TreeModel.cpp:26
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
TreeItem * _rootItem
Definition TreeModel.h:58
bool setData(const QModelIndex &index, const QVariant &value, int role) override