From 1a77aab181c4b188c57f2484201b5526a5840e8e Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sun, 29 Sep 2024 23:29:16 +0700 Subject: [PATCH] Prevent crashes when opening a feature form containing a blob attribute --- src/core/attributeformmodelbase.cpp | 9 ++++++-- src/qml/editorwidgets/Binary.qml | 33 +++++++++++++++++++++++++++++ src/qml/qml.qrc | 1 + 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/qml/editorwidgets/Binary.qml diff --git a/src/core/attributeformmodelbase.cpp b/src/core/attributeformmodelbase.cpp index ad5fa55167..a8494a9995 100644 --- a/src/core/attributeformmodelbase.cpp +++ b/src/core/attributeformmodelbase.cpp @@ -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 ); @@ -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() ); diff --git a/src/qml/editorwidgets/Binary.qml b/src/qml/editorwidgets/Binary.qml new file mode 100644 index 0000000000..7fe33fe82c --- /dev/null +++ b/src/qml/editorwidgets/Binary.qml @@ -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 + } +} diff --git a/src/qml/qml.qrc b/src/qml/qml.qrc index 63836d9ba2..1d36d8475e 100644 --- a/src/qml/qml.qrc +++ b/src/qml/qml.qrc @@ -48,6 +48,7 @@ VariableEditor.qml WelcomeScreen.qml editorwidgets/EditorWidgetBase.qml + editorwidgets/Binary.qml editorwidgets/CheckBox.qml editorwidgets/DateTime.qml editorwidgets/ExternalResource.qml