Skip to content

Commit 0119bb5

Browse files
committedApr 29, 2020
add setting for fetch limit
1 parent 3090824 commit 0119bb5

10 files changed

+168
-8
lines changed
 

‎python/core/auto_generated/qgsfeaturepickermodel.sip.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ still be available in the model as NULL value(s).
3939
void setFeature( const QgsFeatureId &fid );
4040
%Docstring
4141
Set the feature to the given feature id
42+
%End
43+
44+
QgsFeature feature() const;
45+
%Docstring
46+
Returns the current feature
4247
%End
4348

4449
signals:

‎python/core/auto_generated/qgsfeaturepickermodelbase.sip.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ Returns if the geometry is fetched
138138
void setFetchGeometry( bool fetchGeometry );
139139
%Docstring
140140
Defines if the geometry will be fetched
141+
%End
142+
143+
int fetchLimit() const;
144+
%Docstring
145+
Returns the feature request fetch limit
146+
%End
147+
148+
void setFetchLimit( int fetchLimit );
149+
%Docstring
150+
Defines the feature request fetch limit
141151
%End
142152

143153
signals:
@@ -214,6 +224,11 @@ Add a NULL entry to the list.
214224
Emitted when the fetching of the geometry changes
215225
%End
216226

227+
void fetchLimitChanged();
228+
%Docstring
229+
Emitted when the fetching limit for the feature request changes
230+
%End
231+
217232

218233
protected:
219234

‎python/gui/auto_generated/qgsfeaturepickerwidget.sip.in

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ The layer from which features should be listed.
4444
void setFeature( QgsFeatureId featureId );
4545
%Docstring
4646
Sets the current index by using the given feature
47+
%End
48+
49+
QgsFeature feature() const;
50+
%Docstring
51+
Returns the current feature
4752
%End
4853

4954
QString displayExpression() const;
@@ -84,6 +89,26 @@ Determines if a NULL value should be available in the list.
8489
void setAllowNull( bool allowNull );
8590
%Docstring
8691
Determines if a NULL value should be available in the list.
92+
%End
93+
94+
bool fetchGeometry() const;
95+
%Docstring
96+
Returns if the geometry is fetched
97+
%End
98+
99+
void setFetchGeometry( bool fetchGeometry );
100+
%Docstring
101+
Defines if the geometry will be fetched
102+
%End
103+
104+
int fetchLimit() const;
105+
%Docstring
106+
Returns the feature request fetch limit
107+
%End
108+
109+
void setFetchLimit( int fetchLimit );
110+
%Docstring
111+
Defines the feature request fetch limit
87112
%End
88113

89114
QModelIndex currentModelIndex() const;
@@ -119,16 +144,26 @@ the the value to match the typed text against.
119144
%Docstring
120145
An additional expression to further restrict the available features.
121146
This can be used to integrate additional spatial or other constraints.
147+
%End
148+
149+
void featureChanged( const QgsFeature &feature );
150+
%Docstring
151+
Sends the feature as soon as it is chosen
122152
%End
123153

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

129-
void featureChanged( const QgsFeature &feature );
159+
void fetchGeometryChanged();
130160
%Docstring
131-
Sends the feature as soon as it is chosen
161+
Emitted when the fetching of the geometry changes
162+
%End
163+
164+
void fetchLimitChanged();
165+
%Docstring
166+
Emitted when the fetching limit for the feature request changes
132167
%End
133168

134169
};

‎src/core/qgsfeaturefiltermodel.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ QgsFeatureFilterModel::QgsFeatureFilterModel( QObject *parent )
3939
: QgsFeaturePickerModelBase( parent )
4040
{
4141
setFetchGeometry( false );
42+
setFetchLimit( QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ).toInt() );
4243
setExtraIdentifierValueUnguarded( QVariantList() );
4344
}
4445

‎src/core/qgsfeaturepickermodel.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ QgsFeaturePickerModel::QgsFeaturePickerModel( QObject *parent )
2727
setFetchGeometry( true );
2828
setExtraIdentifierValueUnguarded( FID_NULL );
2929

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

3333
void QgsFeaturePickerModel::requestToReloadCurrentFeature( QgsFeatureRequest &request )
@@ -71,6 +71,11 @@ void QgsFeaturePickerModel::setFeature( const QgsFeatureId &fid )
7171
setExtraIdentifierValue( fid );
7272
}
7373

