Skip to content

Commit

Permalink
[wms] When a legend graphic fetch fails, don't show the error in the …
Browse files Browse the repository at this point in the history
…layer tree, but instead just log it to the message log
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Aug 11, 2020
1 parent de80cff commit 00b4296
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 222 deletions.
24 changes: 7 additions & 17 deletions src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -1024,17 +1024,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 @@ -1089,7 +1086,6 @@ QJsonObject QgsWmsLegendNode::exportSymbolToJson( const QgsLegendSettings &, con
return json;
}

/* private */
QImage QgsWmsLegendNode::renderMessage( const QString &msg ) const
{
const int fontHeight = 10;
Expand All @@ -1113,38 +1109,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 @@ -1154,7 +1145,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

0 comments on commit 00b4296

Please sign in to comment.