forked from qt-creator/qt-creator
CompilerExplorer: Fix load/save
Change-Id: I2bc1bdbab73b37a5af9bc1fcd040c8ec0c7f363a Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -109,21 +109,14 @@ Core::IDocument::OpenResult JsonSettingsDocument::open(QString *errorString,
|
|||||||
return OpenResult::ReadError;
|
return OpenResult::ReadError;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonParseError error;
|
auto result = storeFromJson(*contents);
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*contents, &error);
|
if (!result) {
|
||||||
if (error.error != QJsonParseError::NoError) {
|
|
||||||
if (errorString)
|
if (errorString)
|
||||||
*errorString = error.errorString();
|
*errorString = result.error();
|
||||||
return OpenResult::CannotHandle;
|
return OpenResult::ReadError;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!doc.isObject()) {
|
m_ceSettings.fromMap(*result);
|
||||||
if (errorString)
|
|
||||||
*errorString = Tr::tr("Not a valid JSON object.");
|
|
||||||
return OpenResult::CannotHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_ceSettings.fromMap(storeFromVariant(doc.toVariant().toMap()));
|
|
||||||
emit settingsChanged();
|
emit settingsChanged();
|
||||||
return OpenResult::Success;
|
return OpenResult::Success;
|
||||||
}
|
}
|
||||||
@@ -147,14 +140,12 @@ bool JsonSettingsDocument::saveImpl(QString *errorString,
|
|||||||
m_ceSettings.toMap(map);
|
m_ceSettings.toMap(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonDocument doc = QJsonDocument::fromVariant(variantFromStore(map));
|
|
||||||
|
|
||||||
Utils::FilePath path = newFilePath.isEmpty() ? filePath() : newFilePath;
|
Utils::FilePath path = newFilePath.isEmpty() ? filePath() : newFilePath;
|
||||||
|
|
||||||
if (!newFilePath.isEmpty() && !autoSave)
|
if (!newFilePath.isEmpty() && !autoSave)
|
||||||
setFilePath(newFilePath);
|
setFilePath(newFilePath);
|
||||||
|
|
||||||
auto result = path.writeFileContents(doc.toJson(QJsonDocument::Indented));
|
auto result = path.writeFileContents(jsonFromStore(map));
|
||||||
if (!result && errorString) {
|
if (!result && errorString) {
|
||||||
*errorString = result.error();
|
*errorString = result.error();
|
||||||
return false;
|
return false;
|
||||||
@@ -170,13 +161,10 @@ bool JsonSettingsDocument::isModified() const
|
|||||||
|
|
||||||
bool JsonSettingsDocument::setContents(const QByteArray &contents)
|
bool JsonSettingsDocument::setContents(const QByteArray &contents)
|
||||||
{
|
{
|
||||||
QJsonParseError error;
|
auto result = storeFromJson(contents);
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(contents, &error);
|
QTC_ASSERT_EXPECTED(result, return false);
|
||||||
QTC_ASSERT(error.error == QJsonParseError::NoError, return false);
|
|
||||||
|
|
||||||
QTC_ASSERT(doc.isObject(), return false);
|
m_ceSettings.fromMap(*result);
|
||||||
|
|
||||||
m_ceSettings.fromMap(storeFromVariant(doc.toVariant()));
|
|
||||||
|
|
||||||
emit settingsChanged();
|
emit settingsChanged();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user