74+
QgsFeature QgsFeaturePickerModel::feature() const
75+
{
76+
return mEntries.value( mExtraValueIndex ).feature;
77+
}
78+
7479
QgsFeatureExpressionValuesGatherer *QgsFeaturePickerModel::createValuesGatherer( const QgsFeatureRequest &request ) const
7580
{
7681
return new QgsFeatureExpressionValuesGatherer( sourceLayer(), displayExpression(), request );

‎src/core/qgsfeaturepickermodel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class CORE_EXPORT QgsFeaturePickerModel : public QgsFeaturePickerModelBase
4949
//! Set the feature to the given feature id
5050
void setFeature( const QgsFeatureId &fid );
5151

52+
/**
53+
* Returns the current feature
54+
*/
55+
QgsFeature feature() const;
56+
5257
signals:
5358
void featureChanged( const QgsFeature &feature );
5459

‎src/core/qgsfeaturepickermodelbase.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void QgsFeaturePickerModelBase::scheduledReload()
409409

410410
if ( !mFetchGeometry )
411411
request.setFlags( QgsFeatureRequest::NoGeometry );
412-
request.setLimit( QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ).toInt() );
412+
request.setLimit( mFetchLimit );
413413

414414
mGatherer = createValuesGatherer( request );
415415
mGatherer->setData( mShouldReloadCurrentFeature );
@@ -566,6 +566,20 @@ void QgsFeaturePickerModelBase::setFetchGeometry( bool fetchGeometry )
566566
reload();
567567
}
568568

569+
int QgsFeaturePickerModelBase::fetchLimit() const
570+
{
571+
return mFetchLimit;
572+
}
573+
574+
void QgsFeaturePickerModelBase::setFetchLimit( int fetchLimit )
575+
{
576+
if ( fetchLimit == mFetchLimit )
577+
return;
578+
579+
mFetchLimit = fetchLimit;
580+
emit fetchLimitChanged();
581+
}
582+
569583

570584
bool QgsFeaturePickerModelBase::extraValueDoesNotExist() const
571585
{

‎src/core/qgsfeaturepickermodelbase.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
3636
Q_PROPERTY( QString filterValue READ filterValue WRITE setFilterValue NOTIFY filterValueChanged )
3737
Q_PROPERTY( QString filterExpression READ filterExpression WRITE setFilterExpression NOTIFY filterExpressionChanged )
3838
Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull NOTIFY allowNullChanged )
39-
Q_PROPERTY( bool fetchGeometry READ fetchGeometry WRITE setFetchGeometry NOTIFY fetchGeometryGeometry )
39+
Q_PROPERTY( bool fetchGeometry READ fetchGeometry WRITE setFetchGeometry NOTIFY fetchGeometryChanged )
40+
Q_PROPERTY( int fetchLimit READ fetchLimit WRITE setFetchLimit NOTIFY fetchLimitChanged )
4041
Q_PROPERTY( int extraIdentifierValueIndex READ extraIdentifierValueIndex NOTIFY extraIdentifierValueIndexChanged )
4142

4243
public:
@@ -162,6 +163,16 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
162163
*/
163164
void setFetchGeometry( bool fetchGeometry );
164165

166+
/**
167+
* Returns the feature request fetch limit
168+
*/
169+
int fetchLimit() const;
170+
171+
/**
172+
* Defines the feature request fetch limit
173+
*/
174+
void setFetchLimit( int fetchLimit );
175+
165176
signals:
166177

167178
/**
@@ -236,6 +247,11 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
236247
*/
237248
void fetchGeometryChanged();
238249

250+
/**
251+
* Emitted when the fetching limit for the feature request changes
252+
*/
253+
void fetchLimitChanged();
254+
239255

240256
private slots:
241257
void updateCompleter();
@@ -316,6 +332,7 @@ class CORE_EXPORT QgsFeaturePickerModelBase : public QAbstractItemModel SIP_ABST
316332

317333
QgsFeatureExpressionValuesGatherer *mGatherer = nullptr;
318334
bool mFetchGeometry = true;
335+
int mFetchLimit = 100;
319336

320337
QTimer mReloadTimer;
321338
bool mShouldReloadCurrentFeature = false;

‎src/gui/qgsfeaturepickerwidget.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ QgsFeaturePickerWidget::QgsFeaturePickerWidget( QWidget *parent )
4141
connect( mModel, &QgsFeaturePickerModel::isLoadingChanged, this, &QgsFeaturePickerWidget::onLoadingChanged );
4242
connect( mModel, &QgsFeaturePickerModel::filterJobCompleted, this, &QgsFeaturePickerWidget::onFilterUpdateCompleted );
4343
connect( mModel, &QgsFeaturePickerModel::allowNullChanged, this, &QgsFeaturePickerWidget::allowNullChanged );
44+
connect( mModel, &QgsFeaturePickerModel::fetchGeometryChanged, this, &QgsFeaturePickerWidget::fetchGeometryChanged );
45+
connect( mModel, &QgsFeaturePickerModel::fetchLimitChanged, this, &QgsFeaturePickerWidget::fetchLimitChanged );
4446
connect( mModel, &QgsFeaturePickerModel::extraIdentifierValueIndexChanged, mComboBox, &QComboBox::setCurrentIndex );
4547
connect( mModel, &QgsFeaturePickerModel::featureChanged, this, &QgsFeaturePickerWidget::featureChanged );
4648
connect( mCompleter, static_cast<void( QCompleter::* )( const QModelIndex & )>( &QCompleter::highlighted ), this, &QgsFeaturePickerWidget::onItemSelected );
@@ -80,6 +82,11 @@ void QgsFeaturePickerWidget::setFeature( QgsFeatureId featureId )
8082
mModel->setFeature( featureId );
8183
}
8284

