Commit fc4a64de authored by Valentin Platzgummer's avatar Valentin Platzgummer

saveing added, loading of MeasurementComplexItem missing

parent a0521309
......@@ -12,8 +12,8 @@
QGC_LOGGING_CATEGORY(AreaDataLog, "AreaDataLog")
const char *originJsonKey = "Origin";
const char *areaListJsonKey = "AreaList";
const char *initializedJsonKey = "Initialized";
const char *areaListKey = "AreaList";
const char *initializedKey = "Initialized";
AreaData::AreaData(QObject *parent) : QObject(parent) {}
......@@ -133,6 +133,8 @@ bool AreaData::isCorrect() {
"the Measurement Area."));
return false;
}
_initialized = true;
return true;
}
......@@ -275,38 +277,147 @@ bool AreaData::operator!=(const AreaData &other) const {
return !(*this == other);
}
bool AreaData::load(const QJsonObject &obj, QString &guiErrorString) {
qWarning() << "AreaData::load impl. missing";
return true;
bool AreaData::load(const QJsonObject &obj, QString &errorString) {
bool returnValue = true;
// load initialized.
{
QString e;
QList<JsonHelper::KeyValidateInfo> keyInfo = {
{initializedKey, QJsonValue::Bool, true},
};
if (JsonHelper::validateKeys(obj, keyInfo, e)) {
_initialized = obj[initializedKey].toBool();
} else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
}
}
// load areaList.
{
QString e;
QList<JsonHelper::KeyValidateInfo> keyInfo = {
{areaListKey, QJsonValue::Array, true},
};
if (JsonHelper::validateKeys(obj, keyInfo, e)) {
this->clear();
// iterate over json array
for (const auto &jsonArea : obj[areaListKey]) {
// check if area type key is present
QList<JsonHelper::KeyValidateInfo> areaInfo = {
{GeoArea::areaTypeKey, QJsonValue::String, true},
};
if (!JsonHelper::validateKeys(jsonArea, areaInfo, e)) {
// load MeasurementArea
if (jsonArea[GeoArea::areaTypeKey] == MeasurementArea::name) {
auto area = getGeoArea<MeasurementArea *>(_areaList);
if (area == nullptr) {
auto area = new MeasurementArea(this);
if (area->loadFromJson(jsonArea, e)) {
this->insert(area);
} else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
area->deleteLater();
}
} else {
returnValue = false;
errorString.append(
tr("Multiple Measurement Areas detected. Area was ignored."));
}
}
// load SafeArea
else if (jsonArea[GeoArea::areaTypeKey] == SafeArea::name) {
auto area = getGeoArea<SafeArea *>(_areaList);
if (area == nullptr) {
auto area = new SafeArea(this);
if (area->loadFromJson(jsonArea, e)) {
this->insert(area);
} else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
area->deleteLater();
}
} else {
returnValue = false;
errorString.append(
tr("Multiple Safe Areas detected. Area was ignored."));
}
}
// unknown area
else {
returnValue = false;
errorString.append(tr("Unknown area type: ") +
jsonArea[GeoArea::areaTypeKey]);
}
}
// GeoArea::areaTypeKey missing
else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
}
}
}
// AreaList missing
else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
}
}
// load origin
{
QString e;
QList<JsonHelper::KeyValidateInfo> keyInfo = {
{originKey, QJsonValue::Object, true},
};
if (JsonHelper::validateKeys(obj, keyInfo, e)) {
QGeoCoordinate origin;
if (JsonHelper::loadGeoCoordinate(obj[originKey], false, origin, e)) {
_origin = origin;
}
}
}
// check if this is correct.
if (!this->isCorrect()) {
returnValue = false;
}
return returnValue;
}
bool AreaData::save(QJsonObject &obj) const {
// QJsonObject temp;
// QJsonValue jsonOrigin;
// JsonHelper::saveGeoCoordinate(_origin, true, jsonOrigin);
// temp[originJsonKey] = jsonOrigin;
// temp[initializedJsonKey] = _initialized;
// QJsonObject jsonAreaList;
// for (int i = 0; i < _areaList.count(); ++i) {
// auto const &qobj = _areaList[i];
// auto const &area = qobject_cast<const GeoArea *>(qobj);
// QJsonObject jsonArea;
// if (area->saveToJson(jsonArea)) {
// QJsonObject jsonObj;
// jsonObj[area->objectName()] = jsonArea;
// jsonAreaList.append(jsonObj);
// } else {
// qDebug(AreaListLog) << "save(): not able to save area: "
// << area->objectName();
// _processError(tr("Not able to save area: ") + area->objectName());
// return false;
// }
// }
// temp[areaListJsonKey] = jsonAreaList;
// obj = std::move(temp);
bool AreaData::save(QJsonObject &obj) {
QJsonObject temp;
QJsonValue jsonOrigin;
JsonHelper::saveGeoCoordinate(_origin, true, jsonOrigin);
temp[originJsonKey] = jsonOrigin;
temp[initializedKey] = _initialized;
QJsonArray jsonAreaList;
for (int i = 0; i < _areaList.count(); ++i) {
auto qobj = _areaList[i];
auto area = qobject_cast<GeoArea *>(qobj);
QJsonObject jsonArea;
if (area->saveToJson(jsonArea)) {
jsonAreaList.append(jsonArea);
} else {
qDebug(AreaDataLog) << "save(): not able to save area: "
<< area->objectName();
_processError(tr("Not able to save area: ") + area->objectName());
return false;
}
}
temp[areaListKey] = jsonAreaList;
obj = std::move(temp);
return true;
}
......
......@@ -74,8 +74,8 @@ public:
bool operator==(const AreaData &other) const;
bool operator!=(const AreaData &other) const;
bool load(const QJsonObject &obj, QString &guiErrorString);
bool save(QJsonObject &obj) const;
bool load(const QJsonObject &obj, QString &errorString);
bool save(QJsonObject &obj);
QString errorString() const; // Contains a message about the last error.
......
......@@ -27,10 +27,10 @@ bool circularTransects(const snake::FPoint &reference,
snake::Length minLength, snake::Transects &transects);
const char *CircularGenerator::settingsGroup = "CircularGenerator";
const char *CircularGenerator::distanceName = "TransectDistance";
const char *CircularGenerator::deltaAlphaName = "DeltaAlpha";
const char *CircularGenerator::minLengthName = "MinLength";
const char *CircularGenerator::refPointName = "ReferencePoint";
const char *CircularGenerator::distanceKey = "TransectDistance";
const char *CircularGenerator::deltaAlphaKey = "DeltaAlpha";
const char *CircularGenerator::minLengthKey = "MinLength";
const char *CircularGenerator::referenceKey = "ReferencePoint";
CircularGenerator::CircularGenerator(QObject *parent)
: CircularGenerator(nullptr, parent) {}
......@@ -39,9 +39,9 @@ CircularGenerator::CircularGenerator(GeneratorBase::Data d, QObject *parent)
: GeneratorBase(d, parent),
_metaDataMap(FactMetaData::createMapFromJsonFile(
QStringLiteral(":/json/CircularGenerator.SettingsGroup.json"), this)),
_distance(settingsGroup, _metaDataMap[distanceName]),
_deltaAlpha(settingsGroup, _metaDataMap[deltaAlphaName]),
_minLength(settingsGroup, _metaDataMap[minLengthName]),
_distance(settingsGroup, _metaDataMap[distanceKey]),
_deltaAlpha(settingsGroup, _metaDataMap[deltaAlphaKey]),
_minLength(settingsGroup, _metaDataMap[minLengthKey]),
_measurementArea(nullptr) {
connect(this->distance(), &Fact::rawValueChanged, this,
&GeneratorBase::generatorChanged);
......@@ -184,53 +184,121 @@ void CircularGenerator::setReference(const QGeoCoordinate &reference) {
}
bool CircularGenerator::save(QJsonObject &obj) const {
// QJsonObject temp;
// bool ok = false;
// auto variant = _distance.rawValue();
// auto val = variant.toDouble(ok);
// if (!ok) {
// qCDebug(CircularGeneratorLog)
// << "save(): not able to save distance. Not a double: "
// << variant.typeName();
// return false;
// } else {
// temp[distanceName] = val;
// }
// variant = _deltaAlpha.rawValue();
// val = variant.toDouble(ok);
// if (!ok) {
// qCDebug(CircularGeneratorLog)
// << "save(): not able to save deltaAlpha. Not a double: "
// << variant.typeName();
// return false;
// } else {
// temp[deltaAlphaName] = val;
// }
// variant = _minLength.rawValue();
// val = variant.toDouble(ok);
// if (!ok) {
// qCDebug(CircularGeneratorLog)
// << "save(): not able to save minLength. Not a double: "
// << variant.typeName();
// return false;
// } else {
// temp[minLengthName] = val;
// }
// QJsonObject jsonReference;
// JsonHelper::saveGeoCoordinate(_reference, true, jsonReference);
// temp[refPointName] = jsonReference;
// obj = std::move(temp);
QJsonObject temp;
bool ok = false;
auto variant = _distance.rawValue();
auto val = variant.toDouble(&ok);
if (!ok) {
qCDebug(CircularGeneratorLog)
<< "save(): not able to save distance. Not a double: "
<< variant.typeName();
return false;
} else {
temp[distanceKey] = val;
}
variant = _deltaAlpha.rawValue();
val = variant.toDouble(&ok);
if (!ok) {
qCDebug(CircularGeneratorLog)
<< "save(): not able to save deltaAlpha. Not a double: "
<< variant.typeName();
return false;
} else {
temp[deltaAlphaKey] = val;
}
variant = _minLength.rawValue();
val = variant.toDouble(&ok);
if (!ok) {
qCDebug(CircularGeneratorLog)
<< "save(): not able to save minLength. Not a double: "
<< variant.typeName();
return false;
} else {
temp[minLengthKey] = val;
}
QJsonValue jsonReference;
JsonHelper::saveGeoCoordinate(_reference, false, jsonReference);
temp[referenceKey] = jsonReference;
obj = std::move(temp);
return true;
}
bool CircularGenerator::load(const QJsonObject &obj, QString &guiErrorMessage) {
qWarning() << "CircularGenerator::load() impl. missing";
return true;
bool CircularGenerator::load(const QJsonObject &obj, QString &errorString) {
bool returnValue = true;
// load distance
{
QString e;
QList<JsonHelper::KeyValidateInfo> keyInfo = {
{distanceKey, QJsonValue::Double, true},
};
if (JsonHelper::validateKeys(obj, keyInfo, e)) {
_distance.setRawValue(obj[distanceKey]);
} else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
}
}
// load deltaAlpha
{
QString e;
QList<JsonHelper::KeyValidateInfo> keyInfo = {
{deltaAlphaKey, QJsonValue::Double, true},
};
if (JsonHelper::validateKeys(obj, keyInfo, e)) {
_deltaAlpha.setRawValue(obj[deltaAlphaKey]);
} else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
}
}
// load distance
{
QString e;
QList<JsonHelper::KeyValidateInfo> keyInfo = {
{minLengthKey, QJsonValue::Double, true},
};
if (JsonHelper::validateKeys(obj, keyInfo, e)) {
_minLength.setRawValue(obj[minLengthKey]);
} else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
}
}
// load reference
{
QString e;
QList<JsonHelper::KeyValidateInfo> keyInfo = {
{referenceKey, QJsonValue::Array, true},
};
if (JsonHelper::validateKeys(obj, keyInfo, e)) {
QGeoCoordinate ref;
if (JsonHelper::loadGeoCoordinate(obj[referenceKey], false, ref, e)) {
setReference(ref);
} else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
}
} else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
}
}
return returnValue;
}
void CircularGenerator::resetReferenceIfInvalid() {
if (!this->_reference.isValid()) {
......
......@@ -47,10 +47,6 @@ public:
virtual bool load(const QJsonObject &obj, QString &guiErrorMessage) override;
static const char *settingsGroup;
static const char *distanceName;
static const char *deltaAlphaName;
static const char *minLengthName;
static const char *refPointName;
signals:
void referenceChanged();
......
......@@ -19,9 +19,9 @@ bool linearTransects(const snake::FPolygon &polygon,
snake::Length minLength, snake::Transects &transects);
const char *LinearGenerator::settingsGroup = "LinearGenerator";
const char *LinearGenerator::distanceName = "TransectDistance";
const char *LinearGenerator::alphaName = "Alpha";
const char *LinearGenerator::minLengthName = "MinLength";
const char *LinearGenerator::distanceKey = "TransectDistance";
const char *LinearGenerator::alphaKey = "Alpha";
const char *LinearGenerator::minLenghKey = "MinLength";
LinearGenerator::LinearGenerator(QObject *parent)
: LinearGenerator(nullptr, parent) {}
......@@ -30,9 +30,9 @@ LinearGenerator::LinearGenerator(GeneratorBase::Data d, QObject *parent)
: GeneratorBase(d, parent),
_metaDataMap(FactMetaData::createMapFromJsonFile(
QStringLiteral(":/json/LinearGenerator.SettingsGroup.json"), this)),
_distance(settingsGroup, _metaDataMap[distanceName]),
_alpha(settingsGroup, _metaDataMap[alphaName]),
_minLength(settingsGroup, _metaDataMap[minLengthName]),
_distance(settingsGroup, _metaDataMap[distanceKey]),
_alpha(settingsGroup, _metaDataMap[alphaKey]),
_minLength(settingsGroup, _metaDataMap[minLenghKey ),
_measurementArea(nullptr), _safeArea(nullptr) {
connect(this->distance(), &Fact::rawValueChanged, this,
&GeneratorBase::generatorChanged);
......@@ -150,49 +150,95 @@ bool LinearGenerator::get(Generator &generator) {
}
bool LinearGenerator::save(QJsonObject &obj) const {
// QJsonObject temp;
// bool ok = false;
// auto variant = _distance.rawValue();
// auto val = variant.toDouble(ok);
// if (!ok) {
// qCDebug(LinearGeneratorLog)
// << "save(): not able to save distance. Not a double: "
// << variant.typeName();
// return false;
// } else {
// temp[distanceName] = val;
// }
// variant = _alpha.rawValue();
// val = variant.toDouble(ok);
// if (!ok) {
// qCDebug(LinearGeneratorLog)
// << "save(): not able to save alpha. Not a double: "
// << variant.typeName();
// return false;
// } else {
// temp[alphaName] = val;
// }
// variant = _minLength.rawValue();
// val = variant.toDouble(ok);
// if (!ok) {
// qCDebug(LinearGeneratorLog)
// << "save(): not able to save minLength. Not a double: "
// << variant.typeName();
// return false;
// } else {
// temp[minLengthName] = val;
// }
// obj = std::move(temp);
QJsonObject temp;
bool ok = false;
auto variant = _distance.rawValue();
auto val = variant.toDouble(&ok);
if (!ok) {
qCDebug(LinearGeneratorLog)
<< "save(): not able to save distance. Not a double: "
<< variant.typeName();
return false;
} else {
temp[distanceKey] = val;
}
variant = _alpha.rawValue();
val = variant.toDouble(&ok);
if (!ok) {
qCDebug(LinearGeneratorLog)
<< "save(): not able to save alpha. Not a double: "
<< variant.typeName();
return false;
} else {
temp[alphaKey] = val;
}
variant = _minLength.rawValue();
val = variant.toDouble(&ok);
if (!ok) {
qCDebug(LinearGeneratorLog)
<< "save(): not able to save minLength. Not a double: "
<< variant.typeName();
return false;
} else {
temp[minLenghKey = val;
}
obj = std::move(temp);
return true;
}
bool LinearGenerator::load(const QJsonObject &obj, QString &guiErrorString) {
qWarning() << "LinearGenerator::load() impl. missing";
return true;
bool LinearGenerator::load(const QJsonObject &obj, QString &errorString) {
bool returnValue = true;
// load distance
{
QString e;
QList<JsonHelper::KeyValidateInfo> keyInfo = {
{distanceKey, QJsonValue::Double, true},
};
if (JsonHelper::validateKeys(obj, keyInfo, e)) {
_distance.setRawValue(obj[distanceKey]);
} else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
}
}
// load alpha
{
QString e;
QList<JsonHelper::KeyValidateInfo> keyInfo = {
{alphaKey, QJsonValue::Double, true},
};
if (JsonHelper::validateKeys(obj, keyInfo, e)) {
_alpha.setRawValue(obj[alphaKey]);
} else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
}
}
// load distance
{
QString e;
QList<JsonHelper::KeyValidateInfo> keyInfo = {
{minLengthKey, QJsonValue::Double, true},
};
if (JsonHelper::validateKeys(obj, keyInfo, e)) {
_minLength.setRawValue(obj[minLengthKey]);
} else {
returnValue = false;
errorString.append(e);
errorString.append("\n");
}
}
return returnValue;
}
Fact *LinearGenerator::distance() { return &_distance; }
......
......@@ -36,16 +36,13 @@ public:
//! \note This methode does not save the data.
//!
virtual bool save(QJsonObject &obj) const override;
virtual bool load(const QJsonObject &obj, QString &guiErrorString) override;
virtual bool load(const QJsonObject &obj, QString &errorString) override;
Fact *distance();
Fact *alpha();
Fact *minLength();
static const char *settingsGroup;
static const char *distanceName;
static const char *alphaName;
static const char *minLengthName;
private:
void onAreaListChanged();
......
......@@ -33,7 +33,7 @@ const char *MeasurementComplexItem::jsonComplexItemTypeValue =
const char *MeasurementComplexItem::variantName = "Variant";
const char *MeasurementComplexItem::altitudeName = "Altitude";
const QString MeasurementComplexItem::name(tr("Measurement"));
const char *areaDataName = "AreaDataName";
const char *areaDataName = "AreaData";
const char *variantNamesName = "VariantNames";
const char *generatorsName = "Generators";
const char *variantsName = "Variants";
......@@ -100,14 +100,9 @@ MeasurementComplexItem::MeasurementComplexItem(
connect(this, &MeasurementComplexItem::routeChanged,
[this] { emit this->complexDistanceChanged(); });
// Register Generators.
auto lg = new routing::LinearGenerator(this->_pAreaData, this);
addGenerator(lg->name(), lg);
auto cg = new routing::CircularGenerator(this->_pAreaData, this);
addGenerator(cg->name(), cg);
resetGenerators();
qCritical() << "ToDo: _altitude connections missing.";
qCritical() << "ToDo: add generator saveing.";
}
MeasurementComplexItem::~MeasurementComplexItem() {}
......@@ -174,10 +169,7 @@ bool MeasurementComplexItem::load(const QJsonObject &complexObject,
setSequenceNumber(sequenceNumber);
if (!load(complexObject, sequenceNumber, errorString)) {
return false;
}
static_assert(false, "continue here");
_variant.setRawValue(complexObject[variantName].toInt());
_altitude.setRawValue(complexObject[altitudeName].toDouble());
......@@ -212,7 +204,7 @@ QString MeasurementComplexItem::mapVisualQML() const {
return QStringLiteral("MeasurementItemMapVisual.qml");
}
void MeasurementComplexItem::save(QJsonObject &planItems) {
void MeasurementComplexItem::save(QJsonArray &planItems) {
if (idle()) {
QJsonObject saveObject;
......@@ -227,47 +219,47 @@ void MeasurementComplexItem::save(QJsonObject &planItems) {
saveObject[altitudeName] = double(_altitude.rawValue().toUInt());
// Variant names.
QJsonObject jsonVariantNames;
QJsonArray jsonVariantNames;
for (auto const &name : _variantNames) {
jsonVariantNames.append(name);
}
saveObject[variantNamesName] = jsonVariantNames;
// AreaData.
// QJsonObject jsonAreaData;
// if (!_pAreaData->save(jsonAreaData)) {
// qCDebug(MeasurementComplexItemLog)
// << "save(): not able to save area data";
// return;
// }
// saveObject[areaDataName] = jsonAreaData;
QJsonObject jsonAreaData;
if (!_pAreaData->save(jsonAreaData)) {
qCDebug(MeasurementComplexItemLog)
<< "save(): not able to save area data";
return;
}
saveObject[areaDataName] = jsonAreaData;
// Generators.
// QJsonArray generatorArray;
// for (int i = 0; i < _generatorList.size(); ++i) {
// auto const gen = _generatorList[i];
// auto const &name = _generatorNameList[i];
// QJsonObject innerObj;
// if (!gen->save(innerObj)) {
// qCDebug(MeasurementComplexItemLog)
// << "save(): not able to save generator: " << name;
// return;
// } else {
// QJsonObject outerObj;
// outerObj[name] = innerObj;
// generatorArray.append(outerObj);
// }
// }
// saveObject[generatorsName] = generatorArray;
QJsonArray generatorArray;
for (int i = 0; i < _generatorList.size(); ++i) {
auto const gen = _generatorList[i];
auto const &name = _generatorNameList[i];
QJsonObject innerObj;
if (!gen->save(innerObj)) {
qCDebug(MeasurementComplexItemLog)
<< "save(): not able to save generator: " << name;
return;
} else {
QJsonObject outerObj;
outerObj[name] = innerObj;
generatorArray.append(outerObj);
}
}
saveObject[generatorsName] = generatorArray;
// Route Variants
QJsonObject variantsArray;
QJsonArray variantsArray;
for (auto const &route : _variantVector) {
QJsonValue variant;
if (!(route.size() == 0)) {
JsonHelper::saveGeoCoordinateArray(route, true, variant);
JsonHelper::saveGeoCoordinateArray(route, false, variant);
} else {
JsonHelper::saveGeoCoordinateArray(_route, true, variant);
JsonHelper::saveGeoCoordinateArray(_route, false, variant);
}
variantsArray.append(variant);
}
......@@ -763,6 +755,16 @@ bool MeasurementComplexItem::switchToGenerator(int index) {
}
}
void MeasurementComplexItem::resetGenerators() {
while (_generatorList.size() > 0) {
removeGenerator(0);
}
auto lg = new routing::LinearGenerator(this->_pAreaData, this);
addGenerator(lg->name(), lg);
auto cg = new routing::CircularGenerator(this->_pAreaData, this);
addGenerator(cg->name(), cg);
}
QStringList MeasurementComplexItem::generatorNameList() {
return this->_generatorNameList;
}
......
......@@ -85,7 +85,7 @@ public:
virtual void setDirty(bool dirty) override final;
virtual void setCoordinate(const QGeoCoordinate &coordinate) override final;
virtual void setSequenceNumber(int sequenceNumber) override final;
virtual void save(QJsonObject &missionItems) override final;
virtual void save(QJsonArray &missionItems) override final;
virtual double amslEntryAlt(void) const override final;
virtual double amslExitAlt(void) const override final;
virtual double minAMSLAltitude(void) const override final;
......@@ -100,6 +100,7 @@ public:
bool removeGenerator(int index);
Q_INVOKABLE bool switchToGenerator(const QString &name);
Q_INVOKABLE bool switchToGenerator(int index);
Q_INVOKABLE void resetGenerators();
QStringList generatorNameList();
routing::GeneratorBase *generator();
int generatorIndex();
......
......@@ -9,8 +9,8 @@
QGC_LOGGING_CATEGORY(GeoAreaLog, "GeoAreaLog")
const char *GeoArea::wimaAreaName = "GeoArea";
const char *GeoArea::areaTypeName = "AreaType";
const char *GeoArea::name = "GeoArea";
const char *GeoArea::areaTypeKey = "AreaType";
const char *GeoArea::settingsGroup = "GeoArea";
// Constructors
......@@ -30,8 +30,9 @@ GeoArea &GeoArea::operator=(const GeoArea &other) {
return *this;
}
void GeoArea::saveToJson(QJsonObject &json) {
bool GeoArea::saveToJson(QJsonObject &json) {
this->QGCMapPolygon::saveToJson(json);
return true;
}
bool GeoArea::loadFromJson(const QJsonObject &json, QString &errorString) {
......@@ -80,7 +81,7 @@ bool GeoArea::covers(const QGeoCoordinate &c) {
}
void GeoArea::init() {
this->setObjectName(wimaAreaName);
this->setObjectName(name);
// connect(this, &GeoArea::pathChanged, [this] {
// if (this->objectName() != "Tile") {
// qDebug() << this->objectName() << " path: " << this->path() << "\n";
......
......@@ -18,7 +18,7 @@ public:
virtual QString mapVisualQML(void) const = 0;
virtual QString editorQML(void) const = 0;
virtual void saveToJson(QJsonObject &jsonObject);
virtual bool saveToJson(QJsonObject &jsonObject);
virtual bool loadFromJson(const QJsonObject &jsonObject,
QString &errorString);
......@@ -35,8 +35,8 @@ public:
Q_INVOKABLE bool covers(const QGeoCoordinate &c);
// static Members
static const char *wimaAreaName;
static const char *areaTypeName;
static const char *name;
static const char *areaTypeKey;
static const char *settingsGroup;
signals:
......
......@@ -64,25 +64,25 @@ size_t TileData::size() const {
}
const char *MeasurementArea::settingsGroup = "MeasurementArea";
const char *MeasurementArea::tileHeightName = "TileHeight";
const char *MeasurementArea::tileHeightKey = "TileHeight";
const char *MeasurementArea::tileWidthName = "TileWidth";
const char *MeasurementArea::minTileAreaName = "MinTileAreaPercent";
const char *MeasurementArea::showTilesName = "ShowTiles";
const char *MeasurementArea::measurementAreaName = "Measurement Area";
const char *MeasurementArea::minTileAreaKey = "MinTileAreaPercent";
const char *MeasurementArea::showTilesKey = "ShowTiles";
const char *MeasurementArea::name = "Measurement Area";
MeasurementArea::MeasurementArea(QObject *parent)
: GeoArea(parent),
_metaDataMap(FactMetaData::createMapFromJsonFile(
QStringLiteral(":/json/MeasurementArea.SettingsGroup.json"),
this /* QObject parent */)),
_tileHeight(SettingsFact(settingsGroup, _metaDataMap[tileHeightName],
_tileHeight(SettingsFact(settingsGroup, _metaDataMap[tileHeightKey],
this /* QObject parent */)),
_tileWidth(SettingsFact(settingsGroup, _metaDataMap[tileWidthName],
this /* QObject parent */)),
_minTileAreaPercent(SettingsFact(settingsGroup,
_metaDataMap[minTileAreaName],
_metaDataMap[minTileAreaKey],
this /* QObject parent */)),
_showTiles(SettingsFact(settingsGroup, _metaDataMap[showTilesName],
_showTiles(SettingsFact(settingsGroup, _metaDataMap[showTilesKey],
this /* QObject parent */)),
_state(STATE::IDLE) {
init();
......@@ -93,14 +93,14 @@ MeasurementArea::MeasurementArea(const MeasurementArea &other, QObject *parent)
_metaDataMap(FactMetaData::createMapFromJsonFile(
QStringLiteral(":/json/MeasurementArea.SettingsGroup.json"),
this /* QObject parent */)),
_tileHeight(SettingsFact(settingsGroup, _metaDataMap[tileHeightName],
_tileHeight(SettingsFact(settingsGroup, _metaDataMap[tileHeightKey],
this /* QObject parent */)),
_tileWidth(SettingsFact(settingsGroup, _metaDataMap[tileWidthName],
this /* QObject parent */)),
_minTileAreaPercent(SettingsFact(settingsGroup,
_metaDataMap[minTileAreaName],
_metaDataMap[minTileAreaKey],
this /* QObject parent */)),
_showTiles(SettingsFact(settingsGroup, _metaDataMap[showTilesName],
_showTiles(SettingsFact(settingsGroup, _metaDataMap[showTilesKey],
this /* QObject parent */)),
_state(STATE::IDLE) {
init();
......@@ -186,17 +186,29 @@ int MeasurementArea::maxTiles() const { return SNAKE_MAX_TILES; }
bool MeasurementArea::ready() const { return this->_state == STATE::IDLE; }
void MeasurementArea::saveToJson(QJsonObject &json) {
const char *MeasurementArea::getTileWidthName() { return tileWidthName; }
void MeasurementArea::setTileWidthName(const char *value) {
tileWidthName = value;
}
bool MeasurementArea::saveToJson(QJsonObject &json) {
if (ready()) {
this->GeoArea::saveToJson(json);
json[tileHeightName] = _tileHeight.rawValue().toDouble();
json[tileWidthName] = _tileWidth.rawValue().toDouble();
json[minTileAreaName] = _minTileAreaPercent.rawValue().toDouble();
json[showTilesName] = _showTiles.rawValue().toBool();
json[areaTypeName] = measurementAreaName;
if (this->GeoArea::saveToJson(json)) {
json[tileHeightKey] = _tileHeight.rawValue().toDouble();
json[tileWidthName] = _tileWidth.rawValue().toDouble();
json[minTileAreaKey] = _minTileAreaPercent.rawValue().toDouble();
json[showTilesKey] = _showTiles.rawValue().toBool();
json[areaTypeKey] = name;
return true;
} else {
qCDebug(MeasurementAreaLog)
<< "saveToJson(): error inside GeoArea::saveToJson().";
}
} else {
qCDebug(MeasurementAreaLog) << "saveToJson(): not ready for saveing.";
qCDebug(MeasurementAreaLog) << "saveToJson(): not ready().";
}
return false;
}
bool MeasurementArea::loadFromJson(const QJsonObject &json,
......@@ -205,11 +217,11 @@ bool MeasurementArea::loadFromJson(const QJsonObject &json,
disableUpdate();
bool retVal = true;
if (!json.contains(tileHeightName) || !json[tileHeightName].isDouble()) {
if (!json.contains(tileHeightKey) || !json[tileHeightKey].isDouble()) {
errorString.append(tr("Could not load tile height!\n"));
retVal = false;
} else {
_tileHeight.setRawValue(json[tileHeightName].toDouble());
_tileHeight.setRawValue(json[tileHeightKey].toDouble());
}
if (!json.contains(tileWidthName) || !json[tileWidthName].isDouble()) {
......@@ -219,18 +231,18 @@ bool MeasurementArea::loadFromJson(const QJsonObject &json,
_tileWidth.setRawValue(json[tileWidthName].toDouble());
}
if (!json.contains(minTileAreaName) || !json[minTileAreaName].isDouble()) {
if (!json.contains(minTileAreaKey) || !json[minTileAreaKey].isDouble()) {
errorString.append(tr("Could not load minimal tile area!\n"));
retVal = false;
} else {
_minTileAreaPercent.setRawValue(json[minTileAreaName].toDouble());
_minTileAreaPercent.setRawValue(json[minTileAreaKey].toDouble());
}
if (!json.contains(showTilesName) || !json[showTilesName].isBool()) {
if (!json.contains(showTilesKey) || !json[showTilesKey].isBool()) {
errorString.append(tr("Could not load show tiles !\n"));
retVal = false;
} else {
_showTiles.setRawValue(json[showTilesName].toBool());
_showTiles.setRawValue(json[showTilesKey].toBool());
}
enableUpdate();
......@@ -402,7 +414,7 @@ void MeasurementArea::enableUpdate() {
}
void MeasurementArea::init() {
this->setObjectName(measurementAreaName);
this->setObjectName(name);
connect(&this->_tileHeight, &Fact::rawValueChanged, this,
&MeasurementArea::deferUpdate);
connect(&this->_tileWidth, &Fact::rawValueChanged, this,
......
......@@ -48,7 +48,7 @@ public:
QString mapVisualQML(void) const override;
QString editorQML(void) const override;
MeasurementArea *clone(QObject *parent = nullptr) const;
void saveToJson(QJsonObject &json) override;
bool saveToJson(QJsonObject &json) override;
bool loadFromJson(const QJsonObject &json, QString &errorString) override;
Q_INVOKABLE virtual bool isCorrect();
......@@ -68,11 +68,10 @@ public:
// Static Variables
static const char *settingsGroup;
static const char *tileHeightName;
static const char *tileWidthName;
static const char *minTileAreaName;
static const char *showTilesName;
static const char *measurementAreaName;
static const char *name;
static const char *getTileWidthName();
static void setTileWidthName(const char *value);
signals:
void tilesChanged();
......
#include "SafeArea.h"
#include "JsonHelper.h"
#include "QGCLoggingCategory.h"
#include "QGCQGeoCoordinate.h"
......@@ -7,10 +8,8 @@
QGC_LOGGING_CATEGORY(SafeAreaLog, "SafeAreaLog")
const char *SafeArea::safeAreaName = "Safe Area";
const char *SafeArea::depotLatitudeName = "DepotLatitude";
const char *SafeArea::depotLongitudeName = "DepotLongitude";
const char *SafeArea::depotAltitudeName = "DepotAltitude";
const char *SafeArea::name = "Safe Area";
const char *SafeArea::depotKey = "Depot Point";
SafeArea::SafeArea(QObject *parent) : GeoArea(parent) { init(); }
......@@ -83,43 +82,42 @@ bool SafeArea::setDepot(const QGeoCoordinate &newDepot) {
return false;
}
void SafeArea::saveToJson(QJsonObject &json) {
this->GeoArea::saveToJson(json);
json[areaTypeName] = safeAreaName;
json[depotLatitudeName] = _depot.latitude();
json[depotLongitudeName] = _depot.longitude();
json[depotAltitudeName] = _depot.altitude();
bool SafeArea::saveToJson(QJsonObject &json) {
if (this->GeoArea::saveToJson(json)) {
json[areaTypeKey] = name;
QJsonValue jsonDepot;
JsonHelper::saveGeoCoordinate(_depot, false, jsonDepot);
json[depotKey] = jsonDepot;
return true;
} else {
qCDebug(SafeAreaLog) << "saveToJson(): error in GeoArea::safeToJson()";
}
return false;
}
bool SafeArea::loadFromJson(const QJsonObject &json, QString &errorString) {
bool retVal = false;
if (this->GeoArea::loadFromJson(json, errorString)) {
double lat = 0;
if (json.contains(depotLatitudeName) &&
json[depotLatitudeName].isDouble()) {
lat = json[depotLatitudeName].toDouble();
double lon = 0;
if (json.contains(depotLongitudeName) &&
json[depotLongitudeName].isDouble()) {
lon = json[depotLongitudeName].toDouble();
double alt = 0;
if (json.contains(depotAltitudeName) &&
json[depotAltitudeName].isDouble()) {
alt = json[depotAltitudeName].toDouble();
this->setDepot(QGeoCoordinate(lat, lon, alt));
retVal = true;
} else {
errorString = "Not able to load depot altitude.";
}
} else {
errorString = "Not able to load depot longitude.";
}
} else {
errorString = "Not able to load depot latitude.";
bool returnValue = true;
if (!this->GeoArea::loadFromJson(json, errorString)) {
returnValue = false;
}
QList<JsonHelper::KeyValidateInfo> versionKeyInfoList = {
{depotKey, QJsonValue::Array, true},
};
if (!JsonHelper::validateKeys(complexObject, versionKeyInfoList,
errorString)) {
returnValue = false;
} else {
const auto &jsonDepot = json[depotKey];
if (!JsonHelper::loadGeoCoordinate(jsonDepot, false, _depot, errorString)) {
returnValue = false;
}
retVal = true;
}
return retVal;
return returnValue;
}
bool SafeArea::isCorrect() {
......@@ -138,6 +136,6 @@ bool SafeArea::isCorrect() {
}
void SafeArea::init() {
this->setObjectName(safeAreaName);
this->setObjectName(name);
connect(this, &GeoArea::pathChanged, this, &SafeArea::putDepotInside);
}
......@@ -17,7 +17,7 @@ public:
QString mapVisualQML(void) const override;
QString editorQML(void) const override;
SafeArea *clone(QObject *parent = nullptr) const;
void saveToJson(QJsonObject &json) override;
bool saveToJson(QJsonObject &json) override;
bool loadFromJson(const QJsonObject &json, QString &errorString) override;
Q_INVOKABLE virtual bool isCorrect();
......@@ -27,10 +27,8 @@ public:
QGeoCoordinate depotQml(void) const;
// static Members
static const char *safeAreaName;
static const char *depotLatitudeName;
static const char *depotLongitudeName;
static const char *depotAltitudeName;
static const char *name;
signals:
void depotChanged(void);
private slots:
......
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