FactTextField.qml 1.9 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
    showUnits:  true
17
    showHelp:   true
Don Gagne's avatar
Don Gagne committed
18

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

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

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

43 44 45
    onHelpClicked: qgcView.showDialog(helpDialogComponent, qsTr("Value Details"), qgcView.showDialogDefaultWidth, StandardButton.Save)


Don Gagne's avatar
Don Gagne committed
46
    Component {
47
        id: validationErrorDialogComponent
Don Gagne's avatar
Don Gagne committed
48 49 50 51 52 53 54

        ParameterEditorDialog {
            validate:       true
            validateValue:  _validateString
            fact:           _textField.fact
        }
    }
55 56 57 58 59 60 61 62

    Component {
        id: helpDialogComponent

        ParameterEditorDialog {
            fact: _textField.fact
        }
    }
63
}