FactTextField.qml 1.18 KB
Newer Older
1 2 3
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
Don Gagne's avatar
Don Gagne committed
4 5
import QtQuick.Dialogs 1.2

6 7 8 9 10 11

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

QGCTextField {
Don Gagne's avatar
Don Gagne committed
12 13 14 15 16
    id: _textField

    property Fact   fact:           null
    property string _validateString

Don Gagne's avatar
Don Gagne committed
17 18 19 20 21
    text:               fact.valueString
    unitsLabel:         fact.units

    // At this point all Facts are numeric
    inputMethodHints:   Qt.ImhFormattedNumbersOnly
Don Gagne's avatar
Don Gagne committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

    onEditingFinished: {
        if (qgcView) {
            var errorString = fact.validate(text, false /* convertOnly */)
            if (errorString == "") {
                fact.value = text
            } else {
                _validateString = text
                qgcView.showDialog(editorDialogComponent, "Invalid Parameter Value", 50, StandardButton.Save)
            }
        } else {
            fact.value = text
            fact.valueChanged(fact.value)
        }
    }

    Component {
        id: editorDialogComponent

        ParameterEditorDialog {
            validate:       true
            validateValue:  _validateString
            fact:           _textField.fact
        }
    }
47
}