diff --git a/src/MissionManager/GeoFenceController.cc b/src/MissionManager/GeoFenceController.cc index 048bcc1e202f81e49cbd541398eec3002cb29fb5..254790b3da6d49f3a1cb98306c5060ca41e4cc20 100644 --- a/src/MissionManager/GeoFenceController.cc +++ b/src/MissionManager/GeoFenceController.cc @@ -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 keyInfoList = { { JsonHelper::jsonVersionKey, QJsonValue::Double, true }, { _jsonCirclesKey, QJsonValue::Array, true }, diff --git a/src/MissionManager/GeoFenceController.h b/src/MissionManager/GeoFenceController.h index cac130d64adce4510786b328956df4fe648be486..9412fc00530c0ca81c0408bf10af327ec5e59502 100644 --- a/src/MissionManager/GeoFenceController.h +++ b/src/MissionManager/GeoFenceController.h @@ -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; diff --git a/src/MissionManager/RallyPointController.cc b/src/MissionManager/RallyPointController.cc index ab52a8adf7d014b2c770ec6745f4d07bc90d789e..58a369aa4ece83d646c9a3e0d97b2a7980de33c9 100644 --- a/src/MissionManager/RallyPointController.cc +++ b/src/MissionManager/RallyPointController.cc @@ -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 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