Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[wms] When a legend graphic fetch fails, don't show the error in the
layer tree, but instead just log it to the message log

This error indicates an issue on the server configuration and isn't
anything that a user can resolve. Showing it in the layer tree incorrectly
indicates that there's a problem with the layer rendering, which isn't
really true. Better to be more forgiving of misconfigured legend
services (there seems to be a lot!) and don't show this warning
right in the user's face...
  • Loading branch information
nyalldawson committed Aug 10, 2020
1 parent 30424a2 commit a6a14df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
24 changes: 7 additions & 17 deletions src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -1034,17 +1034,14 @@ QImage QgsWmsLegendNode::getLegendGraphic() const
connect( mFetcher.get(), &QgsImageFetcher::error, this, &QgsWmsLegendNode::getLegendGraphicErrored );
connect( mFetcher.get(), &QgsImageFetcher::progress, this, &QgsWmsLegendNode::getLegendGraphicProgress );
mFetcher->start();
} // else QgsDebugMsg("XXX No legend supported?");

}
}

return mImage;
}

QVariant QgsWmsLegendNode::data( int role ) const
{
//QgsDebugMsg( QStringLiteral("XXX data called with role %1 -- mImage size is %2x%3").arg(role).arg(mImage.width()).arg(mImage.height()) );

if ( role == Qt::DecorationRole )
{
return QPixmap::fromImage( getLegendGraphic() );
Expand Down Expand Up @@ -1099,7 +1096,6 @@ QJsonObject QgsWmsLegendNode::exportSymbolToJson( const QgsLegendSettings &, con
return json;
}

/* private */
QImage QgsWmsLegendNode::renderMessage( const QString &msg ) const
{
const int fontHeight = 10;
Expand All @@ -1123,38 +1119,33 @@ QImage QgsWmsLegendNode::renderMessage( const QString &msg ) const
void QgsWmsLegendNode::getLegendGraphicProgress( qint64 cur, qint64 tot )
{
QString msg = QStringLiteral( "Downloading... %1/%2" ).arg( cur ).arg( tot );
//QgsDebugMsg ( QString("XXX %1").arg(msg) );
mImage = renderMessage( msg );
emit dataChanged();
}

void QgsWmsLegendNode::getLegendGraphicErrored( const QString &msg )
void QgsWmsLegendNode::getLegendGraphicErrored( const QString & )
{
if ( ! mFetcher ) return; // must be coming after finish

mImage = renderMessage( msg );
//QgsDebugMsg( QStringLiteral("XXX emitting dataChanged after writing an image of %1x%2").arg(mImage.width()).arg(mImage.height()) );
if ( ! mFetcher )
return; // must be coming after finish

mImage = QImage();
emit dataChanged();

mFetcher.reset();

mValid = true; // we consider it valid anyway
// ... but remove validity after 5 seconds
//QTimer::singleShot(5000, this, SLOT(invalidateMapBasedData()));
}

void QgsWmsLegendNode::getLegendGraphicFinished( const QImage &image )
{
if ( ! mFetcher ) return; // must be coming after error
if ( ! mFetcher )
return; // must be coming after error

//QgsDebugMsg( QStringLiteral("XXX legend graphic finished, image is %1x%2").arg(theImage.width()).arg(theImage.height()) );
if ( ! image.isNull() )
{
if ( image != mImage )
{
mImage = image;
//QgsDebugMsg( QStringLiteral("XXX emitting dataChanged") );
emit dataChanged();
}
mValid = true; // only if not null I guess
Expand All @@ -1164,7 +1155,6 @@ void QgsWmsLegendNode::getLegendGraphicFinished( const QImage &image )

void QgsWmsLegendNode::invalidateMapBasedData()
{
//QgsDebugMsg( QStringLiteral("XXX invalidateMapBasedData called") );
// TODO: do this only if this extent != prev extent ?
mValid = false;
emit dataChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -4509,7 +4509,7 @@ void QgsWmsLegendDownloadHandler::startUrl( const QUrl &url )

void QgsWmsLegendDownloadHandler::sendError( const QString &msg )
{
QgsDebugMsgLevel( QStringLiteral( "emitting error: %1" ).arg( msg ), 2 );
QgsMessageLog::logMessage( msg, tr( "WMS" ) );
Q_ASSERT( mReply );
mReply->deleteLater();
mReply = nullptr;
Expand Down

0 comments on commit a6a14df

Please sign in to comment.