-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqjsontablemodel.h
35 lines (28 loc) · 1.09 KB
/
qjsontablemodel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef QJSONTABLEMODEL_H
#define QJSONTABLEMODEL_H
#include <QObject>
#include <QVector>
#include <QMap>
#include <QAbstractTableModel>
#include <QJsonDocument>
#include <QJsonArray>
class QJsonTableModel : public QAbstractTableModel
{
public:
enum class VerticalNums {NONE, BASEZERO, BASEONE};
typedef QMap<QString, QString> Heading;
typedef QVector<Heading> Header;
QJsonTableModel(const Header& header, QObject * parent = 0, VerticalNums nums = VerticalNums::NONE);
bool setJson( const QJsonDocument& json );
bool setJson( const QJsonArray& array );
virtual QJsonObject getJsonObject( const QModelIndex &index ) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
private:
const VerticalNums vhdr;
Header m_header;
QJsonArray m_json;
};
#endif // QJSONTABLEMODEL_H