Skip to content

Commit

Permalink
fix entering negative values in range field (#2560)
Browse files Browse the repository at this point in the history
* fix entering negative values

* better fix for range editor issue with negative numbers

* add tests
  • Loading branch information
alexbruy committed Feb 20, 2023
1 parent 769865a commit 55f61ed
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/attributes/attributecontroller.cpp
Expand Up @@ -647,7 +647,7 @@ bool AttributeController::recalculateDefaultValues(
{
mFeatureLayerPair.featureRef().setAttribute( item->fieldIndex(), val );
item->setRawValue( val );
emit formDataChanged( item->id(), { AttributeFormModel::RawValue } );
emit formDataChanged( item->id(), { AttributeFormModel::RawValue, AttributeFormModel::RawValueIsNull } );
// Update also expression context after an attribute change
expressionContext.setFeature( featureLayerPair().featureRef() );
changedFormItems.insert( item->id() );
Expand Down Expand Up @@ -1202,7 +1202,7 @@ bool AttributeController::setFormValue( const QUuid &id, QVariant value )
else
{
mFeatureLayerPair.featureRef().setAttribute( item->fieldIndex(), val );
emit formDataChanged( item->id(), { AttributeFormModel::AttributeValue, AttributeFormModel::AttributeValueIsNull } );
emit formDataChanged( item->id(), { AttributeFormModel::AttributeValue, AttributeFormModel::RawValueIsNull } );
}
recalculateDerivedItems( true, false );
return true;
Expand Down
6 changes: 3 additions & 3 deletions app/attributes/attributeformmodel.cpp
Expand Up @@ -58,8 +58,8 @@ QVariant AttributeFormModel::data( const QModelIndex &index, int role ) const
return item->type();
case AttributeValue:
return mController->formValue( item->fieldIndex() );
case AttributeValueIsNull:
return mController->formValue( item->fieldIndex() ).isNull();
case RawValueIsNull:
return item->rawValue().isNull();
case AttributeEditable:
return item->isEditable();
case AttributeFormModel::EditorWidget:
Expand Down Expand Up @@ -117,7 +117,7 @@ QHash<int, QByteArray> AttributeFormModel::roleNames() const
roles[Type] = QByteArray( "Type" );
roles[Name] = QByteArray( "Name" );
roles[AttributeValue] = QByteArray( "AttributeValue" );
roles[AttributeValueIsNull] = QByteArray( "AttributeValueIsNull" );
roles[RawValueIsNull] = QByteArray( "RawValueIsNull" );
roles[AttributeEditable] = QByteArray( "AttributeEditable" );
roles[EditorWidget] = QByteArray( "EditorWidget" );
roles[EditorWidgetConfig] = QByteArray( "EditorWidgetConfig" );
Expand Down
2 changes: 1 addition & 1 deletion app/attributes/attributeformmodel.h
Expand Up @@ -49,7 +49,7 @@ class AttributeFormModel : public QAbstractListModel
Type = Qt::UserRole + 1, //!< User role used to identify either "field" or "container" type of item
Name, //!< Field Name
AttributeValue, //!< Field Value
AttributeValueIsNull, //!< Whether field value is null (QVariant with set type, but NULL flag)
RawValueIsNull, //!< Whether field raw value is null (QVariant with set type, but NULL flag)
AttributeEditable, //!< Whether is field editable
EditorWidget, //!< Widget type to represent the data (text field, value map, ...)
EditorWidgetConfig, //!< Widget configuration
Expand Down
2 changes: 1 addition & 1 deletion app/qml/form/FeatureForm.qml
Expand Up @@ -496,7 +496,7 @@ Item {
anchors { left: placeholder.left; right: placeholder.right }

property var value: RawValue
property bool valueIsNull: AttributeValueIsNull
property bool valueIsNull: RawValueIsNull

property var field: Field
property var widget: EditorWidget
Expand Down
2 changes: 2 additions & 0 deletions app/test/testattributecontroller.cpp
Expand Up @@ -381,6 +381,8 @@ void TestAttributeController::testValidationMessages()
{ items.at( 3 ), "13", V::softUniqueFailed, FieldValidator::Warning }, // there should already be feature with such value
{ items.at( 3 ), "14", "", FieldValidator::Valid },
{ items.at( 3 ), "14sad", V::numberInvalid, FieldValidator::Error },
{ items.at( 3 ), "-", V::numberInvalid, FieldValidator::Error },
{ items.at( 3 ), ".", V::numberInvalid, FieldValidator::Error },
{ items.at( 3 ), "14", "", FieldValidator::Valid },

// Attribute - Occupied Expression, must be TRUE - HARD, expression descriptionn: 'Must be true'
Expand Down

1 comment on commit 55f61ed

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 23.02.407211 just submitted!

Please sign in to comment.