Skip to content

Commit

Permalink
Merge pull request #5350 from pblottiere/null_218
Browse files Browse the repository at this point in the history
[bugfix] Properly update filter comboboxes of relation reference widget
  • Loading branch information
pblottiere authored Oct 19, 2017
2 parents fe52c93 + b70d9b5 commit 05dcb53
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
void QgsRelationReferenceWidget::deleteForeignKey()
{
QVariant nullValue = QSettings().value( "qgis/nullValue", "NULL" );

// deactivate filter comboboxes
if ( mChainFilters && !mFilterComboBoxes.isEmpty() )
{
QComboBox *cb = mFilterComboBoxes.first();
cb->setCurrentIndex( 0 );
disableChainedComboBoxes( cb );
}

if ( mReadOnlySelector )
{
QString nullText = "";
Expand Down Expand Up @@ -522,6 +531,13 @@ void QgsRelationReferenceWidget::init()
mFilterCache[mFilterFields[i]][cf] << nf;
}
}

if ( !mFilterComboBoxes.isEmpty() )
{
QComboBox *cb = mFilterComboBoxes.first();
cb->setCurrentIndex( 0 );
disableChainedComboBoxes( cb );
}
}
}
else
Expand Down
44 changes: 44 additions & 0 deletions tests/src/gui/testqgsrelationreferencewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TestQgsRelationReferenceWidget : public QObject

void testChainFilter();
void testChainFilterRefreshed();
void testChainFilterDeleteForeignKey();

private:
QgsVectorLayer* mLayer1;
Expand Down Expand Up @@ -220,5 +221,48 @@ void TestQgsRelationReferenceWidget::testChainFilterRefreshed()
QCOMPARE( cbs[2]->currentText(), QString( "sleeve" ) );
}

void TestQgsRelationReferenceWidget::testChainFilterDeleteForeignKey()
{
// init a relation reference widget
QStringList filterFields = QStringList() << "material" << "diameter" << "raccord";

QgsRelationReferenceWidget w( new QWidget() );
w.setChainFilters( true );
w.setFilterFields( filterFields );
w.setRelation( *mRelation, true );
w.init();

// check the default status of filter comboboxes
QList<QComboBox *> cbs = w.mFilterComboBoxes;

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

// set a foreign key
w.setForeignKey( QVariant( 11 ) );

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

// delete the foreign key
w.deleteForeignKey();

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

QTEST_MAIN( TestQgsRelationReferenceWidget )
#include "testqgsrelationreferencewidget.moc"

0 comments on commit 05dcb53

Please sign in to comment.