Skip to content
Permalink
Browse files

Sort values in chained filter comboboxes (relation reference)

Fix #15454
  • Loading branch information
m-kuhn committed Aug 19, 2016
1 parent ecec1f0 commit 74cb4f6b23bff57231161f3ddf5da017ec81f530
Showing with 10 additions and 5 deletions.
  1. +10 −5 src/gui/editorwidgets/qgsrelationreferencewidget.cpp
@@ -466,12 +466,14 @@ void QgsRelationReferenceWidget::init()
int idx = mReferencedLayer->fieldNameIndex( fieldName );
QComboBox* cb = new QComboBox();
cb->setProperty( "Field", fieldName );
cb->setProperty( "FieldAlias", mReferencedLayer->attributeDisplayName( idx ) );
mFilterComboBoxes << cb;
mReferencedLayer->uniqueValues( idx, uniqueValues );
cb->addItem( mReferencedLayer->attributeAlias( idx ).isEmpty() ? fieldName : mReferencedLayer->attributeAlias( idx ) );
cb->addItem( mReferencedLayer->attributeDisplayName( idx ) );
QVariant nullValue = QSettings().value( "qgis/nullValue", "NULL" );
cb->addItem( nullValue.toString(), QVariant( mReferencedLayer->fields().at( idx ).type() ) );

std::sort( uniqueValues.begin(), uniqueValues.end(), qgsVariantLessThan );
Q_FOREACH ( const QVariant& v, uniqueValues )
{
cb->addItem( v.toString(), v );
@@ -495,8 +497,8 @@ void QgsRelationReferenceWidget::init()
{
for ( int i = 0; i < mFilterComboBoxes.count() - 1; ++i )
{
QVariant cv = ft.attribute( mFilterFields[i] );
QVariant nv = ft.attribute( mFilterFields[i + 1] );
QVariant cv = ft.attribute( mFilterFields.at( i ) );
QVariant nv = ft.attribute( mFilterFields.at( i + 1 ) );
QString cf = cv.isNull() ? nullValue.toString() : cv.toString();
QString nf = nv.isNull() ? nullValue.toString() : nv.toString();
mFilterCache[mFilterFields[i]][cf] << nf;
@@ -817,14 +819,17 @@ void QgsRelationReferenceWidget::filterChanged()
{
cb->blockSignals( true );
cb->clear();
cb->addItem( cb->property( "Field" ).toString() );
cb->addItem( cb->property( "FieldAlias" ).toString() );

// ccb = scb
// cb = scb + 1
QStringList texts;
Q_FOREACH ( const QString& txt, mFilterCache[ccb->property( "Field" ).toString()][ccb->currentText()] )
{
cb->addItem( txt );
texts << txt;
}
texts.sort();
cb->addItems( texts );

cb->setEnabled( true );
cb->blockSignals( false );

0 comments on commit 74cb4f6

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