OGS
TreeModel.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <QAbstractItemModel>
18 
19 class QVariant;
20 class QModelIndex;
21 class TreeItem;
22 
29 class TreeModel : public QAbstractItemModel
30 {
31  Q_OBJECT
32 
33 public:
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 
54 public slots:
55  void updateData();
56 
57 protected:
59 
60 private:
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)
Definition: TreeModel.cpp:230
bool removeRows(int position, int count, const QModelIndex &parent) override
Definition: TreeModel.cpp:215
TreeItem * getItem(const QModelIndex &index) const
Definition: TreeModel.cpp:188
void updateData()
Definition: TreeModel.cpp:137
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: TreeModel.cpp:104
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
Definition: TreeModel.cpp:142
QModelIndex parent(const QModelIndex &index) const override
Definition: TreeModel.cpp:81
TreeItem * rootItem() const
Definition: TreeModel.cpp:294
TreeModel(QObject *parent=nullptr)
Definition: TreeModel.cpp:26
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: TreeModel.cpp:127
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: TreeModel.cpp:201
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: TreeModel.cpp:175
TreeItem * _rootItem
Definition: TreeModel.h:58
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Definition: TreeModel.cpp:159