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

    property Fact   fact:           null
    property string _validateString

    text:       fact.valueString
18
    unitsLabel: fact.units
Don Gagne's avatar
Don Gagne committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

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