Files
DbMinecraft/chathelper.cpp

37 lines
885 B
C++
Raw Permalink Normal View History

#include "chathelper.h"
#include <QJsonDocument>
2020-07-19 01:01:04 +02:00
#include <QJsonArray>
2020-07-19 01:01:04 +02:00
QJsonObject ChatPart::toObject() const
{
2020-07-19 01:01:04 +02:00
QJsonObject obj;
if (text.has_value())
obj["text"] = *text;
if (bold.has_value())
obj["bold"] = *bold;
if (italic.has_value())
obj["italic"] = *italic;
if (underlined.has_value())
obj["underlined"] = *underlined;
if (strikethrough.has_value())
obj["strikethrough"] = *strikethrough;
if (obfuscated.has_value())
obj["obfuscated"] = *obfuscated;
if (color.has_value())
obj["color"] = *color;
if (!extra.empty())
{
QJsonArray arr;
for (const auto &sub : extra)
arr.append(sub.toObject());
obj["extra"] = arr;
}
return obj;
}
2020-07-19 01:01:04 +02:00
QString ChatPart::toString() const
{
2020-07-19 01:01:04 +02:00
return QJsonDocument{toObject()}.toJson(QJsonDocument::Compact);
}