Commit 674bf254 authored by Don Gagne's avatar Don Gagne

Add support for lines between items

parent 9c5a4938
......@@ -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 <QQmlContext>
#include <QQmlEngine>
......@@ -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<MissionItem*>(_missionItems->get(i-1));
MissionItem* item2 = qobject_cast<MissionItem*>(_missionItems->get(i));
_waypointLines.append(new CoordinateVector(item1->coordinate(), item2->coordinate()));
}
emit waypointLinesChanged();
}
void MissionEditor::_missionListDirtyChanged(bool dirty)
{
Q_UNUSED(dirty);
_rebuildWaypointLines();
}
......@@ -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;
......
......@@ -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)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment