Skip to content

Commit

Permalink
Merge pull request #52246 from signedav/fetchlimit_relationreference
Browse files Browse the repository at this point in the history
Relation Reference: Limit number of entries (resp. unlimit it) per widget
  • Loading branch information
signedav committed Mar 21, 2023
2 parents 3556ece + 4eaeb3e commit 74baacc
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 50 deletions.
Expand Up @@ -237,6 +237,21 @@ Set the name of the referenced layer to ``referencedLayerName``
.. versionadded:: 3.12
%End

int fetchLimit() const;
%Docstring
Returns the limit of fetched features (0 means all features)

.. versionadded:: 3.32
%End

void setFetchLimit( int fetchLimit );
%Docstring
Set the limit of fetched features (0 means all features)

.. versionadded:: 3.32
%End


public slots:
void openForm();
%Docstring
Expand Down
15 changes: 15 additions & 0 deletions python/gui/auto_generated/qgsfeaturelistcombobox.sip.in
Expand Up @@ -135,6 +135,21 @@ 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

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

.. versionadded:: 3.32
%End

void setFetchLimit( int fetchLimit );
%Docstring
Defines the feature request fetch limit
If set to 0, no limit is applied when fetching

.. versionadded:: 3.32
%End

QString identifierField() const /Deprecated/;
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsfeaturepickermodelbase.cpp
Expand Up @@ -592,6 +592,8 @@ void QgsFeaturePickerModelBase::setFetchLimit( int fetchLimit )

mFetchLimit = fetchLimit;
emit fetchLimitChanged();

reload();
}


Expand Down
7 changes: 7 additions & 0 deletions src/gui/editorwidgets/qgsrelationreferenceconfigdlg.cpp
Expand Up @@ -27,6 +27,9 @@ QgsRelationReferenceConfigDlg::QgsRelationReferenceConfigDlg( QgsVectorLayer *vl

{
setupUi( this );

mFetchLimit->setMaximum( std::numeric_limits<int>::max() );

connect( mAddFilterButton, &QToolButton::clicked, this, &QgsRelationReferenceConfigDlg::mAddFilterButton_clicked );
connect( mRemoveFilterButton, &QToolButton::clicked, this, &QgsRelationReferenceConfigDlg::mRemoveFilterButton_clicked );

Expand Down Expand Up @@ -110,6 +113,8 @@ void QgsRelationReferenceConfigDlg::setConfig( const QVariantMap &config )
mCbxMapIdentification->setChecked( config.value( QStringLiteral( "MapIdentification" ), false ).toBool() );
mCbxAllowAddFeatures->setChecked( config.value( QStringLiteral( "AllowAddFeatures" ), false ).toBool() );
mCbxReadOnly->setChecked( config.value( QStringLiteral( "ReadOnly" ), false ).toBool() );
mFetchLimitGroupBox->setChecked( config.value( QStringLiteral( "FetchLimitActive" ), QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ).toInt() > 0 ).toBool() );
mFetchLimit->setValue( config.value( QStringLiteral( "FetchLimitNumber" ), QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ) ).toInt() );
mFilterExpression->setPlainText( config.value( QStringLiteral( "FilterExpression" ) ).toString() );

if ( config.contains( QStringLiteral( "FilterFields" ) ) )
Expand Down Expand Up @@ -170,6 +175,8 @@ QVariantMap QgsRelationReferenceConfigDlg::config()
myConfig.insert( QStringLiteral( "ReadOnly" ), mCbxReadOnly->isChecked() );
myConfig.insert( QStringLiteral( "Relation" ), mComboRelation->currentData() );
myConfig.insert( QStringLiteral( "AllowAddFeatures" ), mCbxAllowAddFeatures->isChecked() );
myConfig.insert( QStringLiteral( "FetchLimitActive" ), mFetchLimitGroupBox->isChecked() );
myConfig.insert( QStringLiteral( "FetchLimitNumber" ), mFetchLimit->value() );

if ( mFilterGroupBox->isChecked() )
{
Expand Down
Expand Up @@ -212,6 +212,12 @@ void QgsRelationReferenceSearchWidgetWrapper::initWidget( QWidget *editor )
mWidget->setAllowAddFeatures( false );
mWidget->setOpenFormButtonVisible( false );

const bool fetchLimitActive = config( QStringLiteral( "FetchLimitActive" ), QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ).toInt() > 0 ).toBool();
if ( fetchLimitActive )
{
mWidget->setFetchLimit( config( QStringLiteral( "FetchLimitNumber" ), QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ) ).toInt() );
}

