Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add setting for fetch limit
  • Loading branch information
3nids committed Apr 29, 2020
1 parent 3090824 commit 0119bb5
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 8 deletions.
5 changes: 5 additions & 0 deletions python/core/auto_generated/qgsfeaturepickermodel.sip.in
Expand Up @@ -39,6 +39,11 @@ still be available in the model as NULL value(s).
void setFeature( const QgsFeatureId &fid );
%Docstring
Set the feature to the given feature id
%End

QgsFeature feature() const;
%Docstring
Returns the current feature
%End

signals:
Expand Down
15 changes: 15 additions & 0 deletions python/core/auto_generated/qgsfeaturepickermodelbase.sip.in
Expand Up @@ -138,6 +138,16 @@ Returns if the geometry is fetched
void setFetchGeometry( bool fetchGeometry );
%Docstring
Defines if the geometry will be fetched
%End

int fetchLimit() const;
%Docstring
Returns the feature request fetch limit
%End

void setFetchLimit( int fetchLimit );
%Docstring
Defines the feature request fetch limit
%End

signals:
Expand Down Expand Up @@ -214,6 +224,11 @@ Add a NULL entry to the list.
Emitted when the fetching of the geometry changes
%End

void fetchLimitChanged();
%Docstring
Emitted when the fetching limit for the feature request changes
%End


protected:

Expand Down
39 changes: 37 additions & 2 deletions python/gui/auto_generated/qgsfeaturepickerwidget.sip.in
Expand Up @@ -44,6 +44,11 @@ The layer from which features should be listed.
void setFeature( QgsFeatureId featureId );
%Docstring
Sets the current index by using the given feature
%End

QgsFeature feature() const;
%Docstring
Returns the current feature
%End

QString displayExpression() const;
Expand Down Expand Up @@ -84,6 +89,26 @@ Determines if a NULL value should be available in the list.
void setAllowNull( bool allowNull );
%Docstring
Determines if a NULL value should be available in 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

int fetchLimit() const;
%Docstring
Returns the feature request fetch limit
%End

void setFetchLimit( int fetchLimit );
%Docstring
Defines the feature request fetch limit
%End

QModelIndex currentModelIndex() const;
Expand Down Expand Up @@ -119,16 +144,26 @@ the the value to match the typed text against.
%Docstring
An additional expression to further restrict the available features.
This can be used to integrate additional spatial or other constraints.
%End

void featureChanged( const QgsFeature &feature );
%Docstring
Sends the feature as soon as it is chosen
%End

void allowNullChanged();
%Docstring
Determines if a NULL value should be available in the list.
%End

void featureChanged( const QgsFeature &feature );
void fetchGeometryChanged();
%Docstring
Sends the feature as soon as it is chosen
Emitted when the fetching of the geometry changes
%End

void fetchLimitChanged();
%Docstring
Emitted when the fetching limit for the feature request changes
%End

};
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsfeaturefiltermodel.cpp
Expand Up @@ -39,6 +39,7 @@ QgsFeatureFilterModel::QgsFeatureFilterModel( QObject *parent )
: QgsFeaturePickerModelBase( parent )
{
setFetchGeometry( false );
setFetchLimit( QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ).toInt() );
setExtraIdentifierValueUnguarded( QVariantList() );
}

Expand Down
7 changes: 6 additions & 1 deletion src/core/qgsfeaturepickermodel.cpp
Expand Up @@ -27,7 +27,7 @@ QgsFeaturePickerModel::QgsFeaturePickerModel( QObject *parent )
setFetchGeometry( true );
setExtraIdentifierValueUnguarded( FID_NULL );

connect( this, &QgsFeaturePickerModelBase::extraIdentifierValueIndexChanged, this, [ = ]() {emit featureChanged( mEntries.value( mExtraValueIndex ).feature );} );
connect( this, &QgsFeaturePickerModelBase::extraIdentifierValueIndexChanged, this, [ = ]() {emit featureChanged( feature() );} );
}

void QgsFeaturePickerModel::requestToReloadCurrentFeature( QgsFeatureRequest &request )
Expand Down Expand Up @@ -71,6 +71,11 @@ void QgsFeaturePickerModel::setFeature( const QgsFeatureId &fid )
setExtraIdentifierValue( fid );
}

