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