Merge pull request #57180 from elpaso/bugfix-gh45206-wms-feature-count

WMS: GetFeatureInfo FEATURE_COUNT set connection default
This commit is contained in:
Alessandro Pasotti 2024-04-29 13:17:32 +02:00 committed by GitHub
commit fcec63d10c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 106 additions and 34 deletions

View File

@ -74,6 +74,7 @@ const QgsSettingsEntryBool *QgsOwsConnection::settingsInvertAxisOrientation = ne
const QgsSettingsEntryString *QgsOwsConnection::settingsUsername = new QgsSettingsEntryString( QStringLiteral( "username" ), sTreeOwsConnections ) ;
const QgsSettingsEntryString *QgsOwsConnection::settingsPassword = new QgsSettingsEntryString( QStringLiteral( "password" ), sTreeOwsConnections ) ;
const QgsSettingsEntryString *QgsOwsConnection::settingsAuthCfg = new QgsSettingsEntryString( QStringLiteral( "authcfg" ), sTreeOwsConnections ) ;
const QgsSettingsEntryInteger *QgsOwsConnection::settingsFeatureCount = new QgsSettingsEntryInteger( QStringLiteral( "feature-count" ), sTreeOwsConnections, 10 );
QgsOwsConnection::QgsOwsConnection( const QString &service, const QString &connName )
: mConnName( connName )
@ -212,6 +213,10 @@ QgsDataSourceUri &QgsOwsConnection::addWmsWcsConnectionSettings( QgsDataSourceUr
{
uri.setParam( QStringLiteral( "tilePixelRatio" ), QString::number( static_cast<int>( settingsTilePixelRatio->value( {service.toLower(), connName} ) ) ) );
}
if ( settingsFeatureCount->exists( {service.toLower(), connName} ) )
{
uri.setParam( QStringLiteral( "featureCount" ), QString::number( settingsFeatureCount->value( {service.toLower(), connName} ) ) );
}
return uri;
}

View File

@ -115,6 +115,7 @@ class CORE_EXPORT QgsOwsConnection : public QObject
static const QgsSettingsEntryString *settingsUsername;
static const QgsSettingsEntryString *settingsPassword;
static const QgsSettingsEntryString *settingsAuthCfg;
static const QgsSettingsEntryInteger *settingsFeatureCount;
#endif

View File

@ -141,6 +141,11 @@ QgsNewHttpConnection::QgsNewHttpConnection( QWidget *parent, ConnectionTypes typ
cbxIgnoreGetFeatureInfoURI->setVisible( false );
mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );
sbFeatureCount->setVisible( false );
mGroupBox->layout()->removeWidget( sbFeatureCount );
lblFeatureCount->setVisible( false );
mGroupBox->layout()->removeWidget( lblFeatureCount );
cmbDpiMode->setVisible( false );
mGroupBox->layout()->removeWidget( cmbDpiMode );
lblDpiMode->setVisible( false );
@ -320,6 +325,8 @@ void QgsNewHttpConnection::updateServiceSpecificSettings()
Qgis::TilePixelRatio tilePixelRatio = QgsOwsConnection::settingsTilePixelRatio->value( detailsParameters );
cmbTilePixelRatio->setCurrentIndex( cmbTilePixelRatio->findData( static_cast<int>( tilePixelRatio ) ) );
sbFeatureCount->setValue( QgsOwsConnection::settingsFeatureCount->value( detailsParameters ) );
const QString version = QgsOwsConnection::settingsVersion->value( detailsParameters );
int versionIdx = WFS_VERSION_MAX; // AUTO
if ( version == QLatin1String( "1.0.0" ) )
@ -426,6 +433,7 @@ void QgsNewHttpConnection::accept()
if ( mTypes & ConnectionWms )
{
QgsOwsConnection::settingsIgnoreGetFeatureInfoURI->setValue( cbxIgnoreGetFeatureInfoURI->isChecked(), detailsParameters );
QgsOwsConnection::settingsFeatureCount->setValue( sbFeatureCount->value(), detailsParameters );
}
if ( mTypes & ConnectionWfs )
{

View File

@ -462,6 +462,14 @@ QString QgsWMSItemBase::createUri( bool withStyle )
crs = mLayerProperty.crs[0];
}
mDataSourceUri.setParam( QStringLiteral( "crs" ), crs );
// Set default featureCount to 10, old connections might miss this
// setting.
if ( ! mDataSourceUri.hasParam( QStringLiteral( "featureCount" ) ) )
{
mDataSourceUri.setParam( QStringLiteral( "featureCount" ), QStringLiteral( "10" ) );
}
//uri = rasterLayerPath + "|layers=" + layers.join( "," ) + "|styles=" + styles.join( "," ) + "|format=" + format + "|crs=" + crs;
return mDataSourceUri.encodedUri();

View File

