Skip to content

Commit

Permalink
Fix chained filters and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 26, 2017
1 parent 957f6ab commit 83a02eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -258,6 +258,22 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant &value )
else
{
mComboBox->setIdentifierValue( value );

if ( mChainFilters )
{
QVariant nullValue = QgsApplication::nullRepresentation();

QgsFeatureRequest request = mComboBox->currentFeatureRequest();

mReferencedLayer->getFeatures( request ).nextFeature( mFeature );

for ( int i = 0; i < mFilterFields.size(); i++ )
{
QVariant v = mFeature.attribute( mFilterFields[i] );
QString f = v.isNull() ? nullValue.toString() : v.toString();
mFilterComboBoxes.at( i )->setCurrentIndex( mFilterComboBoxes.at( i )->findText( f ) );
}
}
}

mRemoveFKButton->setEnabled( mIsEditable );
Expand Down Expand Up @@ -292,6 +308,8 @@ void QgsRelationReferenceWidget::deleteForeignKey()
else
{
mComboBox->setIdentifierValue( QVariant() );


}
mRemoveFKButton->setEnabled( false );
updateAttributeEditorFrame( QgsFeature() );
Expand Down
6 changes: 6 additions & 0 deletions tests/src/gui/testqgsrelationreferencewidget.cpp
Expand Up @@ -25,6 +25,7 @@
#include <qgsrelationmanager.h>
#include <attributetable/qgsattributetablefiltermodel.h>
#include "qgsfeaturelistcombobox.h"
#include "qgsfeaturefiltermodel.h"
#include "qgsgui.h"

class TestQgsRelationReferenceWidget : public QObject
Expand Down Expand Up @@ -180,12 +181,17 @@ void TestQgsRelationReferenceWidget::testChainFilter()
cbs[2]->setCurrentIndex( cbs[2]->findText( QStringLiteral( "brides" ) ) );
cbs[1]->setCurrentIndex( cbs[1]->findText( QStringLiteral( "diameter" ) ) );

QEventLoop loop;
connect( qobject_cast<QgsFeatureFilterModel *>( w.mComboBox->model() ), &QgsFeatureFilterModel::filterJobCompleted, &loop, &QEventLoop::quit );
loop.exec();

// combobox should propose NULL, 10 and 11 because the filter is now:
// "material" == 'iron'
QCOMPARE( w.mComboBox->count(), 3 );

// if there's no filter at all, all features' id should be proposed
cbs[0]->setCurrentIndex( cbs[0]->findText( QStringLiteral( "material" ) ) );
loop.exec();
QCOMPARE( w.mComboBox->count(), 4 );
}

Expand Down

0 comments on commit 83a02eb

Please sign in to comment.