code layout

This commit is contained in:
Denis Rouzaud 2020-04-30 06:52:22 +02:00
parent b97543d9cc
commit 9488f06025
7 changed files with 13 additions and 4 deletions

View File

@ -48,6 +48,9 @@ Returns the current feature
signals: signals:
void featureChanged( const QgsFeature &feature ); void featureChanged( const QgsFeature &feature );
%Docstring
Emitted when the current feature changes
%End
}; };

View File

@ -250,6 +250,9 @@ Update the request to match the current feature to be reloaded
%End %End
void setExtraIdentifierValueUnguarded( const QVariant &identifierValue ); void setExtraIdentifierValueUnguarded( const QVariant &identifierValue );
%Docstring
This will set the identifier value to be set in the model even if it doesn't exist currently in the data
%End

View File

@ -40,7 +40,7 @@ QgsFeatureFilterModel::QgsFeatureFilterModel( QObject *parent )
{ {
setFetchGeometry( false ); setFetchGeometry( false );
setFetchLimit( QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ).toInt() ); setFetchLimit( QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ).toInt() );
setExtraIdentifierValueUnguarded( QVariantList() ); setExtraIdentifierValueUnguarded( nullIentifier() );
} }
QString QgsFeatureFilterModel::identifierField() const QString QgsFeatureFilterModel::identifierField() const

View File

@ -25,7 +25,7 @@ QgsFeaturePickerModel::QgsFeaturePickerModel( QObject *parent )
: QgsFeaturePickerModelBase( parent ) : QgsFeaturePickerModelBase( parent )
{ {
setFetchGeometry( true ); setFetchGeometry( true );
setExtraIdentifierValueUnguarded( FID_NULL ); setExtraIdentifierValueUnguarded( nullIentifier() );
connect( this, &QgsFeaturePickerModelBase::extraIdentifierValueIndexChanged, this, [ = ]() {emit featureChanged( feature() );} ); connect( this, &QgsFeaturePickerModelBase::extraIdentifierValueIndexChanged, this, [ = ]() {emit featureChanged( feature() );} );
} }

View File

@ -55,6 +55,7 @@ class CORE_EXPORT QgsFeaturePickerModel : public QgsFeaturePickerModelBase
QgsFeature feature() const; QgsFeature feature() const;
signals: signals:
//! Emitted when the current feature changes
void featureChanged( const QgsFeature &feature ); void featureChanged( const QgsFeature &feature );

View File

@ -274,6 +274,7 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
//! Update the request to match the current feature to be reloaded //! Update the request to match the current feature to be reloaded
virtual void requestToReloadCurrentFeature( QgsFeatureRequest &request ) = 0; virtual void requestToReloadCurrentFeature( QgsFeatureRequest &request ) = 0;
//! This will set the identifier value to be set in the model even if it doesn't exist currently in the data
void setExtraIdentifierValueUnguarded( const QVariant &identifierValue ); void setExtraIdentifierValueUnguarded( const QVariant &identifierValue );
#ifndef SIP_RUN #ifndef SIP_RUN
@ -284,10 +285,11 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
*/ */
virtual QSet<QString> requestedAttributes() const {return {};} virtual QSet<QString> requestedAttributes() const {return {};}
//! Creates the value gatherer
virtual QgsFeatureExpressionValuesGatherer *createValuesGatherer( const QgsFeatureRequest &request ) const = 0; virtual QgsFeatureExpressionValuesGatherer *createValuesGatherer( const QgsFeatureRequest &request ) const = 0;
//! Creates an entry with just the identifier so the feature can be retrieved in a next iteration //! Creates an entry with just the identifier so the feature can be retrieved in a next iteration
virtual QgsFeatureExpressionValuesGatherer::Entry createEntry( const QVariant &identifer ) const = 0; virtual QgsFeatureExpressionValuesGatherer::Entry createEntry( const QVariant &identifier ) const = 0;
//! Returns the identifier of the given entry //! Returns the identifier of the given entry
virtual QVariant entryIdentifier( const QgsFeatureExpressionValuesGatherer::Entry &entry ) const = 0; virtual QVariant entryIdentifier( const QgsFeatureExpressionValuesGatherer::Entry &entry ) const = 0;

View File

@ -102,7 +102,7 @@ class TestQgsRelationEditWidget(unittest.TestCase):
spy = QSignalSpy(w.featureChanged) spy = QSignalSpy(w.featureChanged)
spy.wait() spy.wait()
w.findChild(QComboBox).lineEdit().clear() w.findChild(QComboBox).lineEdit().clear()
QTest.keyClicks(w.findChild(QComboBox).lineEdit(), "test99"); QTest.keyClicks(w.findChild(QComboBox).lineEdit(), "test99")
spy.wait() spy.wait()
self.assertEqual(w.feature().id(), 99) self.assertEqual(w.feature().id(), 99)