FactTextField.qml 1.24 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

dogmaphobic's avatar
dogmaphobic committed
14 15
    text:       fact ? fact.valueString : ""
    unitsLabel: fact ? fact.units : ""
Don Gagne's avatar
Don Gagne committed
16 17
    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

    onEditingFinished: {
        if (qgcView) {
            var errorString = fact.validate(text, false /* convertOnly */)
            if (errorString == "") {
                fact.value = text
            } else {
                _validateString = text
32
                qgcView.showDialog(editorDialogComponent, "Invalid Parameter Value", qgcView.showDialogDefaultWidth, StandardButton.Save)
Don Gagne's avatar
Don Gagne committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
            }
        } else {
            fact.value = text
            fact.valueChanged(fact.value)
        }
    }

    Component {
        id: editorDialogComponent

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