mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 11:05:44 +08:00
refs #192 , enabled CValueObject for JSON
* operators * from/toJson method
This commit is contained in:
@@ -8,6 +8,9 @@
|
|||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonValueRef>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -196,6 +199,18 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
virtual QVariant toQVariant() const = 0;
|
virtual QVariant toQVariant() const = 0;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Contribute to JSON object
|
||||||
|
* \return updated JSON object
|
||||||
|
*/
|
||||||
|
virtual QJsonObject toJson() const { QJsonObject json; return json;}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Initialize from JSOn object
|
||||||
|
* \param json
|
||||||
|
*/
|
||||||
|
virtual void fromJson(const QJsonObject &json) { Q_UNUSED(json); }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief As icon, not implement by all classes
|
* \brief As icon, not implement by all classes
|
||||||
* \return
|
* \return
|
||||||
@@ -334,6 +349,67 @@ namespace BlackMisc
|
|||||||
return argument << static_cast<CValueObject const &>(valueObject);
|
return argument << static_cast<CValueObject const &>(valueObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Non member, non friend operator >> for JSON
|
||||||
|
* \param json
|
||||||
|
* \param valueObject
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
inline const QJsonObject &operator>>(const QJsonObject &json, CValueObject &valueObject)
|
||||||
|
{
|
||||||
|
valueObject.fromJson(json);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Non member, non friend operator >> for JSON
|
||||||
|
* \param json
|
||||||
|
* \param valueObject
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
inline const QJsonValue &operator>>(const QJsonValue &json, CValueObject &valueObject)
|
||||||
|
{
|
||||||
|
valueObject.fromJson(json.toObject());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Non member, non friend operator >> for JSON
|
||||||
|
* \param json
|
||||||
|
* \param valueObject
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
inline const QJsonValueRef &operator>>(const QJsonValueRef &json, CValueObject &valueObject)
|
||||||
|
{
|
||||||
|
valueObject.fromJson(json.toObject());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Non member, non friend operator >> for JSON
|
||||||
|
* \param json
|
||||||
|
* \param value
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
inline QJsonArray &operator<<(QJsonArray &json, const CValueObject &value)
|
||||||
|
{
|
||||||
|
json.append(value.toJson());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Non member, non friend operator >> for JSON
|
||||||
|
* \param json
|
||||||
|
* \param value
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
template <class T> typename std::enable_if<std::is_base_of<CValueObject, T>::value, QJsonObject>::type &
|
||||||
|
operator<<(QJsonObject &json, const std::pair<QString, T> &value)
|
||||||
|
{
|
||||||
|
json.insert(value.first, QJsonValue(value.second.toJson()));
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Allow comparison with QVariant, e.g. QVariant == CFrequency ?
|
* Allow comparison with QVariant, e.g. QVariant == CFrequency ?
|
||||||
* \param variant
|
* \param variant
|
||||||
|
|||||||
Reference in New Issue
Block a user