2019-11-10 00:12:44 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* gta5view Grand Theft Auto V Profile Viewer
|
|
|
|
* Copyright (C) 2016 Syping
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QJSON_DOCUMENT_H_
|
|
|
|
#define QJSON_DOCUMENT_H_
|
|
|
|
|
|
|
|
#include <QtCore/QtGlobal>
|
|
|
|
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
#include <QtCore/QJsonDocument>
|
|
|
|
#else
|
|
|
|
|
|
|
|
class QVariant;
|
|
|
|
class QByteArray;
|
|
|
|
class QTextStream;
|
|
|
|
class QJsonObject;
|
|
|
|
class QJsonValue;
|
|
|
|
class QJsonArray;
|
|
|
|
class QJsonParseError;
|
|
|
|
class QJsonRoot;
|
|
|
|
|
|
|
|
class QJsonDocument {
|
|
|
|
public:
|
2020-08-25 20:47:50 +02:00
|
|
|
enum DataValidation {
|
|
|
|
Validate = 0,
|
|
|
|
BypassValidation = 1
|
|
|
|
};
|
2019-11-10 00:12:44 +01:00
|
|
|
|
2020-08-25 20:47:50 +02:00
|
|
|
enum JsonFormat {
|
|
|
|
Indented,
|
|
|
|
Compact
|
|
|
|
};
|
2019-11-10 00:12:44 +01:00
|
|
|
|
|
|
|
public:
|
2020-08-25 20:47:50 +02:00
|
|
|
QJsonDocument();
|
|
|
|
QJsonDocument(const QJsonObject &object);
|
|
|
|
QJsonDocument(const QJsonArray &array);
|
|
|
|
QJsonDocument(const QJsonDocument &other);
|
|
|
|
~QJsonDocument();
|
2019-11-10 00:12:44 +01:00
|
|
|
|
|
|
|
public:
|
2020-08-25 20:47:50 +02:00
|
|
|
QJsonDocument &operator=(const QJsonDocument &other);
|
2019-11-10 00:12:44 +01:00
|
|
|
|
|
|
|
public:
|
2020-08-25 20:47:50 +02:00
|
|
|
bool operator!=(const QJsonDocument &other) const;
|
|
|
|
bool operator==(const QJsonDocument &other) const;
|
2019-11-10 00:12:44 +01:00
|
|
|
|
|
|
|
public:
|
2020-08-25 20:47:50 +02:00
|
|
|
bool isArray() const;
|
|
|
|
bool isEmpty() const;
|
|
|
|
bool isNull() const;
|
|
|
|
bool isObject() const;
|
2019-11-10 00:12:44 +01:00
|
|
|
|
|
|
|
public:
|
2020-08-25 20:47:50 +02:00
|
|
|
QByteArray toBinaryData() const;
|
|
|
|
QByteArray toJson(JsonFormat format = Indented) const;
|
|
|
|
QVariant toVariant() const;
|
2019-11-10 00:12:44 +01:00
|
|
|
|
|
|
|
public:
|
2020-08-25 20:47:50 +02:00
|
|
|
QJsonArray array() const;
|
|
|
|
QJsonObject object() const;
|
|
|
|
const char *rawData(int *size) const;
|
2019-11-10 00:12:44 +01:00
|
|
|
|
|
|
|
public:
|
2020-08-25 20:47:50 +02:00
|
|
|
void setArray(const QJsonArray &array);
|
|
|
|
void setObject(const QJsonObject &object);
|
2019-11-10 00:12:44 +01:00
|
|
|
|
|
|
|
public:
|
2020-08-25 20:47:50 +02:00
|
|
|
static QJsonDocument fromBinaryData(const QByteArray &data, DataValidation validation = Validate);
|
|
|
|
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = 0);
|
|
|
|
static QJsonDocument fromRawData(const char *data, int size, DataValidation validation = Validate);
|
|
|
|
static QJsonDocument fromVariant(const QVariant &variant);
|
2019-11-10 00:12:44 +01:00
|
|
|
|
|
|
|
private:
|
2020-08-25 20:47:50 +02:00
|
|
|
void setRoot(const QJsonRoot &root);
|
|
|
|
QString toJson(const QJsonValue &v, JsonFormat format, int indent = 1) const;
|
|
|
|
QString escapeString(const QString &s) const;
|
2019-11-10 00:12:44 +01:00
|
|
|
|
|
|
|
private:
|
2020-08-25 20:47:50 +02:00
|
|
|
void swap(QJsonDocument &other);
|
2019-11-10 00:12:44 +01:00
|
|
|
|
|
|
|
private:
|
2020-08-25 20:47:50 +02:00
|
|
|
QJsonRoot *root_;
|
2019-11-10 00:12:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|