Skip to content

Commit

Permalink
Merge pull request #46786 from nirvn/geonode_fixes
Browse files Browse the repository at this point in the history
Fix a geonode provider layers fetching crasher
  • Loading branch information
elpaso committed Jan 12, 2022
2 parents 66b481a + 2c6bede commit 33f4f1c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/core/geocms/geonode/qgsgeonoderequest.cpp
Expand Up @@ -54,18 +54,22 @@ void QgsGeoNodeRequest::abort()
void QgsGeoNodeRequest::fetchLayers()
{
request( QStringLiteral( "/api/layers/" ) );
QObject *obj = new QObject( this );

QObject *obj = new QObject( this );
connect( this, &QgsGeoNodeRequest::requestFinished, obj, [obj, this ]
{
QList<QgsGeoNodeRequest::ServiceLayerDetail> layers;
if ( mError.isEmpty() )
if ( !mParsingLayers )
{
layers = parseLayers( this->lastResponse() );
mParsingLayers = true;
QList<QgsGeoNodeRequest::ServiceLayerDetail> layers;
if ( mError.isEmpty() )
{
layers = parseLayers( lastResponse() );
}
emit layersFetched( layers );
mParsingLayers = false;
obj->deleteLater();
}
emit layersFetched( layers );

obj->deleteLater();
} );
}

Expand All @@ -74,11 +78,11 @@ QList<QgsGeoNodeRequest::ServiceLayerDetail> QgsGeoNodeRequest::fetchLayersBlock
QList<QgsGeoNodeRequest::ServiceLayerDetail> layers;

QEventLoop loop;
connect( this, &QgsGeoNodeRequest::requestFinished, &loop, &QEventLoop::quit );
QObject *obj = new QObject( this );
connect( this, &QgsGeoNodeRequest::layersFetched, obj, [&]( const QList<QgsGeoNodeRequest::ServiceLayerDetail> &fetched )
{
layers = fetched;
loop.exit();
} );
fetchLayers();
loop.exec( QEventLoop::ExcludeUserInputEvents );
Expand Down Expand Up @@ -293,7 +297,7 @@ QList<QgsGeoNodeRequest::ServiceLayerDetail> QgsGeoNodeRequest::parseLayers( con
{
if ( wmsURLFormat.isEmpty() && wfsURLFormat.isEmpty() && wcsURLFormat.isEmpty() && xyzURLFormat.isEmpty() )
{
bool success = requestBlocking( QStringLiteral( "/api/layers/" ) + layerStruct.id );
bool success = requestBlocking( QStringLiteral( "/api/layers/%1/" ).arg( layerStruct.id ) );
if ( success )
{
const QJsonDocument resourceUriDocument = QJsonDocument::fromJson( this->lastResponse() );
Expand Down Expand Up @@ -546,10 +550,10 @@ void QgsGeoNodeRequest::request( const QString &endPoint )

bool QgsGeoNodeRequest::requestBlocking( const QString &endPoint )
{
request( endPoint );

QEventLoop loop;
connect( this, &QgsGeoNodeRequest::requestFinished, &loop, &QEventLoop::quit );

request( endPoint );
loop.exec( QEventLoop::ExcludeUserInputEvents );

return mError.isEmpty();
Expand Down
1 change: 1 addition & 0 deletions src/core/geocms/geonode/qgsgeonoderequest.h
Expand Up @@ -284,6 +284,7 @@ class CORE_EXPORT QgsGeoNodeRequest : public QObject

bool mIsAborted = false;
bool mForceRefresh = false;
bool mParsingLayers = false;

QList<QgsGeoNodeRequest::ServiceLayerDetail> parseLayers( const QByteArray &layerResponse );
QgsGeoNodeStyle retrieveStyle( const QString &styleUrl );
Expand Down

0 comments on commit 33f4f1c

Please sign in to comment.