Skip to content

Commit

Permalink
Honour precision separately from step for number fields in AttributeF…
Browse files Browse the repository at this point in the history
…orm/AttributeTable
  • Loading branch information
manisandro committed Feb 19, 2025
1 parent ae81731 commit 38c89b3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions components/QtDesignerForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,12 @@ class QtDesignerForm extends React.Component {
const min = floatConstraint(prop.minimum ?? fieldConstraints.min);
const max = floatConstraint(prop.maximum ?? fieldConstraints.max);
const step = prop.singleStep ?? fieldConstraints.step ?? 1;
const precision = prop.decimals ?? 0;
if (widget.class === "QSlider") {
return (<input max={max} min={min} name={elname} onChange={(ev) => updateField(widget.name, ev.target.value)} {...inputConstraints} size={5} step={step} style={fontStyle} type="range" value={value} />);
} else {
const precision = step > 0 ? Math.ceil(-Math.log10(step)) : 0;
value = feature.properties?.[widget.name] ?? null;
return (<NumberInput decimals={precision} max={max} min={min} name={elname} onChange={(val) => updateField(widget.name, val)} {...inputConstraints} style={fontStyle} value={value} />);
return (<NumberInput decimals={precision} max={max} min={min} name={elname} onChange={(val) => updateField(widget.name, val)} {...inputConstraints} step={step} style={fontStyle} value={value} />);
}
} else if (widget.class === "QDateEdit") {
const min = prop.minimumDate ? this.dateConstraint(prop.minimumDate) : "1600-01-01";
Expand Down
3 changes: 2 additions & 1 deletion components/widgets/NumberInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class NumberInput extends React.Component {
prefix: PropTypes.string,
readOnly: PropTypes.bool,
required: PropTypes.bool,
step: PropTypes.number,
style: PropTypes.object,
suffix: PropTypes.string,
value: PropTypes.number
Expand Down Expand Up @@ -68,7 +69,7 @@ export default class NumberInput extends React.Component {
const style = {
width: `calc(${paddingLength} + ${prefixSuffixLength} + ${numberLength})`
};
const step = Math.pow(10, -this.props.decimals);
const step = this.props.step ?? Math.pow(10, -this.props.decimals);
const plusIcon = this.props.mobile ? "plus" : "chevron-up";
const minusIcon = this.props.mobile ? "minus" : "chevron-down";
return (
Expand Down
5 changes: 3 additions & 2 deletions plugins/AttributeTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,12 @@ class AttributeTable extends React.Component {
updateField={updateField} value={value} values={constraints.values} />
);
} else if (field.type === "number") {
const precision = constraints.step > 0 ? Math.ceil(-Math.log10(constraints.step)) : 0;
const precision = constraints.prec ?? 0;
const step = constraints.step ?? 1;
input = (
<NumberInput decimals={precision} disabled={disabled} max={constraints.max} min={constraints.min}
name={field.id} onChange={v => updateField(field.id, v, true)}
readOnly={constraints.readOnly} required={constraints.required} value={value} />
readOnly={constraints.readOnly} required={constraints.required} step={step} value={value} />
);
} else if (field.type === "date") {
// Truncate time portion of ISO date string
Expand Down

0 comments on commit 38c89b3

Please sign in to comment.