Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Fix chained filters and tests
- Loading branch information
|
@@ -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 ); |
|
|
} |
|
|
|
|
|