Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #46501 from qgis/revert-46440-backport-46439-to-qu…
…eued_ltr_backports

Revert "[Backport queued_ltr_backports] Treat empty array as NULL; and fix value relation filter with NULL"
  • Loading branch information
elpaso committed Dec 15, 2021
2 parents dc8d23b + 6c8eeff commit 93a78f5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 34 deletions.
8 changes: 3 additions & 5 deletions src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp
Expand Up @@ -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() );
}
Expand All @@ -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() );
}
Expand All @@ -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;
}

Expand Down
6 changes: 0 additions & 6 deletions src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp
Expand Up @@ -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 ) )
Expand Down
23 changes: 0 additions & 23 deletions tests/src/gui/testqgsvaluerelationwidgetwrapper.cpp
Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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( ) ) );

Expand All @@ -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() ) );

Expand Down

0 comments on commit 93a78f5

Please sign in to comment.