FactTextField.qml 1.19 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
    id: _textField

Don Gagne's avatar
Don Gagne committed
14 15 16 17
    text:       fact.valueString
    unitsLabel: fact.units
    showUnits:  true

Don Gagne's avatar
Don Gagne committed
18 19 20
    property Fact   fact:           null
    property string _validateString

Don Gagne's avatar
Don Gagne committed
21 22 23

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

    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
        }
    }
49
}