2017-10-09 08:35:48 +02:00
|
|
|
/*****************************************************************************
|
2018-05-24 22:32:00 +02:00
|
|
|
* gta5view Grand Theft Auto V Profile Viewer
|
2017-10-09 08:35:48 +02:00
|
|
|
* 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 15:18:23 +02:00
|
|
|
enum DataValidation {
|
|
|
|
Validate = 0,
|
|
|
|
BypassValidation = 1
|
|
|
|
};
|
2017-10-09 08:35:48 +02:00
|
|
|
|
2020-08-25 15:18:23 +02:00
|
|
|
enum JsonFormat {
|
|
|
|
Indented,
|
|
|
|
Compact
|
|
|
|
};
|
2017-10-09 08:35:48 +02:00
|
|
|
|
|
|
|
public:
|
2020-08-25 15:18:23 +02:00
|
|
|
QJsonDocument();
|
|
|
|
QJsonDocument(const QJsonObject &object);
|
|
|
|
QJsonDocument(const QJsonArray &array);
|
|
|
|
QJsonDocument(const QJsonDocument &other);
|
|
|
|
~QJsonDocument();
|
2017-10-09 08:35:48 +02:00
|
|
|
|
|
|
|
public:
|
2020-08-25 15:18:23 +02:00
|
|
|
QJsonDocument &operator=(const QJsonDocument &other);
|
2017-10-09 08:35:48 +02:00
|
|
|
|
|
|
|
public:
|
2020-08-25 15:18:23 +02:00
|
|
|
bool operator!=(const QJsonDocument &other) const;
|
|
|
|
bool operator==(const QJsonDocument &other) const;
|
2017-10-09 08:35:48 +02:00
|
|
|
|
|
|
|
public:
|
2020-08-25 15:18:23 +02:00
|
|
|
bool isArray() const;
|
|
|
|
bool isEmpty() const;
|
|
|
|
bool isNull() const;
|
|
|
|
bool isObject() const;
|
2017-10-09 08:35:48 +02:00
|
|
|
|
|
|
|
public:
|
2020-08-25 15:18:23 +02:00
|
|
|
QByteArray toBinaryData() const;
|
|
|
|
QByteArray toJson(JsonFormat format = Indented) const;
|
|
|
|
QVariant toVariant() const;
|
2017-10-09 08:35:48 +02:00
|
|
|
|
|
|
|
public:
|
2020-08-25 15:18:23 +02:00
|
|
|
QJsonArray array() const;
|
|
|
|
QJsonObject object() const;
|
|
|
|
const char *rawData(int *size) const;
|
2017-10-09 08:35:48 +02:00
|
|
|
|
|
|
|
public:
|
2020-08-25 15:18:23 +02:00
|
|
|
void setArray(const QJsonArray &array);
|
|
|
|
void setObject(const QJsonObject &object);
|
2017-10-09 08:35:48 +02:00
|
|
|
|
|
|
|
public:
|
2020-08-25 15:18:23 +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);
|
2017-10-09 08:35:48 +02:00
|
|
|
|
|
|
|
private:
|
2020-08-25 15:18:23 +02:00
|
|
|
void setRoot(const QJsonRoot &root);
|
2020-08-25 15:47:08 +02:00
|
|
|
QString toJson(const QJsonValue &v, JsonFormat format, int indent = 1) const;
|
2020-08-25 15:18:23 +02:00
|
|
|
QString escapeString(const QString &s) const;
|
2017-10-09 08:35:48 +02:00
|
|
|
|
|
|
|
private:
|
2020-08-25 15:18:23 +02:00
|
|
|
void swap(QJsonDocument &other);
|
2017-10-09 08:35:48 +02:00
|
|
|
|
|
|
|
private:
|
2020-08-25 15:18:23 +02:00
|
|
|
QJsonRoot *root_;
|
2017-10-09 08:35:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|