@ -469,6 +469,20 @@ void QgsWMSSourceSelect::btnConnect_clicked()
QgsWMSConnection connection( cmbConnections->currentText() );
mUri = connection.uri();
bool featureCountSet { };
if ( connection.uri().hasParam( QStringLiteral( "featureCount" ) ) )
{
connection.uri().param( QStringLiteral( "featureCount" ) ).toInt( &featureCountSet );
if ( featureCountSet )
mFeatureCount->setText( connection.uri().param( QStringLiteral( "featureCount" ) ) );
}
// Original default for old connections with no default feature count set
if ( ! featureCountSet )
{
mFeatureCount->setText( QStringLiteral( "10" ) );
}
QgsWmsSettings wmsSettings;
if ( !wmsSettings.parseUri( mUri.encodedUri() ) )
{
@ -600,6 +614,9 @@ void QgsWMSSourceSelect::addButtonClicked()
uri.setParam( QStringLiteral( "crs" ), crs );
QgsDebugMsgLevel( QStringLiteral( "crs=%2 " ).arg( crs ), 2 );
// Remove in case the default value from the connection settings
// is being overridden here
uri.removeParam( QStringLiteral( "featureCount" ) );
if ( mFeatureCount->text().toInt() > 0 )
{
uri.setParam( QStringLiteral( "featureCount" ), mFeatureCount->text() );

View File

@ -140,43 +140,43 @@
<string>WMS/WMTS Options</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="cbxWmsIgnoreAxisOrientation">
<property name="text">
<string>Ignore axis orientation (WMS 1.3/WMTS)</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="cbxIgnoreGetFeatureInfoURI">
<property name="text">
<string>Ignore GetFeatureInfo URI reported in capabilities</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="cbxIgnoreGetMapURI">
<property name="text">
<string>Ignore GetMap/GetTile/GetLegendGraphic URI reported in capabilities</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<item row="13" column="0" colspan="2">
<widget class="QCheckBox" name="cbxSmoothPixmapTransform">
<property name="text">
<string>Smooth pixmap transform</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="cbxWmsIgnoreAxisOrientation">
<property name="text">
<string>Ignore axis orientation (WMS 1.3/WMTS)</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cmbTilePixelRatio"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lblFeatureCount">
<property name="text">
<string>Maximum number of GetFeatureInfo results</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="QCheckBox" name="cbxWmsInvertAxisOrientation">
<property name="text">
<string>Invert axis orientation</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cmbDpiMode"/>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="cbxIgnoreGetFeatureInfoURI">
<property name="text">
<string>Ignore GetFeatureInfo URI reported in capabilities</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblDpiMode">
@ -188,8 +188,15 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cmbTilePixelRatio"/>
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="cbxWmsIgnoreReportedLayerExtents">
<property name="text">
<string>Ignore reported layer extents</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cmbDpiMode"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblTilePixelRatio">
@ -201,10 +208,29 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="cbxWmsIgnoreReportedLayerExtents">
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="cbxIgnoreGetMapURI">
<property name="text">
<string>Ignore reported layer extents</string>
<string>Ignore GetMap/GetTile/GetLegendGraphic URI reported in capabilities</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="sbFeatureCount">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Specify a default value for FEATURE_COUNT when a new layer is created from this connection. &lt;/p&gt;&lt;p&gt;FEATURE_COUNT defines the maximum number of results returned by a GetFeatureInfo request, if not specified the server default value (usually 1) will be used.&lt;/p&gt;&lt;p&gt;Set to 0 to use server default: no FEATURE_COUNT parameter will be added to the request.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="specialValueText">
<string>server default</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
@ -362,6 +388,7 @@
<tabstop>cbxWfsUseGml2EncodingForTransactions</tabstop>
<tabstop>cmbDpiMode</tabstop>
<tabstop>cmbTilePixelRatio</tabstop>
<tabstop>sbFeatureCount</tabstop>
<tabstop>cbxIgnoreGetMapURI</tabstop>
<tabstop>cbxIgnoreGetFeatureInfoURI</tabstop>
<tabstop>cbxWmsIgnoreReportedLayerExtents</tabstop>
@ -379,8 +406,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>421</x>
<y>453</y>
<x>428</x>
<y>813</y>
</hint>
<hint type="destinationlabel">
<x>430</x>
@ -395,8 +422,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>330</x>
<y>453</y>
<x>337</x>
<y>813</y>
</hint>
<hint type="destinationlabel">
<x>426</x>

View File

@ -211,6 +211,9 @@
</item>
<item row="3" column="2">
<widget class="QLineEdit" name="mFeatureCount">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>10</string>
</property>

View File

@ -38,6 +38,7 @@ class TestQgsOwsConnection(QgisTestCase):
settings.setValue(key + 'dpi-mode', 4)
settings.setValue(key + 'ignore-axis-orientation', True)
settings.setValue(key + 'invert-axis-orientation', True)
settings.setValue(key + 'feature-count', 9)
key = '/connections/ows/items/wfs/connections/items/test/'
settings.setValue(key + 'url', 'ccc.ddd.com')
@ -58,6 +59,7 @@ class TestQgsOwsConnection(QgisTestCase):
self.assertEqual(uri.param('dpiMode'), '4')
self.assertEqual(uri.param('IgnoreAxisOrientation'), '1')
self.assertEqual(uri.param('InvertAxisOrientation'), '1')
self.assertEqual(uri.param('featureCount'), '9')
def testWmsSettings(self):
uri = QgsDataSourceUri()
@ -70,6 +72,7 @@ class TestQgsOwsConnection(QgisTestCase):
self.assertEqual(uri.param('dpiMode'), '4')
self.assertEqual(uri.param('IgnoreAxisOrientation'), '1')
self.assertEqual(uri.param('InvertAxisOrientation'), '1')
self.assertEqual(uri.param('featureCount'), '9')
def testWfsConnection(self):
c = QgsOwsConnection('WFS', 'test')