Merge PR #691: Fix double value input in paramdelegates
This commit is contained in:
commit
6452b5e1cd
@ -258,5 +258,6 @@
|
|||||||
<file>ui/devicepages/CoolingThingPage.qml</file>
|
<file>ui/devicepages/CoolingThingPage.qml</file>
|
||||||
<file>ui/devicepages/EvChargerThingPage.qml</file>
|
<file>ui/devicepages/EvChargerThingPage.qml</file>
|
||||||
<file>ui/components/BlurredLabel.qml</file>
|
<file>ui/components/BlurredLabel.qml</file>
|
||||||
|
<file>ui/components/NymeaSpinBox.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
79
nymea-app/ui/components/NymeaSpinBox.qml
Normal file
79
nymea-app/ui/components/NymeaSpinBox.qml
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
import QtQuick 2.8
|
||||||
|
import QtQuick.Layouts 1.2
|
||||||
|
import QtQuick.Controls 2.3
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property var from
|
||||||
|
property var to
|
||||||
|
|
||||||
|
property var value
|
||||||
|
|
||||||
|
property bool floatingPoint: false
|
||||||
|
|
||||||
|
property bool editable: true
|
||||||
|
|
||||||
|
signal valueModified(var value)
|
||||||
|
|
||||||
|
ColorIcon {
|
||||||
|
name: "remove"
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
onClicked: {
|
||||||
|
var tmp = NaN
|
||||||
|
if (root.floatingPoint) {
|
||||||
|
tmp = parseFloat(root.value)
|
||||||
|
} else {
|
||||||
|
tmp = parseInt(root.value)
|
||||||
|
}
|
||||||
|
if (tmp != NaN){
|
||||||
|
root.value = tmp - 1
|
||||||
|
root.valueModified(root.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TextField {
|
||||||
|
text: root.value
|
||||||
|
readOnly: !root.editable
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
onTextEdited: {
|
||||||
|
root.value = text
|
||||||
|
root.valueModified(root.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
validator: root.floatingPoint ? doubleValidator : intValidator
|
||||||
|
|
||||||
|
IntValidator {
|
||||||
|
id: intValidator
|
||||||
|
bottom: Math.min(root.from, root.to)
|
||||||
|
top: Math.max(root.from, root.to)
|
||||||
|
}
|
||||||
|
|
||||||
|
DoubleValidator {
|
||||||
|
id: doubleValidator
|
||||||
|
bottom: Math.min(root.from, root.to)
|
||||||
|
top: Math.max(root.from, root.to)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
ColorIcon {
|
||||||
|
name: "add"
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
onClicked: {
|
||||||
|
var tmp = NaN
|
||||||
|
if (root.floatingPoint) {
|
||||||
|
tmp = parseFloat(root.value)
|
||||||
|
} else {
|
||||||
|
tmp = parseInt(root.value)
|
||||||
|
}
|
||||||
|
if (tmp != NaN){
|
||||||
|
root.value = tmp + 1
|
||||||
|
root.valueModified(root.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -60,7 +60,7 @@ ItemDelegate {
|
|||||||
Label {
|
Label {
|
||||||
id: nameLabel
|
id: nameLabel
|
||||||
Layout.fillWidth: parent.labelFillsWidth
|
Layout.fillWidth: parent.labelFillsWidth
|
||||||
// Layout.minimumWidth: parent.width / 2
|
// Layout.minimumWidth: parent.width / 2
|
||||||
text: root.paramType.displayName
|
text: root.paramType.displayName
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
}
|
}
|
||||||
@ -212,7 +212,8 @@ ItemDelegate {
|
|||||||
RowLayout {
|
RowLayout {
|
||||||
spacing: app.margins
|
spacing: app.margins
|
||||||
|
|
||||||
SpinBox {
|
NymeaSpinBox {
|
||||||
|
id: spinbox
|
||||||
value: root.param.value ? root.param.value : 0
|
value: root.param.value ? root.param.value : 0
|
||||||
from: root.paramType.minValue !== undefined
|
from: root.paramType.minValue !== undefined
|
||||||
? root.paramType.minValue
|
? root.paramType.minValue
|
||||||
@ -225,9 +226,9 @@ ItemDelegate {
|
|||||||
editable: true
|
editable: true
|
||||||
width: 150
|
width: 150
|
||||||
onValueModified: root.param.value = value
|
onValueModified: root.param.value = value
|
||||||
textFromValue: function(value) {
|
|
||||||
return Types.toUiValue(value, root.paramType.unit)
|
floatingPoint: root.paramType.type.toLowerCase() == "double"
|
||||||
}
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
print("from:", from, "min", root.paramType.minValue)
|
print("from:", from, "min", root.paramType.minValue)
|
||||||
if (root.value === undefined) {
|
if (root.value === undefined) {
|
||||||
@ -331,10 +332,10 @@ ItemDelegate {
|
|||||||
minCt: root.paramType.minValue
|
minCt: root.paramType.minValue
|
||||||
maxCt: root.paramType.maxValue
|
maxCt: root.paramType.maxValue
|
||||||
ct: root.param.value !== undefined
|
ct: root.param.value !== undefined
|
||||||
? root.param.value
|
? root.param.value
|
||||||
: root.paramType.defaultValue
|
: root.paramType.defaultValue
|
||||||
? root.paramType.defaultValue
|
? root.paramType.defaultValue
|
||||||
: root.paramType.minValue
|
: root.paramType.minValue
|
||||||
|
|
||||||
onCtChanged: {
|
onCtChanged: {
|
||||||
root.param.value = ct
|
root.param.value = ct
|
||||||
|
|||||||
Reference in New Issue
Block a user