#pragma once

#include <QObject>
#include "WimaPolygon.h"
#include "QGCMapPolyline.h"
#include "QGCMapPolygon.h"
#include "WimaVehicleMeasurementPolygon.h"
#include "SettingsFact.h"

#include "QScopedPointer"

class WimaGlobalMeasurementPolygon : public WimaPolygon
{
    Q_OBJECT
public:
    WimaGlobalMeasurementPolygon(QObject* parent);
    WimaGlobalMeasurementPolygon(QGCMapPolygon* other, QObject* parent);

    Q_PROPERTY(Fact*                    bottomLayerAltitude         READ bottomLayerAltitude                                            CONSTANT)
    Q_PROPERTY(Fact*                    numberOfLayers              READ numberOfLayers                                                 CONSTANT)
    Q_PROPERTY(Fact*                    layerDistance               READ layerDistance                                                  CONSTANT)
    Q_PROPERTY(QmlObjectListModel*      vehicleList                 READ vehicleList                                                    NOTIFY vehicleListChanged)
    Q_PROPERTY(QmlObjectListModel*      vehiclePolygons             READ vehiclePolygons                                                NOTIFY vehiclePolygonsChanged)
    Q_PROPERTY(WimaPolyline*            polyline                    READ polyline                                                       NOTIFY polylineChanged)


    Q_INVOKABLE void addVehicle                 (Vehicle *vehicle);
    Q_INVOKABLE void removeVehicle              (int vehicleIndex);
    Q_INVOKABLE void recalculatesubPolygons     ();
    Q_INVOKABLE void removeAllVehicles          ();
    Q_INVOKABLE void addVehiclePolygon          ();
    Q_INVOKABLE void removeVehiclePolygon       (int polygonIndex);
    Q_INVOKABLE void removeVehiclePolygon       (WimaVehicleMeasurementPolygon *wimaPolygon);


    // Overrides from WimaPolygon
    QString         mapVisualQML    (void) const { return "WimaGlobalMeasurementPolygonMapVisual.qml";}
    QString         editorQML       (void) const { return "WimaGlobalMeasurementPolygonEditor.qml";}

    // Property accessors
    Fact*                               bottomLayerAltitude     (void)       { return &_bottomLayerAltitude;}
    Fact*                               numberOfLayers          (void)       { return &_numberOfLayers;}
    Fact*                               layerDistance           (void)       { return &_layerDistance;}
    QmlObjectListModel*                 vehicleList             (void) const { return _vehicleList;}
    QmlObjectListModel*                 vehiclePolygons         (void) const { return _vehiclePolygons;}
    WimaPolyline*                       polyline                (void)       { return &_polyline;}


    static const char* settingsGroup;
    static const char* bottomLayerAltitudeName;
    static const char* numberOfLayersName;
    static const char* layerDistanceName;


signals:
    void bottomLayerAltitudeChanged     (void);
    void numberOfLayersChanged          (void);
    void layerDistanceChanged           (void);
    void vehicleListChanged             (void);
    void gatewayPolylinesChanged        (void);
    void vehiclePolygonsChanged         (void);


private:
    QMap<QString, FactMetaData*> _metaDataMap;

    SettingsFact            _bottomLayerAltitude;
    SettingsFact            _numberOfLayers;
    SettingsFact            _layerDistance;


    QmlObjectListModel*     _vehicleList;
    QmlObjectListModel*     _vehiclePolygons;
    WimaPolyline            _polyline;



};


