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(QString type READ type CONSTANT)
Q_PROPERTY(int index READ index CONSTANT) Q_PROPERTY(int index READ index CONSTANT)
Q_PROPERTY(QVariant defaultValue READ defaultValue 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(Types::Unit unit READ unit CONSTANT)
Q_PROPERTY(QString unitString READ unitString CONSTANT) Q_PROPERTY(QString unitString READ unitString CONSTANT)
public: public:
StateType(QObject *parent = 0); StateType(QObject *parent = nullptr);
QString id() const; QString id() const;
void setId(const QString &id); void setId(const QString &id);

View File

@ -11,26 +11,46 @@ ItemDelegate {
property int operatorType: ParamDescriptors.ValueOperatorEquals property int operatorType: ParamDescriptors.ValueOperatorEquals
contentItem: ColumnLayout { contentItem: ColumnLayout {
Label {
Layout.fillWidth: true
text: paramType.displayName
}
RowLayout { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
spacing: app.margins spacing: app.margins
Label {
text: paramType.displayName
}
ComboBox { ComboBox {
FontMetrics {
id: fm
}
Layout.fillWidth: true 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()) { switch (paramType.type.toLowerCase()) {
case "bool": case "bool":
case "string": case "string":
case "qstring": case "qstring":
case "color": case "color":
return [qsTr("is"), qsTr("is not")]; return false;
case "int": case "int":
case "double": 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: { onCurrentTextChanged: {
switch (currentText) { switch (currentText) {
case qsTr("is"): case qsTr("is"):
@ -84,6 +104,10 @@ ItemDelegate {
return null; return null;
} }
} }
Label {
text: paramType.unitString
}
} }
Loader { Loader {
@ -107,8 +131,8 @@ ItemDelegate {
Label { Label {
text: { text: {
switch (root.paramType.type.toLowerCase()) { switch (root.paramType.type.toLowerCase()) {
case "int": case "double":
return Math.round(root.value) return Math.round(root.value * 10) / 10
} }
return root.value return root.value
} }
@ -133,6 +157,13 @@ ItemDelegate {
Slider { Slider {
from: paramType.minValue from: paramType.minValue
to: paramType.maxValue to: paramType.maxValue
stepSize: {
switch (root.paramType.type.toLowerCase()) {
case "double":
return 0.1
}
return 1
}
Layout.fillWidth: true Layout.fillWidth: true
onMoved: { onMoved: {
root.value = value; root.value = value;