Skip to content
Permalink
Browse files

add setting for fetch limit

  • Loading branch information
3nids committed Apr 29, 2020
1 parent 3090824 commit 0119bb52e16e080dd92ca0db962ee668d491703f
@@ -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:
@@ -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:
@@ -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:

@@ -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;
@@ -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;
@@ -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

};
@@ -39,6 +39,7 @@ QgsFeatureFilterModel::QgsFeatureFilterModel( QObject *parent )
: QgsFeaturePickerModelBase( parent )
{
setFetchGeometry( false );
setFetchLimit( QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ).toInt() );
setExtraIdentifierValueUnguarded( QVariantList() );
}

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

@@ -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 );
@@ -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
{
@@ -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:
@@ -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:

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

@@ -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.
@@ -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.
*/
@@ -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 );

0 comments on commit 0119bb5

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