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) ...@@ -119,8 +119,15 @@ void GeoFenceController::managerVehicleChanged(Vehicle* managerVehicle)
bool GeoFenceController::load(const QJsonObject& json, QString& errorString) bool GeoFenceController::load(const QJsonObject& json, QString& errorString)
{ {
removeAll();
errorString.clear(); 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 = { QList<JsonHelper::KeyValidateInfo> keyInfoList = {
{ JsonHelper::jsonVersionKey, QJsonValue::Double, true }, { JsonHelper::jsonVersionKey, QJsonValue::Double, true },
{ _jsonCirclesKey, QJsonValue::Array, true }, { _jsonCirclesKey, QJsonValue::Array, true },
......
...@@ -113,7 +113,7 @@ private: ...@@ -113,7 +113,7 @@ private:
static const char* _px4ParamCircularFence; static const char* _px4ParamCircularFence;
static const int _jsonCurrentVersion = 1; static const int _jsonCurrentVersion = 2;
static const char* _jsonFileTypeValue; static const char* _jsonFileTypeValue;
static const char* _jsonBreachReturnKey; static const char* _jsonBreachReturnKey;
......
...@@ -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) 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 errorStr;
QString errorMessage = tr("Rally: %1"); QString errorMessage = tr("Rally: %1");
// Check for required keys if (json[JsonHelper::jsonVersionKey].toInt() != _jsonCurrentVersion) {
QStringList requiredKeys = { _jsonPointsKey }; errorString = tr("Rally Points supports version %1").arg(_jsonCurrentVersion);
if (!JsonHelper::validateRequiredKeys(json, requiredKeys, errorStr)) {
errorString = errorMessage.arg(errorStr);
return false; 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); errorString = errorMessage.arg(errorStr);
return false; return false;
} }
_points.clearAndDeleteContents();
QObjectList pointList; QObjectList pointList;
for (int i=0; i<rgPoints.count(); i++) { for (int i=0; i<rgPoints.count(); i++) {
pointList.append(new RallyPoint(rgPoints[i], this)); 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) void RallyPointController::save(QJsonObject& json)
{ {
json[JsonHelper::jsonVersionKey] = 1; json[JsonHelper::jsonVersionKey] = _jsonCurrentVersion;
QJsonArray rgPoints; QJsonArray rgPoints;
QJsonValue jsonPoint; QJsonValue jsonPoint;
......
...@@ -74,6 +74,8 @@ private: ...@@ -74,6 +74,8 @@ private:
QObject* _currentRallyPoint; QObject* _currentRallyPoint;
bool _itemsRequested; bool _itemsRequested;
static const int _jsonCurrentVersion = 2;
static const char* _jsonFileTypeValue; static const char* _jsonFileTypeValue;
static const char* _jsonPointsKey; 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