mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-25 10:15:43 +08:00
committed by
Mathew Sutcliffe
parent
7ca06c196d
commit
6a677c06d6
@@ -1,9 +1,15 @@
|
|||||||
/* Copyright (C) 2013 VATSIM Community / authors
|
/* Copyright (C) 2014
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
* swift project Community / Contributors
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
*
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "json.h"
|
#include "json.h"
|
||||||
|
#include "blackmiscfreefunctions.h"
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
const QJsonValue &operator >>(const QJsonValue &json, int &value)
|
const QJsonValue &operator >>(const QJsonValue &json, int &value)
|
||||||
{
|
{
|
||||||
@@ -113,6 +119,20 @@ const QJsonValueRef &operator >>(const QJsonValueRef &json, QDateTime &value)
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, QPixmap &value)
|
||||||
|
{
|
||||||
|
const QString hex(json.toString());
|
||||||
|
BlackMisc::pngHexStringToPixmapRef(hex, value);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValue &operator >>(const QJsonValue &json, QPixmap &value)
|
||||||
|
{
|
||||||
|
const QString hex(json.toString());
|
||||||
|
BlackMisc::pngHexStringToPixmapRef(hex, value);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonArray &operator<<(QJsonArray &json, const int value)
|
QJsonArray &operator<<(QJsonArray &json, const int value)
|
||||||
{
|
{
|
||||||
json.append(QJsonValue(value));
|
json.append(QJsonValue(value));
|
||||||
@@ -167,6 +187,13 @@ QJsonArray &operator<<(QJsonArray &json, const QDateTime &value)
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonArray &operator<<(QJsonArray &json, const QPixmap &value)
|
||||||
|
{
|
||||||
|
QString pm(BlackMisc::pixmapToPngHexString(value));
|
||||||
|
json.append(QJsonValue(pm));
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const int &> &value)
|
QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const int &> &value)
|
||||||
{
|
{
|
||||||
json.insert(value.first, QJsonValue(value.second));
|
json.insert(value.first, QJsonValue(value.second));
|
||||||
@@ -220,3 +247,35 @@ QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const QDateT
|
|||||||
json.insert(value.first, QJsonValue(value.second.toString()));
|
json.insert(value.first, QJsonValue(value.second.toString()));
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const QPixmap &> &value)
|
||||||
|
{
|
||||||
|
QString pm(BlackMisc::pixmapToPngHexString(value.second));
|
||||||
|
json.insert(value.first, pm);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject BlackMisc::Json::jsonObjectFromString(const QString &json)
|
||||||
|
{
|
||||||
|
if (json.isEmpty()) { return QJsonObject();}
|
||||||
|
QJsonDocument jsonDoc(QJsonDocument::fromJson(json.toUtf8()));
|
||||||
|
return jsonDoc.object();
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonArray BlackMisc::Json::jsonArrayFromString(const QString &json)
|
||||||
|
{
|
||||||
|
if (json.isEmpty()) { return QJsonArray();}
|
||||||
|
QJsonDocument jsonDoc(QJsonDocument::fromJson(json.toUtf8()));
|
||||||
|
return jsonDoc.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject &BlackMisc::Json::appendJsonObject(QJsonObject &target, const QJsonObject &toBeAppended)
|
||||||
|
{
|
||||||
|
if (toBeAppended.isEmpty()) return target;
|
||||||
|
QStringList keys = toBeAppended.keys();
|
||||||
|
foreach(const QString & key, keys)
|
||||||
|
{
|
||||||
|
target.insert(key, toBeAppended.value(key));
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,9 +7,7 @@
|
|||||||
* contained in the LICENSE file.
|
* contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
//! \file
|
||||||
\file
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BLACKMISC_JSON_H
|
#ifndef BLACKMISC_JSON_H
|
||||||
#define BLACKMISC_JSON_H
|
#define BLACKMISC_JSON_H
|
||||||
@@ -23,6 +21,7 @@
|
|||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QPixmap>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -41,6 +40,7 @@ BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, QString &
|
|||||||
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, double &value);
|
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, double &value);
|
||||||
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, bool &value);
|
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, bool &value);
|
||||||
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, QDateTime &value);
|
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, QDateTime &value);
|
||||||
|
BLACKMISC_EXPORT const QJsonValue &operator >>(const QJsonValue &json, QPixmap &value);
|
||||||
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, int &value);
|
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, int &value);
|
||||||
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, qlonglong &value);
|
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, qlonglong &value);
|
||||||
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, qulonglong &value);
|
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, qulonglong &value);
|
||||||
@@ -50,6 +50,8 @@ BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, QSt
|
|||||||
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, double &value);
|
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, double &value);
|
||||||
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, bool &value);
|
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, bool &value);
|
||||||
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, QDateTime &value);
|
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, QDateTime &value);
|
||||||
|
BLACKMISC_EXPORT const QJsonValueRef &operator >>(const QJsonValueRef &json, QPixmap &value);
|
||||||
|
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
//! \brief Specialized JSON serialization for enum
|
//! \brief Specialized JSON serialization for enum
|
||||||
@@ -95,6 +97,7 @@ BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const QString &value);
|
|||||||
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const double value);
|
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const double value);
|
||||||
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const bool value);
|
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const bool value);
|
||||||
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const QDateTime &value);
|
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const QDateTime &value);
|
||||||
|
BLACKMISC_EXPORT QJsonArray &operator<<(QJsonArray &json, const QPixmap &value);
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
//! \name Streaming operators for QJsonObject (from value)
|
//! \name Streaming operators for QJsonObject (from value)
|
||||||
@@ -109,31 +112,29 @@ BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QStr
|
|||||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const double &> &value);
|
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const double &> &value);
|
||||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const bool &> &value);
|
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const bool &> &value);
|
||||||
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const QDateTime &> &value);
|
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const QDateTime &> &value);
|
||||||
|
BLACKMISC_EXPORT QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const QPixmap &> &value);
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
namespace Json
|
namespace Json
|
||||||
{
|
{
|
||||||
|
//! Append to first JSON object (concatenate)
|
||||||
//! \brief Append to first JSON object (concatenate)
|
|
||||||
//! \ingroup JSON
|
//! \ingroup JSON
|
||||||
inline QJsonObject &appendJsonObject(QJsonObject &target, const QJsonObject &toBeAppended)
|
BLACKMISC_EXPORT QJsonObject &appendJsonObject(QJsonObject &target, const QJsonObject &toBeAppended);
|
||||||
{
|
|
||||||
if (toBeAppended.isEmpty()) return target;
|
//! JSON Object from string
|
||||||
QStringList keys = toBeAppended.keys();
|
//! \ingroup JSON
|
||||||
foreach(const QString & key, keys)
|
BLACKMISC_EXPORT QJsonObject jsonObjectFromString(const QString &json);
|
||||||
{
|
|
||||||
target.insert(key, toBeAppended.value(key));
|
//! JSON Array from string
|
||||||
}
|
//! \ingroup JSON
|
||||||
return target;
|
BLACKMISC_EXPORT QJsonArray jsonArrayFromString(const QString &json);
|
||||||
}
|
|
||||||
|
|
||||||
} // Json
|
} // Json
|
||||||
|
|
||||||
namespace Mixin
|
namespace Mixin
|
||||||
{
|
{
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* CRTP class template which will generate marshalling operators for a derived class with its own marshalling implementation.
|
* CRTP class template which will generate marshalling operators for a derived class with its own marshalling implementation.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user