Commit 44b635f9 authored by Valentin Platzgummer's avatar Valentin Platzgummer

error removed: max_tiles yielded wrong error messages

parent 558239cf
......@@ -41,6 +41,7 @@ const char *tileWidthName = "TileWidth";
const char *minTileAreaKey = "MinTileAreaPercent";
const char *showTilesKey = "ShowTiles";
const char *tileKey = "Tiles";
const char *toManyTilesKey = "ToManyTiles";
const char *MeasurementArea::nameString = "Measurement Area";
MeasurementArea::MeasurementArea(QObject *parent)
......@@ -57,7 +58,8 @@ MeasurementArea::MeasurementArea(QObject *parent)
this /* QObject parent */)),
_showTiles(SettingsFact(settingsGroup, _metaDataMap[showTilesKey],
this /* QObject parent */)),
_tiles(new QmlObjectListModel()), _state(STATE::IDLE) {
_toManyTiles(false), _tiles(new QmlObjectListModel()),
_state(STATE::IDLE) {
init();
}
......@@ -75,7 +77,8 @@ MeasurementArea::MeasurementArea(const MeasurementArea &other, QObject *parent)
this /* QObject parent */)),
_showTiles(SettingsFact(settingsGroup, _metaDataMap[showTilesKey],
this /* QObject parent */)),
_tiles(new QmlObjectListModel()), _state(STATE::IDLE) {
_toManyTiles(other._toManyTiles), _tiles(new QmlObjectListModel()),
_state(STATE::IDLE) {
init();
disableUpdate();
......@@ -115,6 +118,7 @@ MeasurementArea &MeasurementArea::operator=(const MeasurementArea &other) {
->clone(_tiles.get()));
}
_indexMap = other._indexMap;
_toManyTiles = other._toManyTiles;
enableUpdate();
} else {
enableUpdate();
......@@ -178,6 +182,7 @@ bool MeasurementArea::saveToJson(QJsonObject &json) {
json[minTileAreaKey] = _minTileAreaPercent.rawValue().toDouble();
json[showTilesKey] = _showTiles.rawValue().toBool();
json[areaTypeKey] = nameString;
json[toManyTilesKey] = _toManyTiles;
// save tiles
QJsonArray jsonTileArray;
......@@ -253,40 +258,46 @@ bool MeasurementArea::loadFromJson(const QJsonObject &json,
break;
}
}
}
if (!tileError) {
this->_indexMap.clear();
for (int i = 0; i < _tiles->count(); ++i) {
auto tile = qobject_cast<MeasurementTile *>(_tiles->get(i));
auto it = _indexMap.find(tile->id());
// find unique id
if (it != _indexMap.end()) {
auto newId = MeasurementTile::randomId();
constexpr long counterMax = 1e6;
unsigned long counter = 0;
for (; counter <= counterMax; ++counter) {
it = _indexMap.find(newId);
if (it == _indexMap.end()) {
break;
} else {
newId = MeasurementTile::randomId();
}
}
if (json.contains(toManyTilesKey) && json[toManyTilesKey].isBool()) {
_toManyTiles = json[toManyTilesKey].toBool();
} else {
tileError = true;
}
if (!tileError) {
this->_indexMap.clear();
for (int i = 0; i < _tiles->count(); ++i) {
if (counter != counterMax) {
tile->setId(newId);
tile->setProgress(0.0);
auto tile = qobject_cast<MeasurementTile *>(_tiles->get(i));
auto it = _indexMap.find(tile->id());
// find unique id
if (it != _indexMap.end()) {
auto newId = MeasurementTile::randomId();
constexpr long counterMax = 1e6;
unsigned long counter = 0;
for (; counter <= counterMax; ++counter) {
it = _indexMap.find(newId);
if (it == _indexMap.end()) {
break;
} else {
qCritical() << "MeasurementArea::storeTiles(): not able to find "
"unique id!";
continue;
newId = MeasurementTile::randomId();
}
}
_indexMap.insert(std::make_pair(tile->id(), i));
if (counter != counterMax) {
tile->setId(newId);
tile->setProgress(0.0);
} else {
qCritical() << "MeasurementArea::storeTiles(): not able to find "
"unique id!";
continue;
}
}
_indexMap.insert(std::make_pair(tile->id(), i));
}
} else {
qCWarning(MeasurementAreaLog)
......@@ -314,11 +325,15 @@ bool MeasurementArea::isCorrect() {
if (GeoArea::isCorrect()) {
if (ready()) {
return true;
} else {
} else if (_toManyTiles) {
setErrorString(
tr("Calculation would yield to many tiles, please adjust the tile "
"parameters to reduce the number of tiles."));
} else
setErrorString(
tr("Measurement Area tile calculation in progess. Please wait."));
}
}
return false;
}
......@@ -406,8 +421,10 @@ void MeasurementArea::doUpdate() {
const auto totalArea = this->area() * si::meter * si::meter;
const auto estNumTiles = totalArea / tileArea;
// Check some conditions.
if (long(std::ceil(estNumTiles.value())) <= MAX_TILES &&
this->GeoArea::isCorrect()) {
if (long(std::ceil(estNumTiles.value())) >= MAX_TILES) {
_toManyTiles = true;
} else if (this->GeoArea::isCorrect()) {
_toManyTiles = false;
setState(STATE::UPDATEING);
auto polygon = this->coordinateList();
......
......@@ -12,25 +12,6 @@
#include "SettingsFact.h"
class TileData : public QObject {
public:
TileData();
~TileData();
TileData &operator=(const TileData &other);
bool operator==(const TileData &other) const;
bool operator!=(const TileData &other) const;
void saveToJson(QJsonObject &json);
bool loadFromJson(const QJsonObject &json, QString &errorString);
void clear();
std::size_t size() const;
QmlObjectListModel tiles;
QVariantList tileCenterPoints;
};
class MeasurementArea : public GeoArea {
Q_OBJECT
enum class STATE { IDLE, DEFERED, UPDATEING, RESTARTING, STOP };
......@@ -106,6 +87,7 @@ private:
SettingsFact _showTiles;
// Tile stuff.
bool _toManyTiles;
TilePtr _tiles;
std::map<QString /*id*/, int> _indexMap;
QTimer _timer;
......
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