Skip to content
Permalink
Browse files

Relation reference widget, only send valueChanged signal once

  • Loading branch information
m-kuhn committed May 3, 2018
1 parent da93520 commit 561d255cc9537e351ab4d4b8dcc0a74a4ba42942
@@ -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;
@@ -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();
}
@@ -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();
}
@@ -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();
@@ -298,6 +298,7 @@ class CORE_EXPORT QgsFeatureFilterModel : public QAbstractItemModel
bool mShouldReloadCurrentFeature = false;
bool mExtraValueDoesNotExist = false;
bool mAllowNull = false;
bool mIsSettingExtraIdentifierValue = false;

QString mIdentifierField;

@@ -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()
@@ -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
@@ -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 )
@@ -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 );
}
}
@@ -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;

0 comments on commit 561d255

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