Skip to content

Commit

Permalink
Fixes #34537 : Allow setting null in relation reference widget
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 committed Apr 15, 2020
1 parent 75b5f39 commit 091c86a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsfeaturefiltermodel.cpp
Expand Up @@ -623,7 +623,7 @@ QVariantList QgsFeatureFilterModel::extraIdentifierValues() const
{
QVariantList nullValues;
for ( int i = 0; i < mIdentifierFields.count(); i++ )
nullValues << QVariant();
nullValues << QVariant( QVariant::Int );
return nullValues;
}
return mExtraIdentifierValues;
Expand Down
23 changes: 23 additions & 0 deletions tests/src/gui/testqgsfeaturelistcombobox.cpp
Expand Up @@ -160,6 +160,29 @@ void TestQgsFeatureListComboBox::testMultipleForeignKeys()

cb->setIdentifierValues( QVariantList() << "gold" << 777 << "rush" );
QCOMPARE( cb->identifierValues(), QVariantList() << "gold" << 777 << "rush" );

cb->setIdentifierValuesToNull();
QCOMPARE( cb->identifierValues().count(), 3 );
QCOMPARE( cb->identifierValues(), QVariantList() << QVariant( QVariant::Int ) << QVariant( QVariant::Int ) << QVariant( QVariant::Int ) );

cb->setIdentifierValues( QVariantList() << "silver" << 888 << "fish" );
QCOMPARE( cb->identifierValues(), QVariantList() << "silver" << 888 << "fish" );

cb->setIdentifierValuesToNull();
QCOMPARE( cb->identifierValues().count(), 3 );
QCOMPARE( cb->identifierValues(), QVariantList() << QVariant( QVariant::Int ) << QVariant( QVariant::Int ) << QVariant( QVariant::Int ) );

cb->setIdentifierFields( QStringList() << "material" << "raccord" );
cb->setDisplayExpression( "\"material\" || ' ' || \"raccord\"" );
cb->setAllowNull( true );

cb->setIdentifierValues( QVariantList() << "gold" << "fish" );
QCOMPARE( cb->identifierValues().count(), 2 );
QCOMPARE( cb->identifierValues(), QVariantList() << "gold" << "fish" );

cb->setIdentifierValuesToNull();
QCOMPARE( cb->identifierValues().count(), 2 );
QCOMPARE( cb->identifierValues(), QVariantList() << QVariant( QVariant::Int ) << QVariant( QVariant::Int ) );
}

void TestQgsFeatureListComboBox::testAllowNull()
Expand Down
5 changes: 3 additions & 2 deletions tests/src/gui/testqgsrelationreferencewidget.cpp
Expand Up @@ -511,8 +511,9 @@ void TestQgsRelationReferenceWidget::testSetGetForeignKey()
QCOMPARE( w.mComboBox->currentText(), QStringLiteral( "(12)" ) );
QCOMPARE( spy.count(), 2 );

w.setForeignKeys( QVariantList() << QVariant( QVariant::Int ) );
Q_ASSERT( w.foreignKeys().at( 0 ).isNull() );
w.setForeignKeys( QVariantList() << QVariant() );
QVERIFY( w.foreignKeys().at( 0 ).isNull() );
QVERIFY( w.foreignKeys().at( 0 ).isValid() );
QCOMPARE( spy.count(), 3 );
}

Expand Down

0 comments on commit 091c86a

Please sign in to comment.