Skip to content
Permalink
Browse files

Merge pull request #33765 from signedav/fix_null_reset

Fix NULL set of fkeys in QgsFeatureListModel
  • Loading branch information
signedav committed Jan 16, 2020
2 parents 71808d2 + f3d14f9 commit 10cbf59f16cdd2fff8f496844acc18f1479e86d4
@@ -581,7 +581,7 @@ void QgsFeatureFilterModel::setIdentifierFields( const QStringList &identifierFi

mIdentifierFields = identifierFields;
emit identifierFieldChanged();
setExtraIdentifierValues( QVariantList() );
setExtraIdentifierValuesToNull();
}

void QgsFeatureFilterModel::reload()
@@ -612,7 +612,7 @@ QVariantList QgsFeatureFilterModel::extraIdentifierValues() const
void QgsFeatureFilterModel::setExtraIdentifierValue( const QVariant &extraIdentifierValue )
{
if ( extraIdentifierValue.isNull() )
setExtraIdentifierValues( QVariantList() );
setExtraIdentifierValuesToNull();
else
setExtraIdentifierValues( QVariantList() << extraIdentifierValue );
}
@@ -638,5 +638,5 @@ void QgsFeatureFilterModel::setExtraIdentifierValues( const QVariantList &extraI

void QgsFeatureFilterModel::setExtraIdentifierValuesToNull()
{
mExtraIdentifierValues = QVariantList();
setExtraIdentifierValues( QVariantList() );
}
@@ -396,7 +396,7 @@ void QgsRelationReferenceWidget::deleteForeignKeys()
mRemoveFKButton->setEnabled( false );
updateAttributeEditorFrame( QgsFeature() );

emitForeignKeysChanged( foreignKeys(), true );
emitForeignKeysChanged( foreignKeys() );
}

QgsFeature QgsRelationReferenceWidget::referencedFeature() const
@@ -155,6 +155,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() << QVariant() );

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() << QVariant() );

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() );
}

void TestQgsFeatureListComboBox::testAllowNull()
@@ -310,6 +310,22 @@ void TestQgsRelationReferenceWidget::testChainFilterDeleteForeignKey()

QCOMPARE( cbs[2]->currentText(), QString( "raccord" ) );
QCOMPARE( cbs[2]->isEnabled(), false );

// set a foreign key
w.setForeignKeys( QVariantList() << QVariant( 11 ) );

QCOMPARE( cbs[0]->currentText(), QString( "iron" ) );
QCOMPARE( cbs[1]->currentText(), QString( "120" ) );
QCOMPARE( cbs[2]->currentText(), QString( "sleeve" ) );

// set a null foreign key
w.setForeignKeys( QVariantList() << QVariant( QVariant::Int ) );
QCOMPARE( cbs[0]->currentText(), QString( "material" ) );
QCOMPARE( cbs[0]->isEnabled(), true );
QCOMPARE( cbs[1]->currentText(), QString( "diameter" ) );
QCOMPARE( cbs[1]->isEnabled(), false );
QCOMPARE( cbs[2]->currentText(), QString( "raccord" ) );
QCOMPARE( cbs[2]->isEnabled(), false );
}

void TestQgsRelationReferenceWidget::testInvalidRelation()
@@ -347,7 +363,6 @@ void TestQgsRelationReferenceWidget::testSetGetForeignKey()
QCOMPARE( spy.count(), 3 );
}


// Test issue https://github.com/qgis/QGIS/issues/29884
// Relation reference widget wrong feature when "on map identification"
void TestQgsRelationReferenceWidget::testIdentifyOnMap()
@@ -396,9 +411,9 @@ class DummyVectorLayerTools : public QgsVectorLayerTools // clazy:exclude=missin

bool startEditing( QgsVectorLayer * ) const override {return true;}

bool stopEditing( QgsVectorLayer *, bool = true ) const override {return true;};
bool stopEditing( QgsVectorLayer *, bool = true ) const override {return true;}

bool saveEdits( QgsVectorLayer * ) const override {return true;};
bool saveEdits( QgsVectorLayer * ) const override {return true;}
};

void TestQgsRelationReferenceWidget::testAddEntry()

0 comments on commit 10cbf59

Please sign in to comment.
You can’t perform that action at this time.