diff --git a/src/nlohmann_qt_helpers.h b/src/nlohmann_qt_helpers.h index 49541d20..e66b145e 100644 --- a/src/nlohmann_qt_helpers.h +++ b/src/nlohmann_qt_helpers.h @@ -13,6 +13,8 @@ #include #include +#include +#include #include @@ -28,6 +30,27 @@ inline void to_json(nlohmann::json &j, const QString &s) j = s.toStdString(); } +inline void from_json(const nlohmann::json &j, QStringList &stringList) +{ + if (!j.is_array()) { + qWarning() << Q_FUNC_INFO << "This is not an array, fix the code"; + stringList.clear(); + return; + } + stringList.reserve((int)j.size()); + for (const auto &v : j) { + QString s = v; + stringList.push_back(std::move(s)); + } +} + +inline void to_json(nlohmann::json &j, const QStringList &stringList) +{ + for (const auto &s : stringList) { + j.push_back(s); + } +} + inline void to_json(nlohmann::json& j, const QVariantList& list); inline void from_json(const nlohmann::json& j, QVariantList& list); inline void to_json(nlohmann::json& j, const QVariantMap& map); @@ -166,4 +189,18 @@ inline void from_json(const nlohmann::json& j, QVariantMap& map) } } +inline void to_json(nlohmann::json& j, const QSize& size) +{ + j["width"] = size.width(); + j["height"] = size.height(); +} + +inline void to_json(nlohmann::json& j, const QRect& rect) +{ + j["x"] = rect.x(); + j["y"] = rect.y(); + j["width"] = rect.width(); + j["height"] = rect.height(); +} + QT_END_NAMESPACE