From e7ee7d09e4df77fe88dde0e327e7e9506eaf8a32 Mon Sep 17 00:00:00 2001 From: Valentin Platzgummer Date: Wed, 20 Mar 2019 15:00:36 +0100 Subject: [PATCH] before editing QGCMapPolygonVisuals.qml --- qgroundcontrol.qrc | 2 +- src/MissionManager/WimaController.cc | 10 ++-- src/MissionManager/WimaController.h | 13 ++--- src/MissionManager/WimaFlyArea.cc | 24 +++++++--- src/MissionManager/WimaFlyArea.h | 20 ++++---- src/QGCApplication.cc | 6 ++- src/WimaView/WimaView.qml | 71 +++++++++++++++++++++++++--- 7 files changed, 107 insertions(+), 39 deletions(-) diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index 317324095..aa1286816 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -210,7 +210,7 @@ src/FlightDisplay/VirtualJoystick.qml src/WimaView/WimaToolBar.qml src/WimaView/WimaView.qml - src/WimaView/FlyAreaMapVisual.qml + src/WimaView/FlyAreaMapVisual.qml src/Settings/APMMavlinkStreamRate.SettingsGroup.json diff --git a/src/MissionManager/WimaController.cc b/src/MissionManager/WimaController.cc index c507d748e..3ed4ac864 100644 --- a/src/MissionManager/WimaController.cc +++ b/src/MissionManager/WimaController.cc @@ -3,13 +3,13 @@ WimaController::WimaController(QObject *parent) : QObject(parent) { - this->_flyArea = WimaFlyArea(parent); + this->_flyArea = new WimaFlyArea(parent); } - -void WimaController::initWimaFlyArea() +void WimaController::start() { - this->_flyArea.setReady(); - return; + _flyArea->_init(); } + + diff --git a/src/MissionManager/WimaController.h b/src/MissionManager/WimaController.h index e5266fa21..0b404d307 100644 --- a/src/MissionManager/WimaController.h +++ b/src/MissionManager/WimaController.h @@ -15,17 +15,14 @@ public: Q_PROPERTY(WimaFlyArea *flyArea READ flyArea CONSTANT) //Q_PROPERTY(QmlObjectListModel* visualItems READ visualItems NOTIFY visualItemsChanged) - /// Add a fly area to the list - /// @param itemName: Name of complex item to create (from complexMissionItemNames) - /// @param mapCenterCoordinate: coordinate for current center of map - /// @param i: index to insert at - /// @return Sequence number for new item - Q_INVOKABLE void initWimaFlyArea(); + //Property Accessors - WimaFlyArea *flyArea (void) { return &_flyArea; } + WimaFlyArea *flyArea (void) { return _flyArea; } //QmlObjectListModel* visualItems (void) { return _visualItems; } + Q_INVOKABLE void start(void); + signals: @@ -33,7 +30,7 @@ public slots: private: //QmlObjectListModel* _visualItems; - WimaFlyArea _flyArea; + WimaFlyArea * _flyArea; }; #endif // WIMACONTROLLER_H diff --git a/src/MissionManager/WimaFlyArea.cc b/src/MissionManager/WimaFlyArea.cc index 90953cd1a..92d1d3a74 100644 --- a/src/MissionManager/WimaFlyArea.cc +++ b/src/MissionManager/WimaFlyArea.cc @@ -1,8 +1,9 @@ #include "WimaFlyArea.h" WimaFlyArea::WimaFlyArea(QObject *parent) : QObject(parent) + , _polygons (nullptr) { - this->_isReady = false; + } WimaFlyArea::WimaFlyArea(const WimaFlyArea &other, QObject *parent): QObject(parent) @@ -12,14 +13,23 @@ WimaFlyArea::WimaFlyArea(const WimaFlyArea &other, QObject *parent): QObject(par const WimaFlyArea& WimaFlyArea::operator=(const WimaFlyArea& other) { - this->_flyAreaPolygon = other._flyAreaPolygon; - this->_isReady = other._isReady; - + this->_polygons = other._polygons; return *this; } -void WimaFlyArea::setReady() +void WimaFlyArea::_init() +{ + _polygons = new QmlObjectListModel(this); +} + +void WimaFlyArea::append_WimaFlyArea() { - this->_isReady = true; - emit readyStateChanged(); + QGCMapPolygon *newPolygon = new QGCMapPolygon(); + + _polygons->append(newPolygon); + + emit polygonsChanged(); } + + + diff --git a/src/MissionManager/WimaFlyArea.h b/src/MissionManager/WimaFlyArea.h index 8d9de2866..089b5d02d 100644 --- a/src/MissionManager/WimaFlyArea.h +++ b/src/MissionManager/WimaFlyArea.h @@ -3,6 +3,7 @@ #include #include "QGCMapPolygon.h" +#include "QmlObjectListModel.h" class WimaFlyArea : public QObject { @@ -15,28 +16,27 @@ public: - Q_PROPERTY(QString mapVisualQML READ mapVisualQML CONSTANT) - Q_PROPERTY(bool isReady READ isReady NOTIFY readyStateChanged) - Q_PROPERTY(QGCMapPolygon flyAreaPolygon READ flyAreaPolygon CONSTANT) + Q_PROPERTY(QmlObjectListModel *polygons READ polygons NOTIFY polygonsChanged) + + Q_INVOKABLE void append_WimaFlyArea(); // Property Accessors - QString mapVisualQML (void) const { return QStringLiteral("FlyAreaMapVisual.qml"); } - bool isReady (void) { return _isReady;} - QGCMapPolygon flyAreaPolygon (void) { return _flyAreaPolygon;} + QmlObjectListModel * polygons (void) { return _polygons;} // Methodes - void setReady(); + void _init(void); signals: - void readyStateChanged(void); + void polygonsChanged(void); public slots: private: - QGCMapPolygon _flyAreaPolygon; - bool _isReady; + QmlObjectListModel *_polygons; + + }; #endif // WIMAFLYAREA_H diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 86c017cab..1116e9ded 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -438,7 +438,7 @@ void QGCApplication::_initCommon(void) qmlRegisterUncreatableType("QGroundControl.FactControls", 1, 0, "FactValueSliderListModel", kRefOnly); qmlRegisterUncreatableType ("QGroundControl.FlightMap", 1, 0, "QGCMapPolygon", kRefOnly); - qmlRegisterUncreatableType ("QGroundControl.FlightMap", 1, 0, "WimaFlyArea", kRefOnly); //custom + qmlRegisterUncreatableType ("QGroundControl.FlightMap", 1, 0, "QGCGeoBoundingCube", kRefOnly); qmlRegisterType ("QGroundControl.FlightMap", 1, 0, "QGCMapCircle"); @@ -465,6 +465,10 @@ void QGCApplication::_initCommon(void) qmlRegisterType (kQGCControllers, 1, 0, "GeoTagController"); qmlRegisterType (kQGCControllers, 1, 0, "MavlinkConsoleController"); #endif + // Wima + qmlRegisterUncreatableType ("Wima", 1, 0, "WimaFlyArea", kRefOnly); //custom + qmlRegisterType ("Wima", 1, 0, "WimaController"); //custom + // Register Qml Singletons qmlRegisterSingletonType ("QGroundControl", 1, 0, "QGroundControl", qgroundcontrolQmlGlobalSingletonFactory); diff --git a/src/WimaView/WimaView.qml b/src/WimaView/WimaView.qml index 8f038a33b..086dd127a 100644 --- a/src/WimaView/WimaView.qml +++ b/src/WimaView/WimaView.qml @@ -28,6 +28,8 @@ import QGroundControl.ShapeFileHelper 1.0 import QGroundControl.Airspace 1.0 import QGroundControl.Airmap 1.0 +import Wima 1.0 + /// Mission Editor QGCView { @@ -110,6 +112,8 @@ QGCView { property bool _firstRallyLoadComplete: false property bool _firstLoadComplete: false + + MapFitFunctions { id: mapFitFunctions // The name for this id cannot be changed without breaking references outside of this code. Beware! map: editorMap @@ -201,6 +205,10 @@ QGCView { } WimaController { id:wimaController + + Component.onCompleted: { + wimaController.start() + } } PlanMasterController { @@ -530,12 +538,26 @@ QGCView { } //Add fly area - FlyAreaMapVisual { - map: editorMap - qgcView: _qgcView - _flyAreaPolygon: _flyArea.flyAreaPolygon - } + Repeater { + model: _flyArea.polygons + delegate: QGCMapPolygonVisuals { + qgcView: _qgcView ///< QGCView for popping dialogs + mapControl: editorMap ///< Map control to place item in + mapPolygon: object + interiorColor: "green" + interiorOpacity: 1 + borderWidth: 1 + borderColor: "white" + + Component.onCompleted: { + addInitialPolygon() + } + } + onItemAdded: { + console.log("Item added") + } + } // Add the vehicles to the map MapItemView { @@ -617,7 +639,7 @@ QGCView { iconSource: "/qmlimages/Target.svg", toggle: true }, - { + { name: qsTr("No Fly"), iconSource: "/qmlimages/noFlyArea.svg", toggle: true @@ -650,7 +672,8 @@ QGCView { onClicked: { switch (index) { case 1: - wimaController.initWimaFlyArea(); + _flyArea.append_WimaFlyArea(); + console.log("polygon count: ", _flyArea.polygons.count) //addComplexItem(_missionController.complexMissionItemNames[2]) /*_addWaypointOnClick = checked _addROIOnClick = false*/ @@ -1175,4 +1198,38 @@ QGCView { } } } + + + + Rectangle { + id: debugMessageWindow + anchors.bottom: parent.bottom + width: parent.width*0.7 + x: (parent.width-width)/2 + height: 150 + radius: 10 + border.color: "black" + border.width: 3 + + color: "green" + z:100 + + Text { + id: debugTextTitle + anchors.top: parent.top + x: (parent.width - width)/2 + text: qsTr("Debug Messages") + } + + Text { + id: debugText + anchors.bottom: parent.bottom + x: (parent.width - width)/2 + width: parent.width*0.95 + height: parent.height-debugTextTitle.height + text: "Polygon count: " + wimaController.flyArea.polygons.dirty; + + } + } + } // QGCVIew -- 2.22.0