Skip to content

Commit

Permalink
Prevent crashes when opening a feature form containing a blob attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Sep 30, 2024
1 parent 2fbcbfa commit fc68be4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/attributeformmodelbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,10 @@ void AttributeFormModelBase::buildForm( QgsAttributeEditorContainer *container,
continue;

QgsField field = mLayer->fields().at( fieldIndex );
const QgsEditorWidgetSetup setup = findBest( fieldIndex );

item->setData( mLayer->attributeDisplayName( fieldIndex ), AttributeFormModel::Name );
item->setData( !mLayer->editFormConfig().readOnly( fieldIndex ), AttributeFormModel::AttributeEditable );
const QgsEditorWidgetSetup setup = findBest( fieldIndex );
item->setData( !mLayer->editFormConfig().readOnly( fieldIndex ) && setup.type() != QStringLiteral( "Binary" ), AttributeFormModel::AttributeEditable );
item->setData( setup.type(), AttributeFormModel::EditorWidget );
item->setData( setup.config(), AttributeFormModel::EditorWidgetConfig );
item->setData( mFeatureModel->rememberedAttributes().at( fieldIndex ) ? Qt::Checked : Qt::Unchecked, AttributeFormModel::RememberValue );
Expand Down Expand Up @@ -1042,6 +1042,11 @@ QgsEditorWidgetSetup AttributeFormModelBase::findBest( const int fieldIndex )
// on numeric types, take "Range"
return QgsEditorWidgetSetup( QStringLiteral( "Range" ), QVariantMap() );
}
else if ( field.typeName() == QStringLiteral( "Binary" ) )
{
// on blob type, take "Binary"
return QgsEditorWidgetSetup( QStringLiteral( "Binary" ), QVariantMap() );
}
}

return QgsEditorWidgetSetup( QStringLiteral( "TextEdit" ), QVariantMap() );
Expand Down
33 changes: 33 additions & 0 deletions src/qml/editorwidgets/Binary.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import QtQuick
import QtQuick.Controls
import org.qfield
import Theme

EditorWidgetBase {
id: binaryItem

height: childrenRect.height

Label {
id: binaryValue
topPadding: 10
bottomPadding: 10
anchors.left: parent.left
anchors.right: parent.right
font: Theme.defaultFont
color: Theme.mainTextColor
opacity: 0.45
wrapMode: Text.Wrap

text: qsTr('(Blob)')
}

Rectangle {
anchors.left: parent.left
anchors.right: parent.right
y: binaryValue.height - height - binaryValue.bottomPadding / 2
implicitWidth: 120
height: 1
color: Theme.accentLightColor
}
}
1 change: 1 addition & 0 deletions src/qml/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<file>VariableEditor.qml</file>
<file>WelcomeScreen.qml</file>
<file>editorwidgets/EditorWidgetBase.qml</file>
<file>editorwidgets/Binary.qml</file>
<file>editorwidgets/CheckBox.qml</file>
<file>editorwidgets/DateTime.qml</file>
<file>editorwidgets/ExternalResource.qml</file>
Expand Down

0 comments on commit fc68be4

Please sign in to comment.