Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Relation reference widget, only send valueChanged signal once
  • Loading branch information
m-kuhn committed May 3, 2018
1 parent da93520 commit 561d255
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
16 changes: 12 additions & 4 deletions src/core/qgsfeaturefiltermodel.cpp
Expand Up @@ -394,9 +394,9 @@ QSet<QString> QgsFeatureFilterModel::requestedAttributes() const
return requestedAttrs;
}

void QgsFeatureFilterModel::setExtraIdentifierValueIndex( int index )
void QgsFeatureFilterModel::setExtraIdentifierValueIndex( int index, bool force )
{
if ( mExtraIdentifierValueIndex == index )
if ( mExtraIdentifierValueIndex == index && !force )
return;

mExtraIdentifierValueIndex = index;
Expand Down Expand Up @@ -437,7 +437,7 @@ void QgsFeatureFilterModel::setExtraIdentifierValueUnguarded( const QVariant &ex
mEntries.prepend( Entry( extraIdentifierValue, QStringLiteral( "(%1)" ).arg( extraIdentifierValue.toString() ), QgsFeature() ) );
endInsertRows();

setExtraIdentifierValueIndex( 0 );
setExtraIdentifierValueIndex( 0, true );

reloadCurrentFeature();
}
Expand Down Expand Up @@ -535,8 +535,16 @@ void QgsFeatureFilterModel::setExtraIdentifierValue( const QVariant &extraIdenti
if ( extraIdentifierValue == mExtraIdentifierValue && extraIdentifierValue.isNull() == mExtraIdentifierValue.isNull() && mExtraIdentifierValue.isValid() )
return;

setExtraIdentifierValueUnguarded( extraIdentifierValue );
if ( mIsSettingExtraIdentifierValue )
return;

mIsSettingExtraIdentifierValue = true;

mExtraIdentifierValue = extraIdentifierValue;

setExtraIdentifierValueUnguarded( extraIdentifierValue );

mIsSettingExtraIdentifierValue = false;

emit extraIdentifierValueChanged();
}
3 changes: 2 additions & 1 deletion src/core/qgsfeaturefiltermodel.h
Expand Up @@ -261,7 +261,7 @@ class CORE_EXPORT QgsFeatureFilterModel : public QAbstractItemModel

private:
QSet<QString> requestedAttributes() const;
void setExtraIdentifierValueIndex( int index );
void setExtraIdentifierValueIndex( int index, bool force = false );
void setExtraValueDoesNotExist( bool extraValueDoesNotExist );
void reload();
void reloadCurrentFeature();
Expand Down Expand Up @@ -298,6 +298,7 @@ class CORE_EXPORT QgsFeatureFilterModel : public QAbstractItemModel
bool mShouldReloadCurrentFeature = false;
bool mExtraValueDoesNotExist = false;
bool mAllowNull = false;
bool mIsSettingExtraIdentifierValue = false;

QString mIdentifierField;

Expand Down
23 changes: 16 additions & 7 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -281,7 +281,8 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant &value )
mRemoveFKButton->setEnabled( mIsEditable );
highlightFeature( mFeature ); // TODO : make this async
updateAttributeEditorFrame( mFeature );
emit foreignKeyChanged( foreignKey() );

emitForeignKeyChanged( foreignKey() );
}

void QgsRelationReferenceWidget::deleteForeignKey()
Expand All @@ -304,18 +305,16 @@ void QgsRelationReferenceWidget::deleteForeignKey()
nullText = tr( "%1 (no selection)" ).arg( nullValue );
}
mLineEdit->setText( nullText );
mForeignKey = QVariant();
mForeignKey = QVariant( QVariant::Int );
mFeature.setValid( false );
}
else
{
mComboBox->setIdentifierValue( QVariant() );


mComboBox->setIdentifierValue( QVariant( QVariant::Int ) );
}
mRemoveFKButton->setEnabled( false );
updateAttributeEditorFrame( QgsFeature() );
emit foreignKeyChanged( QVariant( QVariant::Int ) );
emitForeignKeyChanged( QVariant( QVariant::Int ) );
}

QgsFeature QgsRelationReferenceWidget::referencedFeature() const
Expand Down Expand Up @@ -667,7 +666,8 @@ void QgsRelationReferenceWidget::comboReferenceChanged( int index )
mReferencedLayer->getFeatures( mComboBox->currentFeatureRequest() ).nextFeature( mFeature );
highlightFeature( mFeature );
updateAttributeEditorFrame( mFeature );
emit foreignKeyChanged( mFeature.attribute( mReferencedFieldIdx ) );

emitForeignKeyChanged( mComboBox->identifierValue() );
}

void QgsRelationReferenceWidget::updateAttributeEditorFrame( const QgsFeature &feature )
Expand Down Expand Up @@ -900,3 +900,12 @@ void QgsRelationReferenceWidget::disableChainedComboBoxes( const QComboBox *scb
ccb = cb;
}
}

void QgsRelationReferenceWidget::emitForeignKeyChanged( const QVariant &foreignKey )
{
if ( foreignKey != mForeignKey || foreignKey.isNull() != mForeignKey.isNull() )
{
mForeignKey = foreignKey;
emit foreignKeyChanged( foreignKey );
}
}
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidget.h
Expand Up @@ -188,6 +188,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
void highlightFeature( QgsFeature f = QgsFeature(), CanvasExtent canvasExtent = Fixed );
void updateAttributeEditorFrame( const QgsFeature &feature );
void disableChainedComboBoxes( const QComboBox *cb );
void emitForeignKeyChanged( const QVariant &foreignKey );

// initialized
QgsAttributeEditorContext mEditorContext;
Expand Down

0 comments on commit 561d255

Please sign in to comment.