FactTextField.qml 1.78 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: {
30 31
        var errorString = fact.validate(text, false /* convertOnly */)
        if (errorString === "") {
Don Gagne's avatar
Don Gagne committed
32
            fact.value = text
33
            _textField.updated()
34 35
        } else {
            _validateString = text
36
            mainWindow.showComponentDialog(validationErrorDialogComponent, qsTr("Invalid Value"), mainWindow.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
Don Gagne's avatar
Don Gagne committed
37 38 39
        }
    }

40
    onHelpClicked: mainWindow.showComponentDialog(helpDialogComponent, qsTr("Value Details"), mainWindow.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
41

Don Gagne's avatar
Don Gagne committed
42
    Component {
43
        id: validationErrorDialogComponent
Don Gagne's avatar
Don Gagne committed
44 45 46 47 48 49
        ParameterEditorDialog {
            validate:       true
            validateValue:  _validateString
            fact:           _textField.fact
        }
    }
50 51 52 53 54 55 56

    Component {
        id: helpDialogComponent
        ParameterEditorDialog {
            fact: _textField.fact
        }
    }
57
}