mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 15:25:35 +08:00
refs #923, use CVariant JSON to load/save from view
This commit is contained in:
committed by
Mathew Sutcliffe
parent
864e64e295
commit
ff4b37b3fe
@@ -752,13 +752,15 @@ namespace BlackGui
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
QJsonObject CListModelBase<ObjectType, ContainerType, UseCompare>::toJson() const
|
||||
{
|
||||
return container().toJson();
|
||||
const CVariant variant = CVariant::fromValue(container());
|
||||
return variant.toJson();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
QString CListModelBase<ObjectType, ContainerType, UseCompare>::toJsonString(QJsonDocument::JsonFormat format) const
|
||||
{
|
||||
return container().toJsonString(format);
|
||||
const CVariant variant = CVariant::fromValue(container());
|
||||
return variant.toJsonString(format);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
|
||||
@@ -1405,10 +1405,22 @@ namespace BlackGui
|
||||
m = CStatusMessage(this).warning("Reading '%1' yields no data") << fileName;
|
||||
break;
|
||||
}
|
||||
if (!Json::looksLikeSwiftJson(json))
|
||||
{
|
||||
m = CStatusMessage(this).warning("No swift JSON '%1'") << fileName;
|
||||
break;
|
||||
}
|
||||
try
|
||||
{
|
||||
ContainerType container;
|
||||
container.convertFromJson(json);
|
||||
CVariant containerVariant;
|
||||
containerVariant.convertFromJson(Json::jsonObjectFromString(json));
|
||||
if (!containerVariant.canConvert<ContainerType>())
|
||||
{
|
||||
m = CStatusMessage(this).warning("No valid swift JSON '%1'") << fileName;
|
||||
break;
|
||||
}
|
||||
|
||||
ContainerType container = containerVariant.value<ContainerType>();
|
||||
m = this->modifyLoadedJsonData(container);
|
||||
if (m.isFailure()) { break; } // modification error
|
||||
m = this->validateLoadedJsonData(container);
|
||||
@@ -1436,8 +1448,8 @@ namespace BlackGui
|
||||
tr("Save data file"), getDefaultFilename(false),
|
||||
tr("swift (*.json *.txt)"));
|
||||
if (fileName.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityDebug, "Save canceled", true); }
|
||||
const QString json(this->toJsonString());
|
||||
bool ok = CFileUtils::writeStringToFileInBackground(json, fileName);
|
||||
const QString json(this->toJsonString()); // save as CVariant JSON
|
||||
const bool ok = CFileUtils::writeStringToFileInBackground(json, fileName);
|
||||
if (ok)
|
||||
{
|
||||
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Writing " + fileName + " in progress", true);
|
||||
|
||||
Reference in New Issue
Block a user