WimaFlyArea.cc 1.74 KB
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
1 2 3
#include "WimaFlyArea.h"

WimaFlyArea::WimaFlyArea(QObject *parent) : QObject(parent)
4
  , _polygons             (nullptr)
Valentin Platzgummer's avatar
Valentin Platzgummer committed
5
{
6

Valentin Platzgummer's avatar
Valentin Platzgummer committed
7 8 9 10 11 12 13 14 15
}

WimaFlyArea::WimaFlyArea(const WimaFlyArea &other, QObject *parent): QObject(parent)
{
    *this = other;
}

const WimaFlyArea& WimaFlyArea::operator=(const WimaFlyArea& other)
{
16
    this->_polygons = other._polygons;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
17 18 19
    return *this;
}

20 21 22 23 24
void WimaFlyArea::_init()
{
    _polygons = new QmlObjectListModel(this);
}

25 26 27


void WimaFlyArea::appendFlyAreaPolygon()
Valentin Platzgummer's avatar
Valentin Platzgummer committed
28
{
29 30 31
    QGCMapPolygon *newPolygon  = new QGCMapPolygon();

    _polygons->append(newPolygon);
32
    int index = _polygons->count()-1;
33
    selectCurrentPolygon(index);
34 35

    emit polygonsChanged();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
36
}
37

38 39 40 41 42 43 44 45
void WimaFlyArea::removeFlyAreaPolygon(int index)
{
    if(index >= 0 && index < _polygons->count()) {
        _polygons->removeAt(index);

        emit polygonsChanged();
    }
}
46

47
void WimaFlyArea::selectCurrentPolygon(int index)
48 49 50
{
    if(index >= 0 && index < _polygons->count()) {

51
        disselectAllPolygons();
52 53 54 55 56

        _currentPolygonIndex = index;
        _currentPolygonItem  = qobject_cast<QGCMapPolygon*>(_polygons->get(index));
        _currentPolygonItem->setInteractive(true);

57 58 59 60 61
        if(index != _currentPolygonIndex){
            emit currentPolygonItemChanged(_currentPolygonItem);
            emit currentPolygonIndexChanged(index);
        }

62 63
    }
}
64

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
void WimaFlyArea::disselectAllPolygons()
{
    for (int i = 0; i < _polygons->count(); i++) {
        QGCMapPolygon* polygon = qobject_cast<QGCMapPolygon*>(_polygons->get(i));
        polygon->setInteractive(false);
    }
}

/*void WimaFlyArea::setBottomLayerAltitude(double alt)
{
    if(_bottomLayerAltitude != alt){
        _bottomLayerAltitude = alt;
        emit bottomLayerAltitudeChanged(_bottomLayerAltitude);
    }

}*/