Skip to content
Permalink
Browse files
Revert "[Backport queued_ltr_backports] Treat empty array as NULL; an…
…d fix value relation filter with NULL"
  • Loading branch information
elpaso authored and m-kuhn committed Dec 27, 2021
1 parent 3d2288c commit 33a62cac75c38e1d8feccb289961504d4c26da7d
@@ -331,8 +331,7 @@ QSet<QString> QgsValueRelationFieldFormatter::expressionParentFormAttributes( co
QgsExpressionFunction *fd = QgsExpression::QgsExpression::Functions()[f->fnIndex()];
if ( formFunctions.contains( fd->name( ) ) )
{
const QList<QgsExpressionNode *> cExpressionNodes { f->args( )->list() };
for ( const auto &param : qgis::as_const( cExpressionNodes ) )
for ( const auto &param : f->args( )->list() )
{
attributes.insert( param->eval( &exp, &context ).toString() );
}
@@ -356,8 +355,7 @@ QSet<QString> QgsValueRelationFieldFormatter::expressionFormAttributes( const QS
QgsExpressionFunction *fd = QgsExpression::QgsExpression::Functions()[f->fnIndex()];
if ( formFunctions.contains( fd->name( ) ) )
{
const QList<QgsExpressionNode *> cExpressionNodes { f->args( )->list() };
for ( const auto &param : qgis::as_const( cExpressionNodes ) )
for ( const auto &param : f->args( )->list() )
{
attributes.insert( param->eval( &exp, &context ).toString() );
}
@@ -373,7 +371,7 @@ bool QgsValueRelationFieldFormatter::expressionIsUsable( const QString &expressi
const QSet<QString> attrs = expressionFormAttributes( expression );
for ( auto it = attrs.constBegin() ; it != attrs.constEnd(); it++ )
{
if ( feature.fieldNameIndex( *it ) < 0 )
if ( ! feature.attribute( *it ).isValid() )
return false;
}

@@ -76,12 +76,6 @@ QVariant QgsValueRelationWidgetWrapper::value() const
}
}

// If there is no selection and allow NULL is not checked return invalid.
if ( selection.isEmpty() && ! config( QStringLiteral( "AllowNull" ) ).toBool( ) )
{
return QVariant();
}

QVariantList vl;
//store as QVariantList because the field type supports data structure
for ( const QString &s : qgis::as_const( selection ) )
@@ -1337,10 +1337,6 @@ void TestQgsValueRelationWidgetWrapper::testWithJsonInSpatialite()

// FEATURE 4
w_favoriteauthors.setFeature( vl_json->getFeature( 4 ) );
// Because allowNull is false we have an invalid variant here
QCOMPARE( w_favoriteauthors.value(), QVariant( ) );
cfg_favoriteauthors[ QStringLiteral( "AllowNull" ) ] = true;
w_favoriteauthors.setConfig( cfg_favoriteauthors );
//check if first feature checked correctly (NULL)
QCOMPARE( w_favoriteauthors.value(), QVariant( QVariantList() ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->checkState(), Qt::Unchecked );
@@ -1350,16 +1346,9 @@ void TestQgsValueRelationWidgetWrapper::testWithJsonInSpatialite()
QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->checkState(), Qt::Unchecked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->checkState(), Qt::Unchecked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 6, 0 )->checkState(), Qt::Unchecked );
cfg_favoriteauthors[ QStringLiteral( "AllowNull" ) ] = false;
w_favoriteauthors.setConfig( cfg_favoriteauthors );

// FEATURE 5
w_favoriteauthors.setFeature( vl_json->getFeature( 5 ) );
// Because allowNull is false we have an invalid variant here
QCOMPARE( w_favoriteauthors.value(), QVariant( ) );

cfg_favoriteauthors[ QStringLiteral( "AllowNull" ) ] = true;
w_favoriteauthors.setConfig( cfg_favoriteauthors );
//check if first feature checked correctly (blank)
QCOMPARE( w_favoriteauthors.value(), QVariant( QVariantList( ) ) );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->checkState(), Qt::Unchecked );
@@ -1507,11 +1496,6 @@ void TestQgsValueRelationWidgetWrapper::testWithJsonInSpatialiteTextFk()
// FEATURE 4
w_favoriteauthors.setFeature( vl_json->getFeature( 4 ) );

// Because allowNull is false we have an invalid variant here
QCOMPARE( w_favoriteauthors.value(), QVariant( ) );
cfg_favoriteauthors[ QStringLiteral( "AllowNull" ) ] = true;
w_favoriteauthors.setConfig( cfg_favoriteauthors );

//check if first feature checked correctly (NULL)
QCOMPARE( w_favoriteauthors.value(), QVariant( QVariantList( ) ) );

@@ -1522,17 +1506,10 @@ void TestQgsValueRelationWidgetWrapper::testWithJsonInSpatialiteTextFk()
QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->checkState(), Qt::Unchecked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->checkState(), Qt::Unchecked );
QCOMPARE( w_favoriteauthors.mTableWidget->item( 6, 0 )->checkState(), Qt::Unchecked );
cfg_favoriteauthors[ QStringLiteral( "AllowNull" ) ] = false;
w_favoriteauthors.setConfig( cfg_favoriteauthors );

// FEATURE 5
w_favoriteauthors.setFeature( vl_json->getFeature( 5 ) );

// Because allowNull is false we have an invalid variant here
QCOMPARE( w_favoriteauthors.value(), QVariant( ) );
cfg_favoriteauthors[ QStringLiteral( "AllowNull" ) ] = true;
w_favoriteauthors.setConfig( cfg_favoriteauthors );

//check if first feature checked correctly (blank)
QCOMPARE( w_favoriteauthors.value(), QVariant( QVariantList() ) );

0 comments on commit 33a62ca

Please sign in to comment.