2017-09-19 14:27:39 +02:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0+
|
|
|
|
* License-Filename: LICENSES/GPLv3+-QJsonModel
|
|
|
|
*/
|
|
|
|
|
2015-03-04 20:22:58 +01:00
|
|
|
#ifndef QJSONMODEL_H
|
|
|
|
#define QJSONMODEL_H
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include "qjsonitem.h"
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QIcon>
|
|
|
|
class QJsonModel : public QAbstractItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-04-11 13:15:10 +02:00
|
|
|
explicit QJsonModel(QObject *parent = nullptr);
|
2017-10-30 13:43:09 +01:00
|
|
|
~QJsonModel();
|
2015-03-04 20:22:58 +01:00
|
|
|
bool load(const QString& fileName);
|
|
|
|
bool load(QIODevice * device);
|
|
|
|
bool loadJson(const QByteArray& json);
|
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|
|
|
QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
QModelIndex parent(const QModelIndex &index) const;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
void setIcon(const QJsonValue::Type& type, const QIcon& icon);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
QJsonTreeItem * mRootItem;
|
|
|
|
QJsonDocument mDocument;
|
|
|
|
QStringList mHeaders;
|
|
|
|
QHash<QJsonValue::Type, QIcon> mTypeIcons;
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // QJSONMODEL_H
|