From 3bcfda6b18e6bc82cdbd9e5144e9a41300f16a60 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Mon, 12 Aug 2024 10:37:11 +0700 Subject: [PATCH] Harmonize handling of QField's (multi)value relation editor widget with that of QGIS --- src/core/featurechecklistmodel.cpp | 25 +++++++++++++------------ src/qml/editorwidgets/ValueRelation.qml | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/core/featurechecklistmodel.cpp b/src/core/featurechecklistmodel.cpp index f26c0c6878..09a799336b 100644 --- a/src/core/featurechecklistmodel.cpp +++ b/src/core/featurechecklistmodel.cpp @@ -61,8 +61,6 @@ QHash FeatureCheckListModel::roleNames() const QVariant FeatureCheckListModel::attributeValue() const { - QVariant value; - QVariantList vl; //store as QVariantList because the field type supports data structure for ( const QString &s : std::as_const( mCheckedEntries ) ) @@ -83,23 +81,26 @@ QVariant FeatureCheckListModel::attributeValue() const } } - if ( mAllowMulti ) + QVariant value; + if ( !vl.isEmpty() ) { - if ( mAttributeField.type() == QMetaType::QVariantMap || mAttributeField.type() == QMetaType::QVariantList || mAttributeField.type() == QMetaType::QStringList ) + if ( mAllowMulti ) { - value = vl; + if ( mAttributeField.type() == QMetaType::QVariantMap || mAttributeField.type() == QMetaType::QVariantList || mAttributeField.type() == QMetaType::QStringList ) + { + value = vl; + } + else + { + //make string + value = QgsPostgresStringUtils::buildArray( vl ); + } } else { - //make string - value = QgsPostgresStringUtils::buildArray( vl ); + value = vl.first(); } } - else - { - value = vl.first(); - } - return value; } diff --git a/src/qml/editorwidgets/ValueRelation.qml b/src/qml/editorwidgets/ValueRelation.qml index 920dad58dc..c5deaf22cc 100644 --- a/src/qml/editorwidgets/ValueRelation.qml +++ b/src/qml/editorwidgets/ValueRelation.qml @@ -42,7 +42,7 @@ EditorWidgetBase { attributeValue: value !== undefined ? value : "" onListUpdated: { - valueChangeRequested(attributeValue, false); + valueChangeRequested(attributeValue, attributeValue === ""); } }