Commit 63abdfd5 authored by DonLakeFlyer's avatar DonLakeFlyer

Switch to version 2

Ignore old version 1
parent e48aad6b
......@@ -119,8 +119,15 @@ void GeoFenceController::managerVehicleChanged(Vehicle* managerVehicle)
bool GeoFenceController::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 },
{ _jsonCirclesKey, QJsonValue::Array, true },
......
......@@ -113,7 +113,7 @@ private:
static const char* _px4ParamCircularFence;
static const int _jsonCurrentVersion = 1;
static const int _jsonCurrentVersion = 2;
static const char* _jsonFileTypeValue;
static const char* _jsonBreachReturnKey;
......
......@@ -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)
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)
void RallyPointController::save(QJsonObject& json)
{
json[JsonHelper::jsonVersionKey] = 1;
json[JsonHelper::jsonVersionKey] = _jsonCurrentVersion;
QJsonArray rgPoints;
QJsonValue jsonPoint;
......
......@@ -74,6 +74,8 @@ private:
QObject* _currentRallyPoint;
bool _itemsRequested;
static const int _jsonCurrentVersion = 2;
static const char* _jsonFileTypeValue;
static const char* _jsonPointsKey;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment