Skip to content

Commit 74cb4f6

Browse files
committed
Sort values in chained filter comboboxes (relation reference)
Fix #15454
1 parent ecec1f0 commit 74cb4f6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/gui/editorwidgets/qgsrelationreferencewidget.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,14 @@ void QgsRelationReferenceWidget::init()
466466
int idx = mReferencedLayer->fieldNameIndex( fieldName );
467467
QComboBox* cb = new QComboBox();
468468
cb->setProperty( "Field", fieldName );
469+
cb->setProperty( "FieldAlias", mReferencedLayer->attributeDisplayName( idx ) );
469470
mFilterComboBoxes << cb;
470471
mReferencedLayer->uniqueValues( idx, uniqueValues );
471-
cb->addItem( mReferencedLayer->attributeAlias( idx ).isEmpty() ? fieldName : mReferencedLayer->attributeAlias( idx ) );
472+
cb->addItem( mReferencedLayer->attributeDisplayName( idx ) );
472473
QVariant nullValue = QSettings().value( "qgis/nullValue", "NULL" );
473474
cb->addItem( nullValue.toString(), QVariant( mReferencedLayer->fields().at( idx ).type() ) );
474475

476+
std::sort( uniqueValues.begin(), uniqueValues.end(), qgsVariantLessThan );
475477
Q_FOREACH ( const QVariant& v, uniqueValues )
476478
{
477479
cb->addItem( v.toString(), v );
@@ -495,8 +497,8 @@ void QgsRelationReferenceWidget::init()
495497
{
496498
for ( int i = 0; i < mFilterComboBoxes.count() - 1; ++i )
497499
{
498-
QVariant cv = ft.attribute( mFilterFields[i] );
499-
QVariant nv = ft.attribute( mFilterFields[i + 1] );
500+
QVariant cv = ft.attribute( mFilterFields.at( i ) );
501+
QVariant nv = ft.attribute( mFilterFields.at( i + 1 ) );
500502
QString cf = cv.isNull() ? nullValue.toString() : cv.toString();
501503
QString nf = nv.isNull() ? nullValue.toString() : nv.toString();
502504
mFilterCache[mFilterFields[i]][cf] << nf;
@@ -817,14 +819,17 @@ void QgsRelationReferenceWidget::filterChanged()
817819
{
818820
cb->blockSignals( true );
819821
cb->clear();
820-
cb->addItem( cb->property( "Field" ).toString() );
822+
cb->addItem( cb->property( "FieldAlias" ).toString() );
821823

822824
// ccb = scb
823825
// cb = scb + 1
826+
QStringList texts;
824827
Q_FOREACH ( const QString& txt, mFilterCache[ccb->property( "Field" ).toString()][ccb->currentText()] )
825828
{
826-
cb->addItem( txt );
829+
texts << txt;
827830
}
831+
texts.sort();
832+
cb->addItems( texts );
828833

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

0 commit comments

Comments
 (0)