Commit fb486d9c authored by Don Gagne's avatar Don Gagne

Convert polygon editing to dynamic objects

parent 1991d269
......@@ -133,8 +133,10 @@
<file alias="QGroundControl/FlightMap/InstrumentSwipeView.qml">src/FlightMap/Widgets/InstrumentSwipeView.qml</file>
<file alias="QGroundControl/FlightMap/MapScale.qml">src/FlightMap/MapScale.qml</file>
<file alias="QGroundControl/FlightMap/MissionItemIndicator.qml">src/FlightMap/MapItems/MissionItemIndicator.qml</file>
<file alias="QGroundControl/FlightMap/MissionItemIndicatorDrag.qml">src/FlightMap/MapItems/MissionItemIndicatorDrag.qml</file>
<file alias="QGroundControl/FlightMap/MissionItemView.qml">src/FlightMap/MapItems/MissionItemView.qml</file>
<file alias="QGroundControl/FlightMap/MissionLineView.qml">src/FlightMap/MapItems/MissionLineView.qml</file>
<file alias="QGroundControl/FlightMap/PolygonEditor.qml">src/FlightMap/MapItems/PolygonEditor.qml</file>
<file alias="QGroundControl/FlightMap/QGCArtificialHorizon.qml">src/FlightMap/Widgets/QGCArtificialHorizon.qml</file>
<file alias="QGroundControl/FlightMap/QGCAttitudeHUD.qml">src/FlightMap/Widgets/QGCAttitudeHUD.qml</file>
<file alias="QGroundControl/FlightMap/QGCAttitudeWidget.qml">src/FlightMap/Widgets/QGCAttitudeWidget.qml</file>
......
This diff is collapsed.
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
import QtQuick 2.4
import QtLocation 5.3
import QGroundControl 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Controls 1.0
/// Use the drag a MissionItemIndicator
Rectangle {
id: itemDragger
x: itemIndicator.x - _expandMargin
y: itemIndicator.y - _expandMargin
width: itemIndicator.width + (_expandMargin * 2)
height: itemIndicator.height + (_expandMargin * 2)
color: "transparent"
z: QGroundControl.zOrderMapItems + 1 // Above item icons
// These are handy for debugging so left in for now
//border.width: 1
//border.color: "white"
// Properties which must be specific by consumer
property var itemIndicator ///< The mission item indicator to drag around
property var itemCoordinate ///< Coordinate we are updating during drag
property bool _preventCoordinateBindingLoop: false
property real _expandMargin: ScreenTools.isMobile ? ScreenTools.defaultFontPixelWidth : 0
onXChanged: liveDrag()
onYChanged: liveDrag()
function liveDrag() {
if (!itemDragger._preventCoordinateBindingLoop && Drag.active) {
var point = Qt.point(itemDragger.x + _expandMargin + itemIndicator.anchorPoint.x, itemDragger.y + _expandMargin + itemIndicator.anchorPoint.y)
var coordinate = map.toCoordinate(point)
itemDragger._preventCoordinateBindingLoop = true
coordinate.altitude = itemCoordinate.altitude
itemCoordinate = coordinate
itemDragger._preventCoordinateBindingLoop = false
}
}
Drag.active: itemDrag.drag.active
MouseArea {
id: itemDrag
anchors.fill: parent
drag.target: parent
drag.minimumX: 0
drag.minimumY: 0
drag.maximumX: itemDragger.parent.width - parent.width
drag.maximumY: itemDragger.parent.height - parent.height
}
}
This diff is collapsed.
......@@ -22,10 +22,12 @@ VehicleHealthWidget 1.0 VehicleHealthWidget.qml
VibrationWidget 1.0 VibrationWidget.qml
# Map items
MissionItemIndicator 1.0 MissionItemIndicator.qml
MissionItemView 1.0 MissionItemView.qml
MissionLineView 1.0 MissionLineView.qml
VehicleMapItem 1.0 VehicleMapItem.qml
MissionItemIndicator 1.0 MissionItemIndicator.qml
MissionItemIndicatorDrag 1.0 MissionItemIndicatorDrag.qml
MissionItemView 1.0 MissionItemView.qml
MissionLineView 1.0 MissionLineView.qml
PolygonEditor 1.0 PolygonEditor.qml
VehicleMapItem 1.0 VehicleMapItem.qml
# Editor controls
QGCMapPolygonControls 1.0 QGCMapPolygonControls.qml
......@@ -16,6 +16,7 @@ import QGroundControl 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0
import QGroundControl.FlightMap 1.0
/// Fixed Wing Landing Pattern map visuals
Item {
......@@ -78,8 +79,8 @@ Item {
function showDragAreas() {
if (_dragAreas.length === 0) {
_dragAreas.push(dragAreaComponent.createObject(map, { "dragLoiter": true }))
_dragAreas.push(dragAreaComponent.createObject(map, { "dragLoiter": false }))
_dragAreas.push(loiterDragAreaComponent.createObject(map))
_dragAreas.push(landDragAreaComponent.createObject(map))
}
}
......@@ -145,53 +146,27 @@ Item {
}
}
// Control which is used to drag items
// Control which is used to drag the loiter point
Component {
id: dragAreaComponent
Rectangle {
id: itemDragger
x: mapQuickItem.x
y: mapQuickItem.y
width: mapQuickItem.width
height: mapQuickItem.height
color: "transparent"
z: QGroundControl.zOrderMapItems + 1 // Above item icons
property bool dragLoiter
property var mapQuickItem: dragLoiter ? _itemVisuals[_loiterPointIndex] : _itemVisuals[_landPointIndex]
property bool _preventCoordinateBindingLoop: false
onXChanged: liveDrag()
onYChanged: liveDrag()
function liveDrag() {
if (!itemDragger._preventCoordinateBindingLoop && Drag.active) {
var point = Qt.point(itemDragger.x + mapQuickItem.anchorPoint.x, itemDragger.y + mapQuickItem.anchorPoint.y)
var coordinate = map.toCoordinate(point)
itemDragger._preventCoordinateBindingLoop = true
if (dragLoiter) {
coordinate.altitude = _missionItem.loiterCoordinate.altitude
_missionItem.loiterCoordinate = coordinate
} else {
coordinate.altitude = _missionItem.landingCoordinate.altitude
_missionItem.landingCoordinate = coordinate
}
itemDragger._preventCoordinateBindingLoop = false
}
}
id: loiterDragAreaComponent
Drag.active: itemDrag.drag.active
MissionItemIndicatorDrag {
itemIndicator: _itemVisuals[_loiterPointIndex]
itemCoordinate: _missionItem.loiterCoordinate
MouseArea {
id: itemDrag
anchors.fill: parent
drag.target: parent
drag.minimumX: 0
drag.minimumY: 0
drag.maximumX: itemDragger.parent.width - parent.width
drag.maximumY: itemDragger.parent.height - parent.height
}
onItemCoordinateChanged: _missionItem.loiterCoordinate = itemCoordinate
}
}
// Control which is used to drag the loiter point
Component {
id: landDragAreaComponent
MissionItemIndicatorDrag {
itemIndicator: _itemVisuals[_landPointIndex]
itemCoordinate: _missionItem.landingCoordinate
onItemCoordinateChanged: _missionItem.landingCoordinate = itemCoordinate
}
}
......
......@@ -254,7 +254,7 @@ QGCView {
function setCurrentItem(sequenceNumber) {
if (sequenceNumber !== _currentMissionIndex) {
editorMap.polygonDraw.cancelPolygonEdit()
//editorMap.polygonDraw.cancelPolygonEdit()
_currentMissionItem = undefined
_currentMissionIndex = -1
for (var i=0; i<_visualItems.count; i++) {
......
......@@ -80,44 +80,11 @@ Item {
Component {
id: dragAreaComponent
Rectangle {
id: itemDragger
x: _itemVisual.x - _expandMargin
y: _itemVisual.y - _expandMargin
width: _itemVisual.width + (_expandMargin * 2)
height: _itemVisual.height + (_expandMargin * 2)
color: "transparent"
z: QGroundControl.zOrderMapItems + 1 // Above item icons
property bool dragLoiter
property bool _preventCoordinateBindingLoop: false
property real _expandMargin: ScreenTools.isMobile ? ScreenTools.defaultFontPixelWidth : 0
onXChanged: liveDrag()
onYChanged: liveDrag()
function liveDrag() {
if (!itemDragger._preventCoordinateBindingLoop && Drag.active) {
var point = Qt.point(itemDragger.x + _expandMargin + _itemVisual.anchorPoint.x, itemDragger.y + _expandMargin + _itemVisual.anchorPoint.y)
var coordinate = map.toCoordinate(point)
itemDragger._preventCoordinateBindingLoop = true
coordinate.altitude = _missionItem.coordinate.altitude
_missionItem.coordinate = coordinate
itemDragger._preventCoordinateBindingLoop = false
}
}
MissionItemIndicatorDrag {
itemIndicator: _itemVisual
itemCoordinate: _missionItem.coordinate
Drag.active: itemDrag.drag.active
MouseArea {
id: itemDrag
anchors.fill: parent
drag.target: parent
drag.minimumX: 0
drag.minimumY: 0
drag.maximumX: itemDragger.parent.width - parent.width
drag.maximumY: itemDragger.parent.height - parent.height
}
onItemCoordinateChanged: _missionItem.coordinate = itemCoordinate
}
}
......
......@@ -9,6 +9,7 @@ import QGroundControl.Vehicle 1.0
import QGroundControl.Controls 1.0
import QGroundControl.FactControls 1.0
import QGroundControl.Palette 1.0
import QGroundControl.FlightMap 1.0
// Editor for Survery mission items
Rectangle {
......@@ -593,29 +594,29 @@ Rectangle {
QGCButton {
width: _root.width * 0.45
text: editorMap.polygonDraw.drawingPolygon ? qsTr("Finish Draw") : qsTr("Draw")
visible: !editorMap.polygonDraw.adjustingPolygon
enabled: ((editorMap.polygonDraw.drawingPolygon && editorMap.polygonDraw.polygonReady) || !editorMap.polygonDraw.drawingPolygon)
text: polygonEditor.drawingPolygon ? qsTr("Finish Draw") : qsTr("Draw")
visible: !polygonEditor .adjustingPolygon
enabled: ((polygonEditor.drawingPolygon && polygonEditor.polygonReady) || !polygonEditor.drawingPolygon)
onClicked: {
if (editorMap.polygonDraw.drawingPolygon) {
editorMap.polygonDraw.finishCapturePolygon()
if (polygonEditor.drawingPolygon) {
polygonEditor.finishCapturePolygon()
} else {
editorMap.polygonDraw.startCapturePolygon(_root)
polygonEditor.startCapturePolygon()
}
}
}
QGCButton {
width: _root.width * 0.4
text: editorMap.polygonDraw.adjustingPolygon ? qsTr("Finish Adjust") : qsTr("Adjust")
visible: missionItem.polygonPath.length > 0 && !editorMap.polygonDraw.drawingPolygon
text: polygonEditor.adjustingPolygon ? qsTr("Finish Adjust") : qsTr("Adjust")
visible: missionItem.polygonPath.length > 0 && !polygonEditor.drawingPolygon
onClicked: {
if (editorMap.polygonDraw.adjustingPolygon) {
editorMap.polygonDraw.finishAdjustPolygon()
if (polygonEditor.adjustingPolygon) {
polygonEditor.finishAdjustPolygon()
} else {
editorMap.polygonDraw.startAdjustPolygon(_root, missionItem.polygonPath)
polygonEditor.startAdjustPolygon(missionItem.polygonPath)
}
}
}
......@@ -652,4 +653,10 @@ Rectangle {
}
}
}
PolygonEditor {
id: polygonEditor
map: editorMap
callbackObject: parent
}
}
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