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

[server] WMS GetLegendGr.. cascading size #58790

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
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,16 @@ Constructor for QgsWmsLegendNode.
virtual void invalidateMapBasedData();


QImage getLegendGraphic( bool synchronous = false ) const;
%Docstring
Lazily initializes mImage

:param synchronous: if ``True``, the image is fetched synchronously, otherwise asynchronously

.. versionadded:: 3.40
%End


SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsWmsLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,16 @@ Constructor for QgsWmsLegendNode.
virtual void invalidateMapBasedData();


QImage getLegendGraphic( bool synchronous = false ) const;
%Docstring
Lazily initializes mImage

:param synchronous: if ``True``, the image is fetched synchronously, otherwise asynchronously

.. versionadded:: 3.40
%End


SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsWmsLegendNode: \"%1\">" ).arg( sipCpp->data( Qt::DisplayRole ).toString() );
Expand Down
10 changes: 8 additions & 2 deletions src/core/layertree/qgslayertreemodellegendnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,14 @@ class CORE_EXPORT QgsWmsLegendNode : public QgsLayerTreeModelLegendNode

void invalidateMapBasedData() override;

/**
* Lazily initializes mImage
* \param synchronous if TRUE, the image is fetched synchronously, otherwise asynchronously
* \since QGIS 3.40
*/
QImage getLegendGraphic( bool synchronous = false ) const;


#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
Expand All @@ -763,8 +771,6 @@ class CORE_EXPORT QgsWmsLegendNode : public QgsLayerTreeModelLegendNode

private:

// Lazily initializes mImage
QImage getLegendGraphic( bool synchronous = false ) const;

QImage renderMessage( const QString &msg ) const;

Expand Down
31 changes: 29 additions & 2 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,36 @@ namespace QgsWms
QList<QgsMapLayer *> layers = mContext.layersToRender();
configureLayers( layers );

// init renderer
const qreal dpmm = mContext.dotsPerMm();

QgsLegendSettings settings = legendSettings();

// adjust the size settings if there any WMS cascading layers to renderer
const auto layersToRender = mContext.layersToRender();
for ( const auto &layer : std::as_const( layersToRender ) )
{
// If it is a cascading WMS layer, get legend node image size
if ( layer->dataProvider()->name() == QStringLiteral( "wms" ) )
{
if ( QgsWmsLegendNode *layerNode = qobject_cast<QgsWmsLegendNode *>( model.findLegendNode( layer->id(), QString() ) ) )
{
const auto image { layerNode->getLegendGraphic( true ) };
if ( ! image.isNull() )
{
// Check that we are not exceeding the maximum size
if ( mContext.isValidWidthHeight( image.width(), image.height() ) )
{
const double w = image.width() / dpmm;
const double h = image.height() / dpmm;
const QSizeF newWmsSize { w, h };
settings.setWmsLegendSize( newWmsSize );
}
}
}
}
}

// init renderer
QgsLegendRenderer renderer( &model, settings );

// create context
Expand All @@ -146,7 +174,6 @@ namespace QgsWms

// create image according to context
std::unique_ptr<QImage> image;
const qreal dpmm = mContext.dotsPerMm();
const QSizeF minSize = renderer.minimumSize( &context );
const QSize size( static_cast<int>( minSize.width() * dpmm ), static_cast<int>( minSize.height() * dpmm ) );
if ( !mContext.isValidWidthHeight( size.width(), size.height() ) )
Expand Down
Loading