Commit 96ac6aeb authored by Valentin Platzgummer's avatar Valentin Platzgummer

MeasurementComplexItem loading done.

parent f778e405
#include "MeasurementComplexItem.h" #include "MeasurementComplexItem.h"
#include "CircularGenerator.h" #include "CircularGenerator.h"
#include "LinearGenerator.h" #include "LinearGenerator.h"
...@@ -39,7 +39,7 @@ const char *areaDataKey = "AreaData"; ...@@ -39,7 +39,7 @@ const char *areaDataKey = "AreaData";
const char *variantNamesKey = "VariantNames"; const char *variantNamesKey = "VariantNames";
const char *generatorsKey = "Generators"; const char *generatorsKey = "Generators";
const char *variantsKey = "Variants"; const char *variantsKey = "Variants";
const char *generatorIndexKey = "generatorIndex"; const char *generatorIndexKey = "GeneratorIndex";
} // namespace } // namespace
MeasurementComplexItem::MeasurementComplexItem( MeasurementComplexItem::MeasurementComplexItem(
...@@ -367,6 +367,54 @@ bool MeasurementComplexItem::load(const QJsonObject &complexObject, ...@@ -367,6 +367,54 @@ bool MeasurementComplexItem::load(const QJsonObject &complexObject,
} else { } else {
_variantVector.swap(variantVector); _variantVector.swap(variantVector);
qCritical() << "add variant names and set variant"; qCritical() << "add variant names and set variant";
// load variant names
bool variantNamesLoaded = true;
if (complexObject.contains(variantNamesKey) &&
complexObject[variantNamesKey].isArray()) {
QStringList variantNames;
for (const auto &name : complexObject[variantNamesKey]) {
if (name.isString()) {
variantNames.append(name.toString());
} else {
variantNamesLoaded = false;
break;
}
}
if (variantNames.size() != _variantVector.size()) {
variantNamesLoaded = false;
}
if (variantNamesLoaded) {
_variantNames.swap(variantNames);
emit variantNamesChanged();
}
} else {
qCWarning(MeasurementComplexItemLog)
<< "Not able to load variant names. variantNamesKey missing or wrong "
"type";
if (complexObject.contains(variantNamesKey)) {
qCWarning(MeasurementComplexItemLog)
<< "variantNamesKey type: "
<< complexObject[variantNamesKey].type();
}
}
// create std. variant names if loading failed
if (!variantNamesLoaded) {
qCWarning(MeasurementComplexItemLog) << "Creating std. variant names.";
this->_variantNames.clear();
for (std::size_t i = 1; i <= std::size_t(this->_variantVector.size());
++i) {
this->_variantNames.append(QString::number(i));
}
emit variantNamesChanged();
}
_changeVariant();
stopEditing( stopEditing(
false /*doUpdate*/); // does noting if editing was already stopped false /*doUpdate*/); // does noting if editing was already stopped
} }
...@@ -448,7 +496,7 @@ void MeasurementComplexItem::save(QJsonArray &planItems) { ...@@ -448,7 +496,7 @@ void MeasurementComplexItem::save(QJsonArray &planItems) {
saveObject[generatorsKey] = generatorArray; saveObject[generatorsKey] = generatorArray;
// generator index // generator index
saveObject[generatorIndex] = generatorIndex(); saveObject[generatorIndexKey] = generatorIndex();
// Route Variants // Route Variants
QJsonArray variantsArray; QJsonArray variantsArray;
...@@ -752,7 +800,7 @@ void MeasurementComplexItem::_changeVariant() { ...@@ -752,7 +800,7 @@ void MeasurementComplexItem::_changeVariant() {
if (idle()) { if (idle()) {
auto variant = this->_variant.rawValue().toUInt(); auto variant = this->_variant.rawValue().toUInt();
// Find old variant and run. Old run corresponts with empty list. // Find old variant. Old variant corresponts with empty list.
std::size_t old_variant = std::numeric_limits<std::size_t>::max(); std::size_t old_variant = std::numeric_limits<std::size_t>::max();
for (std::size_t i = 0; i < std::size_t(this->_variantVector.size()); ++i) { for (std::size_t i = 0; i < std::size_t(this->_variantVector.size()); ++i) {
const auto &variantCoordinates = this->_variantVector.at(i); const auto &variantCoordinates = this->_variantVector.at(i);
......
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