refs #784 Adjust CValueCache to use the new JSON schema.

This commit is contained in:
Mathew Sutcliffe
2016-10-26 16:45:42 +01:00
committed by Klaus Basan
parent 72a5a0e670
commit 2ab2819867

View File

@@ -316,13 +316,13 @@ namespace BlackMisc
QJsonObject CValueCache::saveToJson(const QString &keyPrefix) const QJsonObject CValueCache::saveToJson(const QString &keyPrefix) const
{ {
return getAllValues(keyPrefix).toJson(); return getAllValues(keyPrefix).toMemoizedJson();
} }
void CValueCache::loadFromJson(const QJsonObject &json) void CValueCache::loadFromJson(const QJsonObject &json)
{ {
CVariantMap map; CVariantMap map;
map.convertFromJson(json); map.convertFromMemoizedJson(json);
insertValues({ map, QDateTime::currentMSecsSinceEpoch() }); insertValues({ map, QDateTime::currentMSecsSinceEpoch() });
} }
@@ -368,7 +368,7 @@ namespace BlackMisc
return CStatusMessage(this).error("Invalid JSON format in %1") << file.fileName(); return CStatusMessage(this).error("Invalid JSON format in %1") << file.fileName();
} }
auto object = json.object(); auto object = json.object();
json.setObject(it->mergeToJson(object)); json.setObject(it->mergeToMemoizedJson(object));
if (!(file.seek(0) && file.resize(0) && file.write(json.toJson()) > 0 && file.checkedClose())) if (!(file.seek(0) && file.resize(0) && file.write(json.toJson()) > 0 && file.checkedClose()))
{ {
@@ -425,8 +425,8 @@ namespace BlackMisc
return CStatusMessage(this).error("Invalid JSON format in %1") << file.fileName(); return CStatusMessage(this).error("Invalid JSON format in %1") << file.fileName();
} }
CVariantMap temp; CVariantMap temp;
temp.convertFromJson(json.object(), it.value()); temp.convertFromMemoizedJson(json.object(), it.value());
if (it.value().isEmpty()) { temp.convertFromJson(json.object()); } if (it.value().isEmpty()) { temp.convertFromMemoizedJson(json.object()); }
temp.removeDuplicates(currentValues); temp.removeDuplicates(currentValues);
o_values.insert(temp, QFileInfo(file).lastModified().toMSecsSinceEpoch()); o_values.insert(temp, QFileInfo(file).lastModified().toMSecsSinceEpoch());
} }