mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 02:55:44 +08:00
Ref T264, Ref T263 simple approach to remember last directory (load/save) in view
* utility function "unwrapCache" to unwrap cache data * fixed loading from file, also supporting memoized formats as well * remember last directory
This commit is contained in:
@@ -392,7 +392,8 @@ namespace BlackMisc
|
||||
{
|
||||
if (json.isEmpty()) { return QJsonObject();}
|
||||
const QJsonDocument jsonDoc(QJsonDocument::fromJson(json.toUtf8()));
|
||||
return acceptCacheFormat ? Json::swiftDataObjectValue(jsonDoc.object()) : jsonDoc.object();
|
||||
return acceptCacheFormat ? Json::unwrapCache(jsonDoc.object()) : jsonDoc.object();
|
||||
// return acceptCacheFormat ? Json::swiftDataObjectValue(jsonDoc.object()) : jsonDoc.object();
|
||||
}
|
||||
|
||||
QString stringFromJsonObject(const QJsonObject &jsonObject, QJsonDocument::JsonFormat format)
|
||||
@@ -487,11 +488,28 @@ namespace BlackMisc
|
||||
const QJsonObject cacheObject = object.value(key).toObject();
|
||||
if (cacheObject.contains("type") && cacheObject.contains("value"))
|
||||
{
|
||||
const QString type = cacheObject.value("type").toString(); // just to verify in debugger
|
||||
Q_UNUSED(type);
|
||||
return cacheObject.value("value").toObject();
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
QJsonObject unwrapCache(const QJsonObject &object)
|
||||
{
|
||||
if (object.size() != 1) { return object; } // no cache format
|
||||
const QString key = object.keys().front();
|
||||
const QJsonObject cacheObject = object.value(key).toObject();
|
||||
if (cacheObject.contains("type") && cacheObject.contains("value"))
|
||||
{
|
||||
// return object in form type/value
|
||||
const QString type = cacheObject.value("type").toString(); // just to verify in debugger
|
||||
Q_UNUSED(type);
|
||||
return cacheObject;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
QJsonObject swiftDataObjectValue(const QString &jsonString)
|
||||
{
|
||||
const QJsonObject obj = jsonObjectFromString(jsonString);
|
||||
@@ -499,6 +517,14 @@ namespace BlackMisc
|
||||
return swiftDataObjectValue(obj);
|
||||
}
|
||||
|
||||
|
||||
QJsonObject unwrapCache(const QString &jsonString)
|
||||
{
|
||||
const QJsonObject obj = jsonObjectFromString(jsonString);
|
||||
if (obj.isEmpty()) { return obj; }
|
||||
return unwrapCache(obj);
|
||||
}
|
||||
|
||||
bool looksLikeSwiftContainerJson(const QJsonObject &object)
|
||||
{
|
||||
// CContainerbase::convertFromJson
|
||||
|
||||
@@ -275,6 +275,16 @@ namespace BlackMisc
|
||||
//! \remark if data object unstrip from that, otherwise leave unchanged
|
||||
BLACKMISC_EXPORT QJsonObject swiftDataObjectValue(const QString &jsonString);
|
||||
|
||||
//! The value of a cache/setting object
|
||||
//! \remark if cache object unstrip from that, otherwise leave unchanged
|
||||
//! \remark format is type/value
|
||||
BLACKMISC_EXPORT QJsonObject unwrapCache(const QJsonObject &object);
|
||||
|
||||
//! The value of a cache/setting object
|
||||
//! \remark if cache object unstrip from that, otherwise leave unchanged
|
||||
//! \remark format is type/value
|
||||
BLACKMISC_EXPORT QJsonObject unwrapCache(const QString &jsonString);
|
||||
|
||||
/*!
|
||||
* Load JSON file and init by that
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user