2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#ifndef TREEMODEL_H
|
|
|
|
#define TREEMODEL_H
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QModelIndex>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
class TreeItem;
|
|
|
|
|
|
|
|
//! [0]
|
|
|
|
class TreeModel : public QAbstractItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-11-23 19:05:42 +00:00
|
|
|
explicit TreeModel(const QString &data, QObject *parent = nullptr);
|
2011-04-27 10:05:43 +00:00
|
|
|
~TreeModel();
|
|
|
|
|
2016-06-15 08:12:35 +00:00
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
2011-04-27 10:05:43 +00:00
|
|
|
QVariant headerData(int section, Qt::Orientation orientation,
|
2016-06-15 08:12:35 +00:00
|
|
|
int role = Qt::DisplayRole) const override;
|
2011-04-27 10:05:43 +00:00
|
|
|
QModelIndex index(int row, int column,
|
2016-06-15 08:12:35 +00:00
|
|
|
const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QModelIndex parent(const QModelIndex &index) const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setupModelData(const QStringList &lines, TreeItem *parent);
|
|
|
|
|
2023-05-26 14:51:49 +00:00
|
|
|
std::unique_ptr<TreeItem> rootItem;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
//! [0]
|
|
|
|
|
2012-11-22 12:40:51 +00:00
|
|
|
#endif // TREEMODEL_H
|