WimaServiceArea.cc 1.79 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
bool WimaServiceArea::setDepot(const QGeoCoordinate &coordinate) {
24
  if (_depot != coordinate) {
25 26 27 28 29
    if (this->containsCoordinate(coordinate)) {
      _depot = coordinate;
      emit depotChanged();
      return true;
    }
30
  }
31
  return false;
32 33
}

34 35 36
void WimaServiceArea::saveToJson(QJsonObject &json) {
  this->WimaArea::saveToJson(json);
  json[areaTypeName] = wimaServiceAreaName;
37 38
}

39 40 41 42 43 44 45 46 47 48
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;
  }
49 50
}

51 52 53 54
void print(const WimaServiceArea &area) {
  QString message;
  print(area, message);
  qWarning() << message;
55 56
}

57 58 59 60
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)));
61 62
}

63 64
void WimaServiceArea::init() {
  this->setObjectName(wimaServiceAreaName);
65 66
  connect(this, &WimaArea::pathChanged, [this] {
    if (!this->_depot.isValid() || !this->containsCoordinate(this->_depot)) {
67 68 69
      this->setDepot(this->center());
    }
  });
70
}