FactTextField.qml 2.09 KB
Newer Older
1 2
import QtQuick                  2.3
import QtQuick.Controls         1.2
3
import QtQuick.Controls.Styles  1.4
4
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
    property Fact   fact: null

Don Gagne's avatar
Don Gagne committed
21 22
    property string _validateString

Don Gagne's avatar
Don Gagne committed
23
    // At this point all Facts are numeric
Don Gagne's avatar
Don Gagne committed
24
    inputMethodHints: ((fact && fact.typeIsString) || ScreenTools.isiOS) ?
Don Gagne's avatar
Don Gagne committed
25
                          Qt.ImhNone :                // iOS numeric keyboard has no 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: {
29 30 31 32
        if (ScreenTools.isMobile) {
            // Toss focus on mobile after Done on virtual keyboard. Prevent strange interactions.
            focus = false
        }
Don Gagne's avatar
Don Gagne committed
33
        if (typeof qgcView !== 'undefined' && qgcView) {
Don Gagne's avatar
Don Gagne committed
34
            var errorString = fact.validate(text, false /* convertOnly */)
35
            if (errorString === "") {
Don Gagne's avatar
Don Gagne committed
36 37 38
                fact.value = text
            } else {
                _validateString = text
39
                qgcView.showDialog(validationErrorDialogComponent, qsTr("Invalid Value"), qgcView.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
Don Gagne's avatar
Don Gagne committed
40 41 42 43 44 45 46
            }
        } else {
            fact.value = text
            fact.valueChanged(fact.value)
        }
    }

Don Gagne's avatar
Don Gagne committed
47
    onHelpClicked: qgcView.showDialog(helpDialogComponent, qsTr("Value Details"), qgcView.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
48 49


Don Gagne's avatar
Don Gagne committed
50
    Component {
51
        id: validationErrorDialogComponent
Don Gagne's avatar
Don Gagne committed
52 53 54 55 56 57 58

        ParameterEditorDialog {
            validate:       true
            validateValue:  _validateString
            fact:           _textField.fact
        }
    }
59 60 61 62 63 64 65 66

    Component {
        id: helpDialogComponent

        ParameterEditorDialog {
            fact: _textField.fact
        }
    }
67
}