add unit string to ParamDescriptorDelegate

This commit is contained in:
Michael Zanetti 2018-09-28 13:25:49 +02:00
parent 9cfbf49535
commit 3c6d00c646
2 changed files with 41 additions and 10 deletions

View File

@ -38,12 +38,12 @@ class StateType : public QObject
Q_PROPERTY(QString type READ type CONSTANT)
Q_PROPERTY(int index READ index CONSTANT)
Q_PROPERTY(QVariant defaultValue READ defaultValue CONSTANT)
Q_PROPERTY(QVariantList allowedValues READ allowedValues WRITE setAllowedValues CONSTANT)
Q_PROPERTY(QVariantList allowedValues READ allowedValues CONSTANT)
Q_PROPERTY(Types::Unit unit READ unit CONSTANT)
Q_PROPERTY(QString unitString READ unitString CONSTANT)
public:
StateType(QObject *parent = 0);
StateType(QObject *parent = nullptr);
QString id() const;
void setId(const QString &id);

View File

@ -11,26 +11,46 @@ ItemDelegate {
property int operatorType: ParamDescriptors.ValueOperatorEquals
contentItem: ColumnLayout {
Label {
Layout.fillWidth: true
text: paramType.displayName
}
RowLayout {
Layout.fillWidth: true
spacing: app.margins
Label {
text: paramType.displayName
}
ComboBox {
FontMetrics {
id: fm
}
Layout.fillWidth: true
model: {
Layout.minimumWidth: {
var minWidth = 0;
for (var i = 0; i < model.length; i++) {
minWidth = Math.max(minWidth, fm.boundingRect(model[i]).width)
}
return minWidth + 60;
}
property bool isNumeric: {
switch (paramType.type.toLowerCase()) {
case "bool":
case "string":
case "qstring":
case "color":
return [qsTr("is"), qsTr("is not")];
return false;
case "int":
case "double":
return [qsTr("is"), qsTr("is not"), qsTr("is greater"), qsTr("is smaller"), qsTr("is greater or equal"), qsTr("is smaller or equal")]
return true;
}
console.warn("ParamDescriptorDelegate: Unhandled data type:", paramType.type.toLowerCase());
return false;
}
model: isNumeric ?
[qsTr("is"), qsTr("is not"), qsTr("is greater"), qsTr("is smaller"), qsTr("is greater or equal"), qsTr("is smaller or equal")]
: [qsTr("is"), qsTr("is not")];
onCurrentTextChanged: {
switch (currentText) {
case qsTr("is"):
@ -84,6 +104,10 @@ ItemDelegate {
return null;
}
}
Label {
text: paramType.unitString
}
}
Loader {
@ -107,8 +131,8 @@ ItemDelegate {
Label {
text: {
switch (root.paramType.type.toLowerCase()) {
case "int":
return Math.round(root.value)
case "double":
return Math.round(root.value * 10) / 10
}
return root.value
}
@ -133,6 +157,13 @@ ItemDelegate {
Slider {
from: paramType.minValue
to: paramType.maxValue
stepSize: {
switch (root.paramType.type.toLowerCase()) {
case "double":
return 0.1
}
return 1
}
Layout.fillWidth: true
onMoved: {
root.value = value;