if ( config( QStringLiteral( "FilterFields" ), QVariant() ).isValid() )
{
mWidget->setFilterFields( config( QStringLiteral( "FilterFields" ) ).toStringList() );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -187,6 +187,7 @@ void QgsRelationReferenceWidget::setRelation( const QgsRelation &relation, bool
mComboBox->setSourceLayer( mReferencedLayer );
mComboBox->setIdentifierFields( mReferencedFields );
mComboBox->setFilterExpression( mFilterExpression );
mComboBox->setFetchLimit( mFetchLimit );
}
mAttributeEditorFrame->setObjectName( QStringLiteral( "referencing/" ) + relation.name() );

Expand Down Expand Up @@ -474,6 +475,7 @@ void QgsRelationReferenceWidget::init()
mComboBox->setDisplayExpression( mReferencedLayer->displayExpression() );
mComboBox->setAllowNull( mAllowNull );
mComboBox->setIdentifierFields( mReferencedFields );
mComboBox->setFetchLimit( mFetchLimit );

if ( ! mFilterExpression.isEmpty() )
mComboBox->setFilterExpression( mFilterExpression );
Expand Down
14 changes: 14 additions & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidget.h
Expand Up @@ -251,6 +251,19 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
*/
void setReferencedLayerName( const QString &referencedLayerName );

/**
* Returns the limit of fetched features (0 means all features)
* \since QGIS 3.32
*/
int fetchLimit() const {return mFetchLimit; }

/**
* Set the limit of fetched features (0 means all features)
* \since QGIS 3.32
*/
void setFetchLimit( int fetchLimit ) {mFetchLimit = fetchLimit; }


public slots:
//! open the form of the related feature in a new dialog
void openForm();
Expand Down Expand Up @@ -328,6 +341,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
QStringList mFilterFields;
QMap<QString, QMap<QString, QSet<QString> > > mFilterCache;
bool mInitialized = false;
int mFetchLimit = 0;

// Q_PROPERTY
bool mEmbedForm = false;
Expand Down
7 changes: 7 additions & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidgetwrapper.cpp
Expand Up @@ -57,6 +57,13 @@ void QgsRelationReferenceWidgetWrapper::initWidget( QWidget *editor )
mWidget->setReadOnlySelector( readOnlyWidget );
mWidget->setAllowMapIdentification( mapIdent );
mWidget->setOpenFormButtonVisible( showOpenFormButton );

const bool fetchLimitActive = config( QStringLiteral( "FetchLimitActive" ), QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ).toInt() > 0 ).toBool();
if ( fetchLimitActive )
{
mWidget->setFetchLimit( config( QStringLiteral( "FetchLimitNumber" ), QgsSettings().value( QStringLiteral( "maxEntriesRelationWidget" ), 100, QgsSettings::Gui ) ).toInt() );
}

if ( config( QStringLiteral( "FilterFields" ), QVariant() ).isValid() )
{
mWidget->setFilterFields( config( QStringLiteral( "FilterFields" ) ).toStringList() );
Expand Down
10 changes: 10 additions & 0 deletions src/gui/qgsfeaturelistcombobox.cpp
Expand Up @@ -241,6 +241,16 @@ void QgsFeatureListComboBox::setAllowNull( bool allowNull )
mLineEdit->setClearMode( allowNull ? QgsFilterLineEdit::ClearToNull : QgsFilterLineEdit::ClearToDefault );
}

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

void QgsFeatureListComboBox::setFetchLimit( int fetchLimit )
{
mModel->setFetchLimit( fetchLimit );
}

QVariant QgsFeatureListComboBox::identifierValue() const
{
Q_NOWARN_DEPRECATED_PUSH
Expand Down
13 changes: 13 additions & 0 deletions src/gui/qgsfeaturelistcombobox.h
Expand Up @@ -154,6 +154,19 @@ class GUI_EXPORT QgsFeatureListComboBox : public QComboBox
*/
void setAllowNull( bool allowNull );

/**
* Returns the feature request fetch limit
* \since QGIS 3.32
*/
int fetchLimit() const;

/**
* Defines the feature request fetch limit
* If set to 0, no limit is applied when fetching
* \since QGIS 3.32
*/
void setFetchLimit( int fetchLimit );

/**
* Field name that will be used to uniquely identify the current feature.
* Normally the primary key of the layer.
Expand Down
130 changes: 80 additions & 50 deletions src/ui/editorwidgets/qgsrelationreferenceconfigdlgbase.ui
Expand Up @@ -7,17 +7,31 @@
<x>0</x>
<y>0</y>
<width>470</width>
<height>553</height>
<height>601</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxReadOnly">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Use a read-only line edit instead of a combobox</string>
<string>Relation</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxAllowAddFeatures">
<property name="text">
<string>Allow adding new features</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxAllowNull">
<property name="text">
<string>Allow NULL value</string>
</property>
</widget>
</item>
Expand All @@ -31,7 +45,38 @@
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxReadOnly">
<property name="text">
<string>Use a read-only line edit instead of a combobox</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxMapIdentification">
<property name="text">
<string>On map identification (for geometric layers only)</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsFieldExpressionWidget" name="mExpressionWidget">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mComboRelation">
<property name="toolTip">
<string>The generated relations for a polymorphic relation cannot be used.</string>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBox" name="mFilterGroupBox">
<property name="title">
<string>Filters</string>
Expand Down Expand Up @@ -148,62 +193,42 @@
</layout>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxShowOpenFormButton">
<property name="text">
<string>Show open form button</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Relation</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxAllowNull">
<property name="text">
<string>Allow NULL value</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxMapIdentification">
<property name="text">
<string>On map identification (for geometric layers only)</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mComboRelation">
<item row="8" column="0" colspan="2">
<widget class="QGroupBox" name="mFetchLimitGroupBox">
<property name="toolTip">
<string>The generated relations for a polymorphic relation cannot be used.</string>
<string>If no limit is set, all entries are loaded.</string>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
<property name="title">
<string>Limit number of entries</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsFieldExpressionWidget" name="mExpressionWidget">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_fetchLimit">
<property name="text">
<string>Maximum number of entries</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsSpinBox" name="mFetchLimit"/>
</item>
</layout>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxAllowAddFeatures">
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxShowForm">
<property name="text">
<string>Allow adding new features</string>
<string>Show embedded form</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxShowForm">
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxShowOpenFormButton">
<property name="text">
<string>Show embedded form</string>
<string>Show open form button</string>
</property>
</widget>
</item>
Expand All @@ -222,6 +247,11 @@
<header>qgsfieldexpressionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsSpinBox</class>
<extends>QSpinBox</extends>
<header>qgsspinbox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mExpressionWidget</tabstop>
Expand Down

0 comments on commit 74baacc

Please sign in to comment.