Skip to content

Commit

Permalink
add a property to determine if geometry is fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Apr 29, 2020
1 parent ae5988c commit 3090824
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 22 deletions.
20 changes: 17 additions & 3 deletions python/core/auto_generated/qgsfeaturepickermodelbase.sip.in
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 1 addition & 7 deletions python/gui/auto_generated/qgsfeaturepickerwidget.sip.in
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsfeaturefiltermodel.cpp
Expand Up @@ -38,6 +38,7 @@ bool qVariantListCompare( const QVariantList &a, const QVariantList &b )
QgsFeatureFilterModel::QgsFeatureFilterModel( QObject *parent )
: QgsFeaturePickerModelBase( parent )
{
setFetchGeometry( false );
setExtraIdentifierValueUnguarded( QVariantList() );
}

Expand Down
1 change: 1 addition & 0 deletions src/core/qgsfeaturepickermodel.cpp
Expand Up @@ -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 );} );
Expand Down
17 changes: 16 additions & 1 deletion src/core/qgsfeaturepickermodelbase.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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
{
Expand Down
23 changes: 19 additions & 4 deletions src/core/qgsfeaturepickermodelbase.h
Expand Up @@ -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
{
Expand All @@ -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:
Expand Down Expand Up @@ -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;

Expand All @@ -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:

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 1 addition & 7 deletions src/gui/qgsfeaturepickerwidget.h
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 );

Expand All @@ -127,8 +123,6 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget

/**
* The underlying model has been updated.
*
* \since QGIS 3.2
*/
void modelUpdated();

Expand Down

0 comments on commit 3090824

Please sign in to comment.