add a property to determine if geometry is fetched

This commit is contained in:
Denis Rouzaud 2020-04-29 14:03:03 +02:00
parent ae5988cbb1
commit 3090824cbf
7 changed files with 56 additions and 22 deletions

View File

@ -14,7 +14,7 @@ class QgsFeaturePickerModelBase : QAbstractItemModel /Abstract/
Provides a list of features based on filter conditions.
Features are fetched asynchronously.
.. versionadded:: 3.0
.. versionadded:: 3.14
%End
%TypeHeaderCode
@ -108,8 +108,6 @@ Indicator if the model is currently performing any feature iteration in the back
%Docstring
Allows specifying one value that does not need to match the filter criteria but will
still be available in the model as NULL value(s).
.. versionadded:: 3.10
%End
int extraIdentifierValueIndex() const;
@ -130,6 +128,16 @@ Add a NULL entry to the list.
void setAllowNull( bool allowNull );
%Docstring
Add a NULL entry to the list.
%End
bool fetchGeometry() const;
%Docstring
Returns if the geometry is fetched
%End
void setFetchGeometry( bool fetchGeometry );
%Docstring
Defines if the geometry will be fetched
%End
signals:
@ -201,6 +209,12 @@ Notification that the model change is finished. Will always be emitted in sync w
Add a NULL entry to the list.
%End
void fetchGeometryChanged();
%Docstring
Emitted when the fetching of the geometry changes
%End
protected:
QVariant extraIdentifierValue() const;

View File

@ -18,7 +18,7 @@ This offers a combobox with autocompleter that allows selecting features from a
It will show up to 100 entries at a time. The entries can be chosen based on the displayExpression
and whenever text is typed into the combobox, the completer and popup will adjust to features matching the typed text.
.. versionadded:: 3.0
.. versionadded:: 3.14
%End
%TypeHeaderCode
@ -68,16 +68,12 @@ This can be used to integrate additional spatial or other constraints.
%Docstring
Returns the current index of the NULL value, or -1 if NULL values are
not allowed.
.. versionadded:: 3.2
%End
void setFilterExpression( const QString &filterExpression );
%Docstring
An additional expression to further restrict the available features.
This can be used to integrate additional spatial or other constraints.
TODO!
%End
bool allowNull() const;
@ -106,8 +102,6 @@ The index of the currently selected item.
void modelUpdated();
%Docstring
The underlying model has been updated.
.. versionadded:: 3.2
%End
void layerChanged();

View File

@ -38,6 +38,7 @@ bool qVariantListCompare( const QVariantList &a, const QVariantList &b )
QgsFeatureFilterModel::QgsFeatureFilterModel( QObject *parent )
: QgsFeaturePickerModelBase( parent )
{
setFetchGeometry( false );
setExtraIdentifierValueUnguarded( QVariantList() );
}

View File

@ -24,6 +24,7 @@
QgsFeaturePickerModel::QgsFeaturePickerModel( QObject *parent )
: QgsFeaturePickerModelBase( parent )
{
setFetchGeometry( true );
setExtraIdentifierValueUnguarded( FID_NULL );
connect( this, &QgsFeaturePickerModelBase::extraIdentifierValueIndexChanged, this, [ = ]() {emit featureChanged( mEntries.value( mExtraValueIndex ).feature );} );

View File

@ -407,7 +407,8 @@ void QgsFeaturePickerModelBase::scheduledReload()
request.setSubsetOfAttributes( attributes, mSourceLayer->fields() );
}
request.setFlags( QgsFeatureRequest::NoGeometry );
if ( !mFetchGeometry )
request.setFlags( QgsFeatureRequest::NoGeometry );
request.setLimit( QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ).toInt() );
mGatherer = createValuesGatherer( request );
@ -551,6 +552,20 @@ void QgsFeaturePickerModelBase::setAllowNull( bool allowNull )
reload();
}
bool QgsFeaturePickerModelBase::fetchGeometry() const
{
return mFetchGeometry;
}
void QgsFeaturePickerModelBase::setFetchGeometry( bool fetchGeometry )
{
if ( mFetchGeometry == fetchGeometry )
return;
mFetchGeometry = fetchGeometry;
reload();
}
bool QgsFeaturePickerModelBase::extraValueDoesNotExist() const
{

View File

@ -25,7 +25,7 @@
* Provides a list of features based on filter conditions.
* Features are fetched asynchronously.
*
* \since QGIS 3.0
* \since QGIS 3.14
*/
class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABSTRACT
{
@ -36,8 +36,7 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
Q_PROPERTY( QString filterValue READ filterValue WRITE setFilterValue NOTIFY filterValueChanged )
Q_PROPERTY( QString filterExpression READ filterExpression WRITE setFilterExpression NOTIFY filterExpressionChanged )
Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull NOTIFY allowNullChanged )
Q_PROPERTY( bool isLoading READ isLoading NOTIFY isLoadingChanged )
Q_PROPERTY( bool fetchGeometry READ fetchGeometry WRITE setFetchGeometry NOTIFY fetchGeometryGeometry )
Q_PROPERTY( int extraIdentifierValueIndex READ extraIdentifierValueIndex NOTIFY extraIdentifierValueIndexChanged )
public:
@ -130,7 +129,6 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
/**
* Allows specifying one value that does not need to match the filter criteria but will
* still be available in the model as NULL value(s).
* \since QGIS 3.10
*/
virtual void setExtraIdentifierValueToNull() = 0;
@ -154,6 +152,16 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
*/
void setAllowNull( bool allowNull );
/**
* Returns if the geometry is fetched
*/
bool fetchGeometry() const;
/**
* Defines if the geometry will be fetched
*/
void setFetchGeometry( bool fetchGeometry );
signals:
/**
@ -223,6 +231,12 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
*/
void allowNullChanged();
/**
* Emitted when the fetching of the geometry changes
*/
void fetchGeometryChanged();
private slots:
void updateCompleter();
void scheduledReload();
@ -301,6 +315,7 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
mutable QMap< QgsFeatureId, QgsConditionalStyle > mEntryStylesMap;
QgsFeatureExpressionValuesGatherer *mGatherer = nullptr;
bool mFetchGeometry = true;
QTimer mReloadTimer;
bool mShouldReloadCurrentFeature = false;

View File

@ -37,7 +37,7 @@ class QgsFilterLineEdit;
* It will show up to 100 entries at a time. The entries can be chosen based on the displayExpression
* and whenever text is typed into the combobox, the completer and popup will adjust to features matching the typed text.
*
* \since QGIS 3.0
* \since QGIS 3.14
*/
class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
{
@ -91,16 +91,12 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
/**
* Returns the current index of the NULL value, or -1 if NULL values are
* not allowed.
*
* \since QGIS 3.2
*/
int nullIndex() const;
/**
* An additional expression to further restrict the available features.
* This can be used to integrate additional spatial or other constraints.
*
* TODO!
*/
void setFilterExpression( const QString &filterExpression );
@ -127,8 +123,6 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
/**
* The underlying model has been updated.
*
* \since QGIS 3.2
*/
void modelUpdated();