mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 07:35:41 +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>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
QJsonObject CListModelBase<ObjectType, ContainerType, UseCompare>::toJson() const
|
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>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
QString CListModelBase<ObjectType, ContainerType, UseCompare>::toJsonString(QJsonDocument::JsonFormat format) const
|
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>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
|
|||||||
@@ -1405,10 +1405,22 @@ namespace BlackGui
|
|||||||
m = CStatusMessage(this).warning("Reading '%1' yields no data") << fileName;
|
m = CStatusMessage(this).warning("Reading '%1' yields no data") << fileName;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!Json::looksLikeSwiftJson(json))
|
||||||
|
{
|
||||||
|
m = CStatusMessage(this).warning("No swift JSON '%1'") << fileName;
|
||||||
|
break;
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ContainerType container;
|
CVariant containerVariant;
|
||||||
container.convertFromJson(json);
|
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);
|
m = this->modifyLoadedJsonData(container);
|
||||||
if (m.isFailure()) { break; } // modification error
|
if (m.isFailure()) { break; } // modification error
|
||||||
m = this->validateLoadedJsonData(container);
|
m = this->validateLoadedJsonData(container);
|
||||||
@@ -1436,8 +1448,8 @@ namespace BlackGui
|
|||||||
tr("Save data file"), getDefaultFilename(false),
|
tr("Save data file"), getDefaultFilename(false),
|
||||||
tr("swift (*.json *.txt)"));
|
tr("swift (*.json *.txt)"));
|
||||||
if (fileName.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityDebug, "Save canceled", true); }
|
if (fileName.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityDebug, "Save canceled", true); }
|
||||||
const QString json(this->toJsonString());
|
const QString json(this->toJsonString()); // save as CVariant JSON
|
||||||
bool ok = CFileUtils::writeStringToFileInBackground(json, fileName);
|
const bool ok = CFileUtils::writeStringToFileInBackground(json, fileName);
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Writing " + fileName + " in progress", true);
|
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Writing " + fileName + " in progress", true);
|
||||||
|
|||||||
Reference in New Issue
Block a user