85+
QgsFeature QgsFeaturePickerWidget::feature() const
86+
{
87+
return mModel->feature();
88+
}
89+
8390
QString QgsFeaturePickerWidget::displayExpression() const
8491
{
8592
return mModel->displayExpression();
@@ -228,7 +235,6 @@ void QgsFeaturePickerWidget::LineEditState::store( QLineEdit *lineEdit )
228235
selectionStart = lineEdit->selectionStart();
229236
selectionLength = lineEdit->selectedText().length();
230237
cursorPosition = lineEdit->cursorPosition();
231-
232238
}
233239

234240
void QgsFeaturePickerWidget::LineEditState::restore( QLineEdit *lineEdit ) const
@@ -238,3 +244,23 @@ void QgsFeaturePickerWidget::LineEditState::restore( QLineEdit *lineEdit ) const
238244
if ( selectionStart > -1 )
239245
lineEdit->setSelection( selectionStart, selectionLength );
240246
}
247+
248+
bool QgsFeaturePickerWidget::fetchGeometry() const
249+
{
250+
return mModel->fetchGeometry();
251+
}
252+
253+
void QgsFeaturePickerWidget::setFetchGeometry( bool fetchGeometry )
254+
{
255+
mModel->setFetchGeometry( fetchGeometry );
256+
}
257+
258+
int QgsFeaturePickerWidget::fetchLimit() const
259+
{
260+
return mModel->fetchLimit();
261+
}
262+
263+
void QgsFeaturePickerWidget::setFetchLimit( int fetchLimit )
264+
{
265+
mModel->setFetchLimit( fetchLimit );
266+
}

‎src/gui/qgsfeaturepickerwidget.h

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
4747
Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
4848
Q_PROPERTY( QString filterExpression READ filterExpression WRITE setFilterExpression NOTIFY filterExpressionChanged )
4949
Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull NOTIFY allowNullChanged )
50+
Q_PROPERTY( bool fetchGeometry READ fetchGeometry WRITE setFetchGeometry NOTIFY fetchGeometryChanged )
51+
Q_PROPERTY( int fetchLimit READ fetchLimit WRITE setFetchLimit NOTIFY fetchLimitChanged )
5052

5153
public:
5254

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

75+
/**
76+
* Returns the current feature
77+
*/
78+
QgsFeature feature() const;
79+
7380
/**
7481
* The display expression will be used to display features as well as
7582
* the value to match the typed text against.
@@ -110,6 +117,26 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
110117
*/
111118
void setAllowNull( bool allowNull );
112119

120+
/**
121+
* Returns if the geometry is fetched
122+
*/
123+
bool fetchGeometry() const;
124+
125+
/**
126+
* Defines if the geometry will be fetched
127+
*/
128+
void setFetchGeometry( bool fetchGeometry );
129+
130+
/**
131+
* Returns the feature request fetch limit
132+
*/
133+
int fetchLimit() const;
134+
135+
/**
136+
* Defines the feature request fetch limit
137+
*/
138+
void setFetchLimit( int fetchLimit );
139+
113140
/**
114141
* The index of the currently selected item.
115142
*/
@@ -143,13 +170,23 @@ class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
143170
*/
144171
void filterExpressionChanged();
145172

173+
//! Sends the feature as soon as it is chosen
174+
void featureChanged( const QgsFeature &feature );
175+
146176
/**
147177
* Determines if a NULL value should be available in the list.
148178
*/
149179
void allowNullChanged();
150180

151-
//! Sends the feature as soon as it is chosen
152-
void featureChanged( const QgsFeature &feature );
181+
/**
182+
* Emitted when the fetching of the geometry changes
183+
*/
184+
void fetchGeometryChanged();
185+
186+
/**
187+
* Emitted when the fetching limit for the feature request changes
188+
*/
189+
void fetchLimitChanged();
153190

154191
private slots:
155192
void onCurrentTextChanged( const QString &text );

0 commit comments

Comments
 (0)
Please sign in to comment.