FactTextField.qml 1.97 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

19 20
    signal updated()

Don Gagne's avatar
Don Gagne committed
21 22
    property Fact   fact: null

Don Gagne's avatar
Don Gagne committed
23 24
    property string _validateString

Don Gagne's avatar
Don Gagne committed
25
    inputMethodHints: ((fact && fact.typeIsString) || ScreenTools.isiOS) ?
Don Gagne's avatar
Don Gagne committed
26
                          Qt.ImhNone :                // iOS numeric keyboard has no done button, we can't use it
27
                          Qt.ImhFormattedNumbersOnly  // Forces use of virtual numeric keyboard
Don Gagne's avatar
Don Gagne committed
28 29

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

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


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

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

    Component {
        id: helpDialogComponent

        ParameterEditorDialog {
            fact: _textField.fact
        }
    }
66
}