|
|
|
@ -82,13 +82,28 @@ void RallyPointController::managerVehicleChanged(Vehicle* managerVehicle)
@@ -82,13 +82,28 @@ void RallyPointController::managerVehicleChanged(Vehicle* managerVehicle)
|
|
|
|
|
|
|
|
|
|
bool RallyPointController::load(const QJsonObject& json, QString& errorString) |
|
|
|
|
{ |
|
|
|
|
removeAll(); |
|
|
|
|
|
|
|
|
|
errorString.clear(); |
|
|
|
|
|
|
|
|
|
if (json.contains(JsonHelper::jsonVersionKey) && json[JsonHelper::jsonVersionKey].toInt() == 1) { |
|
|
|
|
// We just ignore old version 1 data
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QList<JsonHelper::KeyValidateInfo> keyInfoList = { |
|
|
|
|
{ JsonHelper::jsonVersionKey, QJsonValue::Double, true }, |
|
|
|
|
{ _jsonPointsKey, QJsonValue::Array, true }, |
|
|
|
|
}; |
|
|
|
|
if (!JsonHelper::validateKeys(json, keyInfoList, errorString)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString errorStr; |
|
|
|
|
QString errorMessage = tr("Rally: %1"); |
|
|
|
|
|
|
|
|
|
// Check for required keys
|
|
|
|
|
QStringList requiredKeys = { _jsonPointsKey }; |
|
|
|
|
if (!JsonHelper::validateRequiredKeys(json, requiredKeys, errorStr)) { |
|
|
|
|
errorString = errorMessage.arg(errorStr); |
|
|
|
|
if (json[JsonHelper::jsonVersionKey].toInt() != _jsonCurrentVersion) { |
|
|
|
|
errorString = tr("Rally Points supports version %1").arg(_jsonCurrentVersion); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -97,7 +112,7 @@ bool RallyPointController::load(const QJsonObject& json, QString& errorString)
@@ -97,7 +112,7 @@ bool RallyPointController::load(const QJsonObject& json, QString& errorString)
|
|
|
|
|
errorString = errorMessage.arg(errorStr); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
_points.clearAndDeleteContents(); |
|
|
|
|
|
|
|
|
|
QObjectList pointList; |
|
|
|
|
for (int i=0; i<rgPoints.count(); i++) { |
|
|
|
|
pointList.append(new RallyPoint(rgPoints[i], this)); |
|
|
|
@ -112,7 +127,7 @@ bool RallyPointController::load(const QJsonObject& json, QString& errorString)
@@ -112,7 +127,7 @@ bool RallyPointController::load(const QJsonObject& json, QString& errorString)
|
|
|
|
|
|
|
|
|
|
void RallyPointController::save(QJsonObject& json) |
|
|
|
|
{ |
|
|
|
|
json[JsonHelper::jsonVersionKey] = 1; |
|
|
|
|
json[JsonHelper::jsonVersionKey] = _jsonCurrentVersion; |
|
|
|
|
|
|
|
|
|
QJsonArray rgPoints; |
|
|
|
|
QJsonValue jsonPoint; |
|
|
|
|