MeasurementTile.cpp 2.18 KB
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
1
#include "MeasurementTile.h"
2

Valentin Platzgummer's avatar
Valentin Platzgummer committed
3 4 5 6 7
#include <QDebug>

const char *MeasurementTile::settingsGroup = "MeasurementTile";
const char *MeasurementTile::nameString = "MeasurementTile";

8
MeasurementTile::MeasurementTile(QObject *parent)
9
    : GeoArea(parent), _progress(0), _id(MeasurementTile::randomId()) {
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
  init();
}

MeasurementTile::MeasurementTile(const MeasurementTile &other, QObject *parent)
    : GeoArea(other, parent), _progress(other._progress), _id(other._id) {
  init();
}

MeasurementTile::~MeasurementTile() {}

MeasurementTile &MeasurementTile::operator=(const MeasurementTile &other) {
  GeoArea::operator=(other);
  setProgress(other._progress);
  setId(other._id);
  return *this;
}

QString MeasurementTile::mapVisualQML() const { return QStringLiteral(""); }

QString MeasurementTile::editorQML() const { return QStringLiteral(""); }

MeasurementTile *MeasurementTile::clone(QObject *parent) const {
  return new MeasurementTile(*this, parent);
}

void MeasurementTile::push_back(const QGeoCoordinate &c) {
  this->appendVertex(c);
}

Valentin Platzgummer's avatar
Valentin Platzgummer committed
39
void MeasurementTile::init() { this->setObjectName(nameString); }
40

41
QString MeasurementTile::id() const { return _id; }
42

43
void MeasurementTile::setId(const QString &id) {
44 45 46 47 48 49
  if (_id != id) {
    _id = id;
    emit idChanged();
  }
}

Valentin Platzgummer's avatar
Valentin Platzgummer committed
50 51
QList<QGeoCoordinate> MeasurementTile::tile() const { return coordinateList(); }

52 53 54
QString MeasurementTile::randomId(int length) {
  static const QString values(
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
55 56 57 58 59 60 61 62
  static std::uint64_t counter = 0;
  static auto firstCall = std::chrono::high_resolution_clock::now();

  auto delta = std::chrono::duration_cast<std::chrono::nanoseconds>(
                   std::chrono::high_resolution_clock::now() - firstCall)
                   .count();

  std::srand((unsigned int)delta ^ counter);
63 64 65 66 67 68
  QString str;
  for (int i = 0; i < length; ++i) {
    int index = std::rand() % values.length();
    QChar c = values.at(index);
    str.append(c);
  }
69 70

  ++counter;
71 72 73
  return str;
}

74 75 76 77 78 79 80 81
double MeasurementTile::progress() const { return _progress; }

void MeasurementTile::setProgress(double progress) {
  if (_progress != progress) {
    _progress = progress;
    emit progressChanged();
  }
}