Skip to content
FactTextField.qml 1.78 KiB
Newer Older
import QtQuick                  2.3
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.4
import QtQuick.Dialogs          1.2
Don Gagne's avatar
Don Gagne committed

import QGroundControl.FactSystem    1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0

QGCTextField {
Don Gagne's avatar
Don Gagne committed
    id: _textField

dogmaphobic's avatar
dogmaphobic committed
    text:       fact ? fact.valueString : ""
    unitsLabel: fact ? fact.units : ""
Don Gagne's avatar
Don Gagne committed
    showUnits:  true
    showHelp:   true
Don Gagne's avatar
Don Gagne committed

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

Don Gagne's avatar
Don Gagne committed
    property string _validateString

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

    onEditingFinished: {
        var errorString = fact.validate(text, false /* convertOnly */)
        if (errorString === "") {
Don Gagne's avatar
Don Gagne committed
            fact.value = text
            _textField.updated()
            mainWindow.showComponentDialog(validationErrorDialogComponent, qsTr("Invalid Value"), mainWindow.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
Don Gagne's avatar
Don Gagne committed
        }
    }

    onHelpClicked: mainWindow.showComponentDialog(helpDialogComponent, qsTr("Value Details"), mainWindow.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
Don Gagne's avatar
Don Gagne committed
    Component {
        id: validationErrorDialogComponent
Don Gagne's avatar
Don Gagne committed
        ParameterEditorDialog {
            validate:       true
            validateValue:  _validateString
            fact:           _textField.fact
        }
    }

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