WimaServiceArea.cc 1.67 KB
Newer Older
1 2
#include "WimaServiceArea.h"

3
const char *WimaServiceArea::wimaServiceAreaName = "Service Area";
4

5
WimaServiceArea::WimaServiceArea(QObject *parent) : WimaArea(parent) { init(); }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
6

7
WimaServiceArea::WimaServiceArea(const WimaServiceArea &other, QObject *parent)
8 9
    : WimaArea(other, parent) {
  init();
10 11
}

12 13 14 15 16
/*!
 * \overload operator=()
 *
 * Calls the inherited operator WimaArea::operator=().
 */
17 18
WimaServiceArea &WimaServiceArea::operator=(const WimaServiceArea &other) {
  WimaArea::operator=(other);
19

20
  return *this;
21 22
}

23 24 25 26 27
void WimaServiceArea::setDepot(const QGeoCoordinate &coordinate) {
  if (_depot != coordinate) {
    _depot = coordinate;
    emit depotChanged();
  }
28 29
}

30 31 32
void WimaServiceArea::saveToJson(QJsonObject &json) {
  this->WimaArea::saveToJson(json);
  json[areaTypeName] = wimaServiceAreaName;
33 34
}

35 36 37 38 39 40 41 42 43 44
bool WimaServiceArea::loadFromJson(const QJsonObject &json,
                                   QString &errorString) {
  if (this->WimaArea::loadFromJson(json, errorString)) {
    bool retVal = true;
    // code for loading here
    return retVal;
  } else {
    qWarning() << errorString;
    return false;
  }
45 46
}

47 48 49 50
void print(const WimaServiceArea &area) {
  QString message;
  print(area, message);
  qWarning() << message;
51 52
}

53 54 55 56
void print(const WimaServiceArea &area, QString &outputStr) {
  print(static_cast<const WimaArea &>(area), outputStr);
  outputStr.append(QString("Depot Position: %s\n")
                       .arg(area._depot.toString(QGeoCoordinate::Degrees)));
57 58
}

59 60 61 62 63 64 65
void WimaServiceArea::init() {
  this->setObjectName(wimaServiceAreaName);
  connect(this, &WimaServiceArea::centerChanged, [this] {
    if (!this->_depot.isValid()) {
      this->setDepot(this->center());
    }
  });
66
}