Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use last used WMS image encoding when adding WMS layers from Browser dock (fix #57666) #60221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/providers/wms/qgswmsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgslogger.h"

#include "qgsdatasourceuri.h"
#include "qgssettings.h"
#include "qgswmscapabilities.h"
#include "qgswmsconnection.h"
#include "qgsxyzconnection.h"
Expand Down Expand Up @@ -428,15 +429,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
Loading