Browse Source

Switch to version 2

Ignore old version 1
QGC4.4
DonLakeFlyer 7 years ago
parent
commit
63abdfd534
  1. 7
      src/MissionManager/GeoFenceController.cc
  2. 2
      src/MissionManager/GeoFenceController.h
  3. 27
      src/MissionManager/RallyPointController.cc
  4. 2
      src/MissionManager/RallyPointController.h

7
src/MissionManager/GeoFenceController.cc

@ -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)
{
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 },

2
src/MissionManager/GeoFenceController.h

@ -113,7 +113,7 @@ private: @@ -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;

27
src/MissionManager/RallyPointController.cc

@ -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;

2
src/MissionManager/RallyPointController.h

@ -74,6 +74,8 @@ private: @@ -74,6 +74,8 @@ private:
QObject* _currentRallyPoint;
bool _itemsRequested;
static const int _jsonCurrentVersion = 2;
static const char* _jsonFileTypeValue;
static const char* _jsonPointsKey;
};

Loading…
Cancel
Save