QgsFeature QgsFeaturePickerModel::feature() const
{
return mEntries.value( mExtraValueIndex ).feature;
}

QgsFeatureExpressionValuesGatherer *QgsFeaturePickerModel::createValuesGatherer( const QgsFeatureRequest &request ) const
{
return new QgsFeatureExpressionValuesGatherer( sourceLayer(), displayExpression(), request );
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsfeaturepickermodel.h
Expand Up @@ -49,6 +49,11 @@ class CORE_EXPORT QgsFeaturePickerModel : public QgsFeaturePickerModelBase
//! Set the feature to the given feature id
void setFeature( const QgsFeatureId &fid );

/**
* Returns the current feature
*/
QgsFeature feature() const;

signals:
void featureChanged( const QgsFeature &feature );

Expand Down
16 changes: 15 additions & 1 deletion src/core/qgsfeaturepickermodelbase.cpp
Expand Up @@ -409,7 +409,7 @@ void QgsFeaturePickerModelBase::scheduledReload()

if ( !mFetchGeometry )
request.setFlags( QgsFeatureRequest::NoGeometry );
request.setLimit( QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ).toInt() );
request.setLimit( mFetchLimit );

mGatherer = createValuesGatherer( request );
mGatherer->setData( mShouldReloadCurrentFeature );
Expand Down Expand Up @@ -566,6 +566,20 @@ void QgsFeaturePickerModelBase::setFetchGeometry( bool fetchGeometry )
reload();
}

int QgsFeaturePickerModelBase::fetchLimit() const
{
return mFetchLimit;
}

void QgsFeaturePickerModelBase::setFetchLimit( int fetchLimit )
{
if ( fetchLimit == mFetchLimit )
return;

mFetchLimit = fetchLimit;
emit fetchLimitChanged();
}


bool QgsFeaturePickerModelBase::extraValueDoesNotExist() const
{
Expand Down
19 changes: 18 additions & 1 deletion src/core/qgsfeaturepickermodelbase.h
Expand Up @@ -36,7 +36,8 @@ 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 fetchGeometry READ fetchGeometry WRITE setFetchGeometry NOTIFY fetchGeometryGeometry )
Q_PROPERTY( bool fetchGeometry READ fetchGeometry WRITE setFetchGeometry NOTIFY fetchGeometryChanged )
Q_PROPERTY( int fetchLimit READ fetchLimit WRITE setFetchLimit NOTIFY fetchLimitChanged )
Q_PROPERTY( int extraIdentifierValueIndex READ extraIdentifierValueIndex NOTIFY extraIdentifierValueIndexChanged )

public:
Expand Down Expand Up @@ -162,6 +163,16 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
*/
void setFetchGeometry( bool fetchGeometry );

/**
* Returns the feature request fetch limit
*/
int fetchLimit() const;

/**
* Defines the feature request fetch limit
*/
void setFetchLimit( int fetchLimit );

signals:

/**
Expand Down Expand Up @@ -236,6 +247,11 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
*/
void fetchGeometryChanged();

/**
* Emitted when the fetching limit for the feature request changes
*/
void fetchLimitChanged();


private slots:
void updateCompleter();
Expand Down Expand Up @@ -316,6 +332,7 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST

QgsFeatureExpressionValuesGatherer *mGatherer = nullptr;
bool mFetchGeometry = true;
int mFetchLimit = 100;

QTimer mReloadTimer;
bool mShouldReloadCurrentFeature = false;
Expand Down
28 changes: 27 additions & 1 deletion src/gui/qgsfeaturepickerwidget.cpp
Expand Up @@ -41,6 +41,8 @@ QgsFeaturePickerWidget::QgsFeaturePickerWidget( QWidget *parent )
connect( mModel, &QgsFeaturePickerModel::isLoadingChanged, this, &QgsFeaturePickerWidget::onLoadingChanged );
connect( mModel, &QgsFeaturePickerModel::filterJobCompleted, this, &QgsFeaturePickerWidget::onFilterUpdateCompleted );
connect( mModel, &QgsFeaturePickerModel::allowNullChanged, this, &QgsFeaturePickerWidget::allowNullChanged );
connect( mModel, &QgsFeaturePickerModel::fetchGeometryChanged, this, &QgsFeaturePickerWidget::fetchGeometryChanged );
connect( mModel, &QgsFeaturePickerModel::fetchLimitChanged, this, &QgsFeaturePickerWidget::fetchLimitChanged );
connect( mModel, &QgsFeaturePickerModel::extraIdentifierValueIndexChanged, mComboBox, &QComboBox::setCurrentIndex );
connect( mModel, &QgsFeaturePickerModel::featureChanged, this, &QgsFeaturePickerWidget::featureChanged );
connect( mCompleter, static_cast<void( QCompleter::* )( const QModelIndex & )>( &QCompleter::highlighted ), this, &QgsFeaturePickerWidget::onItemSelected );
Expand Down Expand Up @@ -80,6 +82,11 @@ void QgsFeaturePickerWidget::setFeature( QgsFeatureId featureId )
mModel->setFeature( featureId );
}

