FactTextField.qml 1.61 KB
Newer Older
1 2 3 4
import QtQuick                  2.2
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2
import QtQuick.Dialogs          1.2
Don Gagne's avatar
Don Gagne committed
5

6 7 8 9
import QGroundControl.FactSystem    1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
10 11

QGCTextField {
Don Gagne's avatar
Don Gagne committed
12 13
    id: _textField

dogmaphobic's avatar
dogmaphobic committed
14 15
    text:       fact ? fact.valueString : ""
    unitsLabel: fact ? fact.units : ""
Don Gagne's avatar
Don Gagne committed
16 17
    showUnits:  true

Don Gagne's avatar
Don Gagne committed
18 19 20
    property Fact   fact:           null
    property string _validateString

Don Gagne's avatar
Don Gagne committed
21
    // At this point all Facts are numeric
22 23
    validator:          DoubleValidator {}
    inputMethodHints:   ScreenTools.isiOS ?
Don Gagne's avatar
Don Gagne committed
24
                            Qt.ImhNone :                // iOS numeric keyboard has not done button, we can't use it
25
                            Qt.ImhFormattedNumbersOnly  // Forces use of virtual numeric keyboard
Don Gagne's avatar
Don Gagne committed
26 27

    onEditingFinished: {
Don Gagne's avatar
Don Gagne committed
28
        if (typeof qgcView !== 'undefined' && qgcView) {
Don Gagne's avatar
Don Gagne committed
29 30 31 32 33
            var errorString = fact.validate(text, false /* convertOnly */)
            if (errorString == "") {
                fact.value = text
            } else {
                _validateString = text
34
                qgcView.showDialog(editorDialogComponent, qsTr("Invalid Parameter Value"), qgcView.showDialogDefaultWidth, StandardButton.Save)
Don Gagne's avatar
Don Gagne committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
            }
        } else {
            fact.value = text
            fact.valueChanged(fact.value)
        }
    }

    Component {
        id: editorDialogComponent

        ParameterEditorDialog {
            validate:       true
            validateValue:  _validateString
            fact:           _textField.fact
        }
    }
51
}