Skip to content
GeoFenceEditor.qml 12.9 KiB
Newer Older
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts  1.2

import QGroundControl               1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0

QGCFlickable {
    id:             root
Don Gagne's avatar
 
Don Gagne committed
    contentHeight:  geoFenceEditorRect.height
    clip:           true

    property var    myGeoFenceController
    property var    flightMap

Don Gagne's avatar
Don Gagne committed
    readonly property real  _editFieldWidth:    Math.min(width - _margin * 2, ScreenTools.defaultFontPixelWidth * 15)
    readonly property real  _margin:            ScreenTools.defaultFontPixelWidth / 2
    readonly property real  _radius:            ScreenTools.defaultFontPixelWidth / 2

Don Gagne's avatar
 
Don Gagne committed
    Rectangle {
        id:     geoFenceEditorRect
        anchors.left:   parent.left
        anchors.right:  parent.right
Don Gagne's avatar
 
Don Gagne committed
        height: geoFenceItems.y + geoFenceItems.height + (_margin * 2)
        radius: _radius
        color:  qgcPal.missionItemEditor

        QGCLabel {
            id:                 geoFenceLabel
            anchors.margins:    _margin
            anchors.left:       parent.left
            anchors.top:        parent.top
            text:               qsTr("GeoFence")
            anchors.leftMargin: ScreenTools.defaultFontPixelWidth
        }
Don Gagne's avatar
 
Don Gagne committed
            id:                 geoFenceItems
            anchors.margins:    _margin
            anchors.left:       parent.left
            anchors.right:      parent.right
            anchors.top:        geoFenceLabel.bottom
            height:             fenceColumn.y + fenceColumn.height + (_margin * 2)
            color:              qgcPal.windowShadeDark
            radius:             _radius

            Column {
                id:                 fenceColumn
                anchors.margins:    _margin
                anchors.top:        parent.top
                anchors.left:       parent.left
                anchors.right:      parent.right
Don Gagne's avatar
 
Don Gagne committed
                spacing:            ScreenTools.defaultFontPixelHeight / 2
Don Gagne's avatar
 
Don Gagne committed
                QGCLabel {
                    anchors.left:       parent.left
                    anchors.right:      parent.right
Don Gagne's avatar
 
Don Gagne committed
                    wrapMode:           Text.WordWrap
                    font.pointSize:     myGeoFenceController.supported ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
                    text:               myGeoFenceController.supported ?
                                            qsTr("GeoFencing allows you to set a virtual ‘fence’ around the area you want to fly in.") :
                                            qsTr("This vehicle does not support GeoFence.")
                }
Don Gagne's avatar
 
Don Gagne committed
                Column {
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    spacing:        ScreenTools.defaultFontPixelHeight / 2
                    visible:        myGeoFenceController.supported
Don Gagne's avatar
 
Don Gagne committed
                    Repeater {
                        model: myGeoFenceController.params
Don Gagne's avatar
 
Don Gagne committed
                        Item {
                            width:  fenceColumn.width
                            height: textField.height
Don Gagne's avatar
 
Don Gagne committed
                            property bool showCombo: modelData.enumStrings.length > 0
Don Gagne's avatar
 
Don Gagne committed
                            QGCLabel {
                                id:                 textFieldLabel
                                anchors.baseline:   textField.baseline
                                text:               myGeoFenceController.paramLabels[index]
                            }
Don Gagne's avatar
 
Don Gagne committed
                            FactTextField {
                                id:             textField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                showUnits:      true
                                fact:           modelData
                                visible:        !parent.showCombo
                            }
Don Gagne's avatar
 
Don Gagne committed
                            FactComboBox {
                                id:             comboField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                indexModel:     false
                                fact:           showCombo ? modelData : _nullFact
                                visible:        parent.showCombo
Don Gagne's avatar
 
Don Gagne committed
                                property var _nullFact: Fact { }
Don Gagne's avatar
 
Don Gagne committed
                    }
Don Gagne's avatar
 
Don Gagne committed
                    SectionHeader {
                        id:     insertSection
                        text:   qsTr("Insert GeoFence")
                    }
Don Gagne's avatar
 
Don Gagne committed
                    QGCButton {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        text:           qsTr("Polygon Fence")
Don Gagne's avatar
 
Don Gagne committed
                        onClicked: {
                            var rect = Qt.rect(flightMap.centerViewport.x, flightMap.centerViewport.y, flightMap.centerViewport.width, flightMap.centerViewport.height)
                            var topLeftCoord = flightMap.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */)
                            var bottomRightCoord = flightMap.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */)
                            myGeoFenceController.addInclusionPolygon(topLeftCoord, bottomRightCoord)
Don Gagne's avatar
 
Don Gagne committed
                    }
Don Gagne's avatar
 
Don Gagne committed
                    QGCButton {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        text:           qsTr("Circular Fence")
Don Gagne's avatar
 
Don Gagne committed
                        onClicked: {
                            var rect = Qt.rect(flightMap.centerViewport.x, flightMap.centerViewport.y, flightMap.centerViewport.width, flightMap.centerViewport.height)
                            var topLeftCoord = flightMap.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */)
                            var bottomRightCoord = flightMap.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */)
                            myGeoFenceController.addInclusionCircle(topLeftCoord, bottomRightCoord)
Don Gagne's avatar
 
Don Gagne committed
                    }
Don Gagne's avatar
 
Don Gagne committed
                    SectionHeader {
                        id:     polygonSection
                        text:   qsTr("Polygon Fences")
                    }

                    QGCLabel {
                        text:       qsTr("None")
                        visible:    polygonSection.checked && myGeoFenceController.polygons.count === 0
                    }

                    GridLayout {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        columns:        3
                        flow:           GridLayout.TopToBottom
                        visible:        polygonSection.checked && myGeoFenceController.polygons.count > 0
Don Gagne's avatar
 
Don Gagne committed
                            text:               qsTr("Inclusion")
                            Layout.column:      0
                            Layout.alignment:   Qt.AlignHCenter
Don Gagne's avatar
 
Don Gagne committed
                        Repeater {
                            model: myGeoFenceController.polygons
Don Gagne's avatar
 
Don Gagne committed
                            QGCCheckBox {
                                checked:            object.inclusion
                                onClicked:          object.inclusion = checked
                                Layout.alignment:   Qt.AlignHCenter
                            }
Don Gagne's avatar
 
Don Gagne committed
                        }
Don Gagne's avatar
 
Don Gagne committed
                        QGCLabel {
                            text:               qsTr("Edit")
                            Layout.column:      1
                            Layout.alignment:   Qt.AlignHCenter
                        }
Don Gagne's avatar
 
Don Gagne committed
                        Repeater {
                            model: myGeoFenceController.polygons
Don Gagne's avatar
 
Don Gagne committed
                            QGCRadioButton {
                                checked:            _interactive
                                Layout.alignment:   Qt.AlignHCenter

Don Gagne's avatar
 
Don Gagne committed
                                property bool _interactive: object.interactive
Don Gagne's avatar
 
Don Gagne committed
                                on_InteractiveChanged: checked = _interactive
Don Gagne's avatar
 
Don Gagne committed
                                onClicked: {
                                    myGeoFenceController.clearAllInteractive()
                                    object.interactive = checked
Don Gagne's avatar
 
Don Gagne committed
                        }
Don Gagne's avatar
 
Don Gagne committed
                        QGCLabel {
                            text:               qsTr("Delete")
                            Layout.column:      2
                            Layout.alignment:   Qt.AlignHCenter
                        }
Don Gagne's avatar
 
Don Gagne committed
                        Repeater {
                            model: myGeoFenceController.polygons
Don Gagne's avatar
 
Don Gagne committed
                            QGCButton {
                                text:               qsTr("Del")
                                Layout.alignment:   Qt.AlignHCenter
                                onClicked:          myGeoFenceController.deletePolygon(index)
                            }
                        }
                    } // GridLayout
Don Gagne's avatar
 
Don Gagne committed
                    SectionHeader {
                        id:     circleSection
                        text:   qsTr("Circular Fences")
                    }
Don Gagne's avatar
 
Don Gagne committed
                    QGCLabel {
                        text:       qsTr("None")
                        visible:    circleSection.checked && myGeoFenceController.circles.count === 0
                    }
Don Gagne's avatar
 
Don Gagne committed
                    GridLayout {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        columns:        4
                        flow:           GridLayout.TopToBottom
                        visible:        polygonSection.checked && myGeoFenceController.circles.count > 0
Don Gagne's avatar
 
Don Gagne committed
                            text:               qsTr("Inclusion")
                            Layout.column:      0
                            Layout.alignment:   Qt.AlignHCenter
Don Gagne's avatar
 
Don Gagne committed
                        Repeater {
                            model: myGeoFenceController.circles
Don Gagne's avatar
 
Don Gagne committed
                            QGCCheckBox {
                                checked:            object.inclusion
                                onClicked:          object.inclusion = checked
                                Layout.alignment:   Qt.AlignHCenter
                            }
Don Gagne's avatar
 
Don Gagne committed
                        }
Don Gagne's avatar
 
Don Gagne committed
                        QGCLabel {
                            text:               qsTr("Edit")
                            Layout.column:      1
                            Layout.alignment:   Qt.AlignHCenter
                        }
Don Gagne's avatar
 
Don Gagne committed
                        Repeater {
                            model: myGeoFenceController.circles
Don Gagne's avatar
 
Don Gagne committed
                            QGCRadioButton {
                                checked:            _interactive
                                Layout.alignment:   Qt.AlignHCenter

Don Gagne's avatar
 
Don Gagne committed
                                property bool _interactive: object.interactive
Don Gagne's avatar
 
Don Gagne committed
                                on_InteractiveChanged: checked = _interactive
Don Gagne's avatar
 
Don Gagne committed
                                onClicked: {
                                    myGeoFenceController.clearAllInteractive()
                                    object.interactive = checked
Don Gagne's avatar
 
Don Gagne committed
                        }
Don Gagne's avatar
 
Don Gagne committed
                        QGCLabel {
                            text:               qsTr("Radius")
                            Layout.column:      2
                            Layout.alignment:   Qt.AlignHCenter
                        }
Don Gagne's avatar
 
Don Gagne committed
                        Repeater {
                            model: myGeoFenceController.circles
Don Gagne's avatar
 
Don Gagne committed
                            FactTextField {
                                fact:               object.radius
                                Layout.fillWidth:   true
                                Layout.alignment:   Qt.AlignHCenter
                            }
Don Gagne's avatar
 
Don Gagne committed
                        }
Don Gagne's avatar
 
Don Gagne committed
                        QGCLabel {
                            text:               qsTr("Delete")
                            Layout.column:      3
                            Layout.alignment:   Qt.AlignHCenter
                        }
Don Gagne's avatar
 
Don Gagne committed
                        Repeater {
                            model: myGeoFenceController.circles
Don Gagne's avatar
 
Don Gagne committed
                            QGCButton {
                                text:               qsTr("Del")
                                Layout.alignment:   Qt.AlignHCenter
                                onClicked:          myGeoFenceController.deleteCircle(index)
Don Gagne's avatar
 
Don Gagne committed
                        }
                    } // GridLayout
Don Gagne's avatar
 
Don Gagne committed
        }
    } // Rectangle