From 674bf25408dafced00a7fa780aaf9a6f0bef9dcb Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sat, 10 Oct 2015 18:51:49 -0700 Subject: [PATCH] Add support for lines between items --- src/MissionEditor/MissionEditor.cc | 32 +++++++++++++++++- src/MissionEditor/MissionEditor.h | 12 +++++-- src/MissionEditor/MissionEditor.qml | 52 +++++++++++++++++++++++++++-- 3 files changed, 90 insertions(+), 6 deletions(-) diff --git a/src/MissionEditor/MissionEditor.cc b/src/MissionEditor/MissionEditor.cc index 3aa1f1a8e..688ee145c 100644 --- a/src/MissionEditor/MissionEditor.cc +++ b/src/MissionEditor/MissionEditor.cc @@ -26,6 +26,7 @@ This file is part of the QGROUNDCONTROL project #include "MultiVehicleManager.h" #include "MissionManager.h" #include "QGCFileDialog.h" +#include "CoordinateVector.h" #include #include @@ -51,6 +52,7 @@ MissionEditor::MissionEditor(QWidget *parent) _newMissionItemsAvailable(); } else { _missionItems = new QmlObjectListModel(this); + connect(_missionItems, &QmlObjectListModel::dirtyChanged, this, &MissionEditor::_missionListDirtyChanged); } setContextPropertyObject("controller", this); @@ -75,6 +77,9 @@ void MissionEditor::_newMissionItemsAvailable(void) _reSequence(); _missionItems->setDirty(false); + connect(_missionItems, &QmlObjectListModel::dirtyChanged, this, &MissionEditor::_missionListDirtyChanged); + _rebuildWaypointLines(); + emit missionItemsChanged(); emit canEditChanged(_canEdit); } @@ -190,7 +195,11 @@ void MissionEditor::loadMissionFromFile(void) return; } - _missionItems->clear(); + if (_missionItems) { + _missionItems->deleteLater(); + } + _missionItems = new QmlObjectListModel(this); + _canEdit = true; QFile file(filename); @@ -229,6 +238,9 @@ void MissionEditor::loadMissionFromFile(void) _missionItems->setDirty(false); emit canEditChanged(_canEdit); + + connect(_missionItems, &QmlObjectListModel::dirtyChanged, this, &MissionEditor::_missionListDirtyChanged); + _rebuildWaypointLines(); } void MissionEditor::saveMissionToFile(void) @@ -256,3 +268,21 @@ void MissionEditor::saveMissionToFile(void) _missionItems->setDirty(false); } + +void MissionEditor::_rebuildWaypointLines(void) +{ + _waypointLines.clear(); + for (int i=1; i<_missionItems->count(); i++) { + MissionItem* item1 = qobject_cast(_missionItems->get(i-1)); + MissionItem* item2 = qobject_cast(_missionItems->get(i)); + + _waypointLines.append(new CoordinateVector(item1->coordinate(), item2->coordinate())); + } + emit waypointLinesChanged(); +} + +void MissionEditor::_missionListDirtyChanged(bool dirty) +{ + Q_UNUSED(dirty); + _rebuildWaypointLines(); +} diff --git a/src/MissionEditor/MissionEditor.h b/src/MissionEditor/MissionEditor.h index dc8821826..eed09fc19 100644 --- a/src/MissionEditor/MissionEditor.h +++ b/src/MissionEditor/MissionEditor.h @@ -35,7 +35,8 @@ public: MissionEditor(QWidget* parent = NULL); ~MissionEditor(); - Q_PROPERTY(QmlObjectListModel* missionItems READ missionItemsModel NOTIFY missionItemsChanged) + Q_PROPERTY(QmlObjectListModel* missionItems READ missionItems NOTIFY missionItemsChanged) + Q_PROPERTY(QmlObjectListModel* waypointLines READ waypointLines NOTIFY waypointLinesChanged) Q_PROPERTY(bool canEdit READ canEdit NOTIFY canEditChanged) Q_INVOKABLE int addMissionItem(QGeoCoordinate coordinate); @@ -49,21 +50,26 @@ public: // Property accessors - QmlObjectListModel* missionItemsModel(void) { return _missionItems; } + QmlObjectListModel* missionItems(void) { return _missionItems; } + QmlObjectListModel* waypointLines(void) { return &_waypointLines; } bool canEdit(void) { return _canEdit; } signals: void missionItemsChanged(void); void canEditChanged(bool canEdit); + void waypointLinesChanged(void); private slots: void _newMissionItemsAvailable(); + void _missionListDirtyChanged(bool dirty); private: void _reSequence(void); - + void _rebuildWaypointLines(void); + private: QmlObjectListModel* _missionItems; + QmlObjectListModel _waypointLines; bool _canEdit; ///< true: UI can edit these items, false: can't edit, can only send to vehicle or save static const char* _settingsGroup; diff --git a/src/MissionEditor/MissionEditor.qml b/src/MissionEditor/MissionEditor.qml index 1751e19dd..28b0e3a98 100644 --- a/src/MissionEditor/MissionEditor.qml +++ b/src/MissionEditor/MissionEditor.qml @@ -383,6 +383,7 @@ This code will need to wait for Qml 5.5 support since Map.visibleRegion is only label: "H" isCurrentItem: _showHomePositionManager coordinate: _homePositionCoordinate + z: 2 onClicked: _showHomePositionManager = true } @@ -396,13 +397,59 @@ This code will need to wait for Qml 5.5 support since Map.visibleRegion is only label: object.sequenceNumber isCurrentItem: !_showHomePositionManager && object.isCurrentItem coordinate: object.coordinate + z: 2 onClicked: { _showHomePositionManager = false setCurrentItem(object.sequenceNumber) } + } + } + + MapPolyline { + id: homePositionLine + line.width: 3 + line.color: "orange" + z: 1 + + property var homePositionCoordinate: _homePositionCoordinate + + function update() { + while (homePositionLine.path.length != 0) { + homePositionLine.removeCoordinate(homePositionLine.path[0]) + } + if (_missionItems && _missionItems.count != 0) { + homePositionLine.addCoordinate(homePositionCoordinate) + homePositionLine.addCoordinate(_missionItems.get(0).coordinate) + } + } + + onHomePositionCoordinateChanged: update() - Component.onCompleted: console.log("Indicator", object.coordinate) + Connections { + target: controller + + onWaypointLinesChanged: homePositionLine.update() + } + + Component.onCompleted: homePositionLine.update() + } + + + // Add lines between waypoints + MapItemView { + model: controller.waypointLines + + delegate: + MapPolyline { + line.width: 3 + line.color: "orange" + z: 1 + + path: [ + { latitude: object.coordinate1.latitude, longitude: object.coordinate1.longitude }, + { latitude: object.coordinate2.latitude, longitude: object.coordinate2.longitude }, + ] } } @@ -630,7 +677,8 @@ This code will need to wait for Qml 5.5 support since Map.visibleRegion is only text: "Add/Update" onClicked: { - _homePositionManager.updateHomePosition(nameField.text, QtPositioning.coordinate(latitudeField.text, longitudeField.text, altitudeField.text)) + _homePositionCoordinate = QtPositioning.coordinate(latitudeField.text, longitudeField.text, altitudeField.text) + _homePositionManager.updateHomePosition(nameField.text, _homePositionCoordinate) homePosCombo.currentIndex = homePosCombo.find(nameField.text) } } -- 2.22.0