Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix RelationReference widget
previously it would not return any value when the content changed since 868eeb2
  • Loading branch information
m-kuhn committed Apr 17, 2015
1 parent d79268c commit 7527651
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
26 changes: 14 additions & 12 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -364,7 +364,7 @@ QVariant QgsRelationReferenceWidget::foreignKey()
}
else
{
return mFidFkMap.value( varFid.value<QgsFeatureId>() );
return mFeature.attribute( mFkeyFieldIdx );
}
}
}
Expand Down Expand Up @@ -510,8 +510,12 @@ void QgsRelationReferenceWidget::init()
mFeatureListModel->setInjectNull( mAllowNull );
if ( mOrderByValue )
{
int sortIdx = mReferencedLayer->fieldNameIndex( QgsExpression( mReferencedLayer->displayExpression() ).referencedColumns().first() );
mFilterModel->sort( sortIdx );
const QStringList referencedColumns = QgsExpression( mReferencedLayer->displayExpression() ).referencedColumns();
if ( referencedColumns.size() > 0 )
{
int sortIdx = mReferencedLayer->fieldNameIndex( referencedColumns.first() );
mFilterModel->sort( sortIdx );
}
}

mComboBox->setModel( mFeatureListModel );
Expand All @@ -531,7 +535,7 @@ void QgsRelationReferenceWidget::init()
mComboBox->setCurrentIndex( mComboBox->findData( mFeature.id(), QgsAttributeTableModel::FeatureIdRole ) );

// Only connect after iterating, to have only one iterator on the referenced table at once
connect( mComboBox, SIGNAL( activated( int ) ), this, SLOT( comboReferenceChanged( int ) ) );
connect( mComboBox, SIGNAL( currentIndexChanged(int) ), this, SLOT( comboReferenceChanged( int ) ) );
QApplication::restoreOverrideCursor();
}
}
Expand Down Expand Up @@ -671,12 +675,11 @@ void QgsRelationReferenceWidget::mapIdentification()

void QgsRelationReferenceWidget::comboReferenceChanged( int index )
{
QgsFeatureId fid = mComboBox->itemData( index ).value<QgsFeatureId>();
QgsFeature feat;
mReferencedLayer->getFeatures( QgsFeatureRequest().setFilterFid( fid ) ).nextFeature( feat );
highlightFeature( feat );
updateAttributeEditorFrame( feat );
emit foreignKeyChanged( mFidFkMap.value( fid ) );
QgsFeatureId fid = mComboBox->itemData( index, QgsAttributeTableModel::FeatureIdRole ).value<QgsFeatureId>();
mReferencedLayer->getFeatures( QgsFeatureRequest().setFilterFid( fid ) ).nextFeature( mFeature );
highlightFeature( mFeature );
updateAttributeEditorFrame( mFeature );
emit foreignKeyChanged( mFeature.attribute( mFkeyFieldIdx ) );
}

void QgsRelationReferenceWidget::updateAttributeEditorFrame( const QgsFeature feature )
Expand Down Expand Up @@ -708,6 +711,7 @@ void QgsRelationReferenceWidget::featureIdentified( const QgsFeature& feature )
else
{
mComboBox->setCurrentIndex( mComboBox->findData( feature.attribute( mFkeyFieldIdx ), QgsAttributeTableModel::FeatureIdRole ) );
mFeature = feature;
}

mRemoveFKButton->setEnabled( mIsEditable );
Expand Down Expand Up @@ -802,8 +806,6 @@ void QgsRelationReferenceWidget::filterChanged()
{
const QString fieldName = cb->property( "Field" ).toString();

cb->itemData( cb->currentIndex() );

if ( cb->currentText() == nullValue.toString() )
{
filters << QString( "\"%1\" IS NULL" ).arg( fieldName );
Expand Down
1 change: 0 additions & 1 deletion src/gui/editorwidgets/qgsrelationreferencewidget.h
Expand Up @@ -176,7 +176,6 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget

// UI
QVBoxLayout* mTopLayout;
QHash<QgsFeatureId, QVariant> mFidFkMap; // Mapping from feature id => foreign key
QToolButton* mMapIdentificationButton;
QToolButton* mRemoveFKButton;
QToolButton* mOpenFormButton;
Expand Down

0 comments on commit 7527651

Please sign in to comment.