Skip to content
Permalink
Browse files
[geonode] Fix crasher with blocking fetch layers function
  • Loading branch information
nirvn authored and nyalldawson committed Jan 12, 2022
1 parent a0c4b19 commit adc4f3547f1264f834b2ab4fa2a20b31400411fb
Showing with 15 additions and 10 deletions.
  1. +14 −10 src/core/geocms/geonode/qgsgeonoderequest.cpp
  2. +1 −0 src/core/geocms/geonode/qgsgeonoderequest.h
@@ -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( this->lastResponse() );
}
emit layersFetched( layers );
mParsingLayers = false;
obj->deleteLater();
}
emit layersFetched( layers );

obj->deleteLater();
} );
}

@@ -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 );
@@ -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();
@@ -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 );

0 comments on commit adc4f35

Please sign in to comment.