Skip to content
Permalink
Browse files

Fix chained filters and tests

  • Loading branch information
m-kuhn committed Oct 26, 2017
1 parent 957f6ab commit 83a02eb5343a0e74f2b6b3d4f5b83293b76c8f4d
@@ -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 );
@@ -292,6 +308,8 @@ void QgsRelationReferenceWidget::deleteForeignKey()
else
{
mComboBox->setIdentifierValue( QVariant() );


}
mRemoveFKButton->setEnabled( false );
updateAttributeEditorFrame( QgsFeature() );
@@ -25,6 +25,7 @@
#include <qgsrelationmanager.h>
#include <attributetable/qgsattributetablefiltermodel.h>
#include "qgsfeaturelistcombobox.h"
#include "qgsfeaturefiltermodel.h"
#include "qgsgui.h"

class TestQgsRelationReferenceWidget : public QObject
@@ -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 );
}

0 comments on commit 83a02eb

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