QgsFeature QgsFeaturePickerWidget::feature() const
{
return mModel->feature();
}

QString QgsFeaturePickerWidget::displayExpression() const
{
return mModel->displayExpression();
Expand Down Expand Up @@ -228,7 +235,6 @@ void QgsFeaturePickerWidget::LineEditState::store( QLineEdit *lineEdit )
selectionStart = lineEdit->selectionStart();
selectionLength = lineEdit->selectedText().length();
cursorPosition = lineEdit->cursorPosition();

}

void QgsFeaturePickerWidget::LineEditState::restore( QLineEdit *lineEdit ) const
Expand All @@ -238,3 +244,23 @@ void QgsFeaturePickerWidget::LineEditState::restore( QLineEdit *lineEdit ) const
if ( selectionStart > -1 )
lineEdit->setSelection( selectionStart, selectionLength );
}

bool QgsFeaturePickerWidget::fetchGeometry() const
{
return mModel->fetchGeometry();
}

void QgsFeaturePickerWidget::setFetchGeometry( bool fetchGeometry )
{
mModel->setFetchGeometry( fetchGeometry );
}

int QgsFeaturePickerWidget::fetchLimit() const
{
return mModel->fetchLimit();
}

void QgsFeaturePickerWidget::setFetchLimit( int fetchLimit )
{
mModel->setFetchLimit( fetchLimit );
}
41 changes: 39 additions & 2 deletions src/gui/qgsfeaturepickerwidget.h
Expand Up @@ -47,6 +47,8 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
Q_PROPERTY( QString filterExpression READ filterExpression WRITE setFilterExpression NOTIFY filterExpressionChanged )
Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull NOTIFY allowNullChanged )
Q_PROPERTY( bool fetchGeometry READ fetchGeometry WRITE setFetchGeometry NOTIFY fetchGeometryChanged )
Q_PROPERTY( int fetchLimit READ fetchLimit WRITE setFetchLimit NOTIFY fetchLimitChanged )

public:

Expand All @@ -70,6 +72,11 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
*/
void setFeature( QgsFeatureId featureId );

/**
* Returns the current feature
*/
QgsFeature feature() const;

/**
* The display expression will be used to display features as well as
* the value to match the typed text against.
Expand Down Expand Up @@ -110,6 +117,26 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
*/
void setAllowNull( bool allowNull );

/**
* Returns if the geometry is fetched
*/
bool fetchGeometry() const;

/**
* Defines if the geometry will be fetched
*/
void setFetchGeometry( bool fetchGeometry );

/**
* Returns the feature request fetch limit
*/
int fetchLimit() const;

/**
* Defines the feature request fetch limit
*/
void setFetchLimit( int fetchLimit );

/**
* The index of the currently selected item.
*/
Expand Down Expand Up @@ -143,13 +170,23 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
*/
void filterExpressionChanged();

//! Sends the feature as soon as it is chosen
void featureChanged( const QgsFeature &feature );

/**
* Determines if a NULL value should be available in the list.
*/
void allowNullChanged();

//! Sends the feature as soon as it is chosen
void featureChanged( const QgsFeature &feature );
/**
* Emitted when the fetching of the geometry changes
*/
void fetchGeometryChanged();

/**
* Emitted when the fetching limit for the feature request changes
*/
void fetchLimitChanged();

private slots:
void onCurrentTextChanged( const QString &text );
Expand Down

0 comments on commit 0119bb5

Please sign in to comment.