Showing the changes to libraries/script-engine/src/ScriptMessage.cpp (1 of 370 files). Show all
Unified · Split
| @@ -0,0 +1,48 @@ | |||
| 1 | // | ||
| 2 | // ScriptMessage.h | ||
| 3 | // libraries/script-engine/src/v8/FastScriptValueUtils.cpp | ||
| 4 | // | ||
| 5 | // Created by dr Karol Suprynowicz on 2023/09/24. | ||
| 6 | // Copyright 2023 Overte e.V. | ||
| 7 | // | ||
| 8 | // Distributed under the Apache License, Version 2.0. | ||
| 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | ||
| 10 | // | ||
| 11 | |||
| 12 | #include "ScriptMessage.h" | ||
| 13 | |||
| 14 | #include <qhash.h> | ||
| 15 | |||
| 16 | QJsonObject ScriptMessage::toJson() { | ||
| 17 | QJsonObject object; | ||
| 18 | object["message"] = _messageContent; | ||
| 19 | object["lineNumber"] = _lineNumber; | ||
| 20 | object["fileName"] = _fileName; | ||
| 21 | object["entityID"] = _entityID.toString(); | ||
| 22 | object["type"] = static_cast<int>(_scriptType); | ||
| 23 | object["severity"] = static_cast<int>(_severity); | ||
| 24 | return object; | ||
| 25 | } | ||
| 26 | |||
| 27 | bool ScriptMessage::fromJson(const QJsonObject &object) { | ||
| 28 | if (object.isEmpty()) { | ||
| 29 | qDebug() << "ScriptMessage::fromJson object is empty"; | ||
| 30 | return false; | ||
| 31 | } | ||
| 32 | if (!object["message"].isString() | ||
| 33 | || !object["lineNumber"].isDouble() | ||
| 34 | || !object["fileName"].isString() | ||
| 35 | || !object["entityID"].isString() | ||
| 36 | || !object["type"].isDouble() | ||
| 37 | || !object["severity"].isDouble()) { | ||
| 38 | qDebug() << "ScriptMessage::fromJson failed to find required fields in JSON file"; | ||
| 39 | return false; | ||
| 40 | } | ||
| 41 | _messageContent = object["message"].toString(); | ||
| 42 | _lineNumber = object["lineNumber"].toInt(); | ||
| 43 | _fileName = object["fileName"].toInt(); | ||
| 44 | _entityID = QUuid::fromString(object["entityID"].toString()); | ||
| 45 | _scriptType = static_cast<ScriptMessage::ScriptType>(object["type"].toInt()); | ||
| 46 | _severity = static_cast<ScriptMessage::Severity>(object["severity"].toInt()); | ||
| 47 | return true; | ||
| 48 | } | ||