Skip to content

Commit

Permalink
use last used WMS image encoding when adding WMS layers from Browser
Browse files Browse the repository at this point in the history
dock (fix #57666)
  • Loading branch information
alexbruy committed Jan 22, 2025
1 parent ef0dd03 commit ef5ca2e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
27 changes: 20 additions & 7 deletions src/providers/wms/qgswmsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,28 @@ QString QgsWMSItemBase::createUri( bool withStyle )
}

QString format;
// get first supported by qt and server
QVector<QgsWmsSupportedFormat> formats( QgsWmsProvider::supportedFormats() );
const auto constFormats = formats;
for ( const QgsWmsSupportedFormat &f : constFormats )
bool first = true;
const QString defaultEncoding = QgsSettings().value( QStringLiteral( "qgis/lastWmsImageEncoding" ), "image/png" ).toString();
const QVector<QgsWmsSupportedFormat> formats( QgsWmsProvider::supportedFormats() );
QStringList supportedFormats;
supportedFormats.reserve( formats.size() );
for ( const QgsWmsSupportedFormat &f : formats )
{
if ( mCapabilitiesProperty.capability.request.getMap.format.indexOf( f.format ) >= 0 )
supportedFormats.append( f.format );
}

for ( const QString &f : mCapabilitiesProperty.capability.request.getMap.format )
{
if ( !supportedFormats.contains( f ) )
{
format = f.format;
break;
QgsDebugError( QStringLiteral( "encoding %1 not supported." ).arg( f ) );
continue;
}

if ( first || f == defaultEncoding )
{
format = f;
first = false;
}
}
mDataSourceUri.setParam( QStringLiteral( "format" ), format );
Expand Down
11 changes: 9 additions & 2 deletions src/providers/wms/qgswmssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,10 @@ bool QgsWMSSourceSelect::populateLayerList( const QgsWmsCapabilities &capabiliti
const QVector<QgsWmsLayerProperty> layers = capabilities.supportedLayers();
mLayerProperties = layers;

QString defaultEncoding = QgsSettings().value( "qgis/WMSDefaultFormat", "" ).toString();
QString defaultEncoding = QgsSettings().value( QStringLiteral( "qgis/lastWmsImageEncoding" ), "image/png" ).toString();

bool first = true;
bool found = false;
QSet<QString> alreadyAddedLabels;
const auto supportedImageEncodings = capabilities.supportedImageEncodings();
for ( const QString &encoding : supportedImageEncodings )
Expand All @@ -323,7 +324,11 @@ bool QgsWMSSourceSelect::populateLayerList( const QgsWmsCapabilities &capabiliti
mImageFormatGroup->button( id )->setVisible( true );
if ( first || encoding == defaultEncoding )
{
mImageFormatGroup->button( id )->setChecked( true );
if ( !found )
{
mImageFormatGroup->button( id )->setChecked( true );
found = true;
}
first = false;
}
}
Expand Down Expand Up @@ -611,6 +616,8 @@ void QgsWMSSourceSelect::addButtonClicked()
uri.setParam( QStringLiteral( "crs" ), crs );
QgsDebugMsgLevel( QStringLiteral( "crs=%2 " ).arg( crs ), 2 );

QgsSettings().setValue( QStringLiteral( "/qgis/lastWmsImageEncoding" ), format );

// Remove in case the default value from the connection settings
// is being overridden here
uri.removeParam( QStringLiteral( "featureCount" ) );
Expand Down

0 comments on commit ef5ca2e

Please sign in to comment.