| 2279 | } |
| 2280 | |
| 2281 | bool SaveToJSON(QVariantMap &data, QIODevice &f, const char *magicIdentifier, uint32_t magicVersion) |
| 2282 | { |
| 2283 | // marker that this data is valid |
| 2284 | if(magicIdentifier) |
| 2285 | data[QString::fromLatin1(magicIdentifier)] = magicVersion; |
| 2286 | |
| 2287 | QJsonDocument doc = validateAndMakeJSON(data); |
| 2288 | |
| 2289 | if(doc.isEmpty() || doc.isNull()) |
| 2290 | { |
| 2291 | qCritical() << "Failed to convert data to JSON document"; |
| 2292 | return false; |
| 2293 | } |
| 2294 | |
| 2295 | QByteArray jsontext = doc.toJson(QJsonDocument::Indented); |
| 2296 | |
| 2297 | qint64 ret = f.write(jsontext); |
| 2298 | |
| 2299 | if(ret != jsontext.size()) |
| 2300 | { |
| 2301 | qCritical() << "Failed to write JSON data: " << ret << " " << f.errorString(); |
| 2302 | return false; |
| 2303 | } |
| 2304 | |
| 2305 | return true; |
| 2306 | } |
| 2307 | |
| 2308 | bool LoadFromJSON(QVariantMap &data, QIODevice &f, const char *magicIdentifier, uint32_t magicVersion) |
| 2309 | { |
no test coverage detected