FactTextField.qml 1.88 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
    inputMethodHints: ((fact && fact.typeIsString) || ScreenTools.isiOS) ?
Don Gagne's avatar
Don Gagne committed
24
                          Qt.ImhNone :                // iOS numeric keyboard has no 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
            var errorString = fact.validate(text, false /* convertOnly */)
30
            if (errorString === "") {
Don Gagne's avatar
Don Gagne committed
31 32 33
                fact.value = text
            } else {
                _validateString = text
34
                qgcView.showDialog(validationErrorDialogComponent, qsTr("Invalid Value"), qgcView.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
Don Gagne's avatar
Don Gagne committed
35 36 37 38 39 40 41
            }
        } else {
            fact.value = text
            fact.valueChanged(fact.value)
        }
    }

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


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

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

    Component {
        id: helpDialogComponent

        ParameterEditorDialog {
            fact: _textField.fact
        }
    }
62
}