AreaData.h 3.17 KB
Newer Older
1 2 3
#pragma once

#include <QGeoCoordinate>
4
#include <QJsonObject>
5
#include <QObject>
6
#include <QString>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

#include "QmlObjectListModel.h"

class GeoArea;
class SafeArea;
class MeasurementArea;

class AreaData : public QObject {
  Q_OBJECT
public:
  AreaData(QObject *parent = nullptr);
  ~AreaData();
  AreaData(const AreaData &other, QObject *parent = nullptr);
  AreaData &operator=(const AreaData &other);

Valentin Platzgummer's avatar
Valentin Platzgummer committed
22
  Q_PROPERTY(QmlObjectListModel *areaList READ areaList NOTIFY areaListChanged)
23 24
  Q_PROPERTY(bool showErrorMessages READ showErrorMessages WRITE
                 setShowErrorMessages NOTIFY showErrorMessagesChanged)
Valentin Platzgummer's avatar
Valentin Platzgummer committed
25

26 27 28 29 30 31 32 33
  // Member Methodes
  //!
  //! \brief insert Inserts the area if areaList does not contain it.
  //! \param areaData
  bool insert(GeoArea *areaData);
  //!
  //! \brief remove
  //! \param areaData Removes the area.
34 35
  //! \note Deletes the area if it has either no parent or the parent is this
  //! object.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  void remove(GeoArea *areaData);
  void clear();
  //!
  //! \brief areaList
  //! \return Returns the list of areas.
  //! \note For Qml use only, don't alter the list, or risk to break invariants.
  QmlObjectListModel *areaList();
  //!
  //! \brief areaList
  //! \return Returns the list of areas.
  const QmlObjectListModel *areaList() const;

  //!
  //! \brief origin
  //! \return Returns an origin near one of the areas.
  //! \note Origin might change if the list of areas changes.
52
  QGeoCoordinate origin() const;
53

54
  Q_INVOKABLE bool isCorrect();
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
  //!
  //! \brief initialize Initializes the areas in a valid way, such that they
  //! area inside the bounding box. \param bottomLeft bottom left corner of the
  //! bounding box. \param topRight  top right corner of the bounding box. \note
  //! Behavior is undefined, if \p bottomLeft and \p topRight are not the bottom
  //! left and the top right corner of the bounding box. \return Returns true on
  //! succes, false either.
  //!
  Q_INVOKABLE bool initialize(const QGeoCoordinate &bottomLeft,
                              const QGeoCoordinate &topRight);
  //!
  //! \brief initialized Checks if area data is initialized
  //! \return Returns true if area list contains a SafeArea and a
  //! MeasurementArea and both areas have atleast three vertices, returns false
  //! either.
  //!
  Q_INVOKABLE bool initialized();
72
  Q_INVOKABLE void intersection();
73 74 75 76

  bool operator==(const AreaData &other) const;
  bool operator!=(const AreaData &other) const;

77 78
  bool load(const QJsonObject &obj, QString &errorString);
  bool save(QJsonObject &obj);
79

80 81 82 83 84
  QString errorString() const; // Contains a message about the last error.

  bool showErrorMessages() const;
  void setShowErrorMessages(bool showErrorMessages);

85 86 87
signals:
  void areaListChanged();
  void originChanged();
88 89 90 91
  void error(); // Emitted if errorString() contains a new message.
  void showErrorMessagesChanged();
private slots:
  void _updateOrigin();
92 93 94

private:
  void _setOrigin(const QGeoCoordinate &origin);
95 96 97
  void _processError(const QString &str);
  bool _areasCorrect();
  bool _getAreas(MeasurementArea **measurementArea, SafeArea **safeArea);
98 99 100

  QGeoCoordinate _origin;
  QmlObjectListModel _areaList;
101 102 103
  bool _initialized;
  QString _errorString;
  bool _showErrorMessages;
104
};