Skip to content

Commit

Permalink
[geonode] Fix crasher with blocking fetch layers function
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn authored and github-actions[bot] committed Jan 12, 2022
1 parent a708701 commit bf0baed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
24 changes: 14 additions & 10 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( this->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 @@ -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 bf0baed

Please sign in to comment.