Skip to content

Commit

Permalink
[geonode] Don't block data source manager while connecting to a server
Browse files Browse the repository at this point in the history
Also add missing docstrings
  • Loading branch information
nyalldawson committed Sep 12, 2017
1 parent 1a19283 commit e1562df
Show file tree
Hide file tree
Showing 10 changed files with 510 additions and 220 deletions.
178 changes: 144 additions & 34 deletions python/core/geocms/geonode/qgsgeonoderequest.sip
Expand Up @@ -12,15 +12,43 @@ struct QgsGeoNodeStyle
%TypeHeaderCode
#include <qgsgeonoderequest.h>
%End

QString id;
%Docstring
Unique style ID
%End

QString name;
%Docstring
Style name
%End

QString title;
%Docstring
Style title
%End

QDomDocument body;
%Docstring
DOM documenting containing style
%End

QString styleUrl;
%Docstring
Associated URL
%End
};

class QgsGeoNodeRequest : QObject
{
%Docstring
Request handler for GeoNode servers.

QgsGeoNodeRequest handles requesting and parsing service details from a GeoNode
server instance, for instance requesting all available layers or layer styles.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsgeonoderequest.h"
Expand All @@ -30,110 +58,192 @@ class QgsGeoNodeRequest : QObject
struct ServiceLayerDetail
{
QUuid uuid;
%Docstring
Unique identifier (generate on the client side, not at the GeoNode server)
%End
QString name;
%Docstring
Layer name
%End
QString typeName;
%Docstring
Layer type name
%End
QString title;
%Docstring
Layer title
%End
QString wmsURL;
%Docstring
WMS URL for layer
%End
QString wfsURL;
%Docstring
WFS URL for layer
%End
QString xyzURL;
%Docstring
XYZ tileserver URL for layer
%End
};

explicit QgsGeoNodeRequest( bool forceRefresh, QObject *parent = 0 );
QgsGeoNodeRequest( const QString &baseUrl, bool forceRefresh, QObject *parent = 0 );
%Docstring
Constructor for QgsGeoNodeRequest.

If ``forceRefresh`` is false, then cached copies of the request may be reused.
%End
QgsGeoNodeRequest( const QString &baseUrl, bool forceRefresh, QObject *parent = 0 );

virtual ~QgsGeoNodeRequest();

bool request( const QString &endPoint );
void request( const QString &endPoint );
%Docstring
Triggers a new request to the GeoNode server, with the requested ``endPoint``.
Any existing request will be aborted.

Calling this method does not block while waiting for a result.

\warning When using the non-blocking methods in this class, sending
overlapping requests results in undefined behavior. Use separate instances
of QgsGeoNodeRequest instead to avoid this.

.. seealso:: requestBlocking()
%End

bool requestBlocking( const QString &endPoint );
%Docstring
Triggers a new request to the GeoNode server, with the requested ``endPoint``.
Any existing request will be aborted.

Calling this method will block while waiting for a result. It should not be
used from any code which potentially blocks operation in the main GUI thread.

.. seealso:: request()
:rtype: bool
%End

QList<QgsGeoNodeRequest::ServiceLayerDetail> getLayers();
void fetchLayers();
%Docstring
Triggers a new request to fetch the list of available layers from the
server. When complete, the layersFetched() signal will be emitted
with the result.

This method is non-blocking and returns immediately.

\warning When using the non-blocking methods in this class, sending
overlapping requests results in undefined behavior. Use separate instances
of QgsGeoNodeRequest instead to avoid this.

.. seealso:: layersFetched()
.. seealso:: fetchLayersBlocking()
%End

QList<QgsGeoNodeRequest::ServiceLayerDetail> fetchLayersBlocking();
%Docstring
Requests the list of available layers from the server.

This method is blocking and will wait for results from the server before returning.
Accordingly it should not be used from any code which potentially blocks operation in the main GUI thread.

.. seealso:: fetchLayers()
:rtype: list of QgsGeoNodeRequest.ServiceLayerDetail
%End

QList<QgsGeoNodeStyle> getStyles( const QString &layerName );
QList<QgsGeoNodeStyle> fetchStylesBlocking( const QString &layerName );
%Docstring
Requests the list of available styles for the layer
with matching ``layerName`` from the server.

This method is blocking and will wait for results from the server before returning.
Accordingly it should not be used from any code which potentially blocks operation in the main GUI thread.
:rtype: list of QgsGeoNodeStyle
%End

QgsGeoNodeStyle getDefaultStyle( const QString &layerName );
QgsGeoNodeStyle fetchDefaultStyleBlocking( const QString &layerName );
%Docstring
Requests the default style for the layer with matching ``layerName`` from the server.

This method is blocking and will wait for results from the server before returning.
Accordingly it should not be used from any code which potentially blocks operation in the main GUI thread.
:rtype: QgsGeoNodeStyle
%End

QgsGeoNodeStyle getStyle( const QString &styleID );
QgsGeoNodeStyle fetchStyleBlocking( const QString &styleId );
%Docstring
Requests the details for the style with matching ``styleId`` from the server.

This method is blocking and will wait for results from the server before returning.
Accordingly it should not be used from any code which potentially blocks operation in the main GUI thread.
:rtype: QgsGeoNodeStyle
%End

QStringList serviceUrls( const QString &serviceType );
QStringList fetchServiceUrlsBlocking( const QString &serviceType );
%Docstring
Obtain list of unique URLs in the geonode
Requests the list of unique URLs for available services with matching ``serviceType`` from the server.

This method is blocking and will wait for results from the server before returning.
Accordingly it should not be used from any code which potentially blocks operation in the main GUI thread.
:rtype: list of str
%End

QgsStringMap serviceUrlData( const QString &serviceType );
QgsStringMap fetchServiceUrlDataBlocking( const QString &serviceType );
%Docstring
Obtain map of layer name and url for a service type
Obtains a map of layer name to URL for available services with matching ``serviceType`` from the server.

This method is blocking and will wait for results from the server before returning.
Accordingly it should not be used from any code which potentially blocks operation in the main GUI thread.
:rtype: QgsStringMap
%End

QString lastError() const;
%Docstring
Returns the most recent error string for any encountered errors, or an empty string if
no errors have been encountered.
:rtype: str
%End

QByteArray response() const;
QByteArray lastResponse() const;
%Docstring
Returns the most recent response obtained from the server.
:rtype: QByteArray
%End

QNetworkReply *reply() const;
QString protocol() const;
%Docstring
:rtype: QNetworkReply
Returns the network protocol (e.g. 'http') used for connecting with the server.
.. seealso:: setProtocol()
:rtype: str
%End

void abort();
void setProtocol( const QString &protocol );
%Docstring
Abort network request immediately
Sets the network ``protocol`` (e.g. 'http') used for connecting with the server.
.. seealso:: protocol()
%End

QString getProtocol() const;
public slots:

void abort();
%Docstring
:rtype: str
Aborts any active network request immediately.
%End
void setProtocol( const QString &protocol );

signals:

void statusChanged( const QString &statusQString );
%Docstring
emit a signal to be caught by qgisapp and display a statusQString on status bar
Emitted when the status of an ongoing request is changed.
%End

void requestFinished();
%Docstring
emit a signal once the request is finished
Emitted when the existing request has been completed.
%End

protected slots:
void replyFinished();
void replyProgress( qint64, qint64 );

protected:








void layersFetched( const QList<QgsGeoNodeRequest::ServiceLayerDetail> &layers );
%Docstring
Emitted when the result of a fetchLayers call has been received and processed.
%End

};

Expand Down
6 changes: 3 additions & 3 deletions src/app/geocms/geonode/qgsgeonodedataitems.cpp
Expand Up @@ -38,9 +38,9 @@ QVector<QgsDataItem *> QgsGeoNodeConnectionItem::createChildren()
QString url = mConnection->uri().param( QStringLiteral( "url" ) );
QgsGeoNodeRequest geonodeRequest( url, true );

QStringList wmsUrl = geonodeRequest.serviceUrls( QStringLiteral( "WMS" ) );
QStringList wfsUrl = geonodeRequest.serviceUrls( QStringLiteral( "WFS" ) );
QStringList xyzUrl = geonodeRequest.serviceUrls( QStringLiteral( "XYZ" ) );
QStringList wmsUrl = geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "WMS" ) );
QStringList wfsUrl = geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "WFS" ) );
QStringList xyzUrl = geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "XYZ" ) );

if ( !wmsUrl.isEmpty() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/geocms/geonode/qgsgeonodenewconnection.cpp
Expand Up @@ -249,7 +249,7 @@ void QgsGeoNodeNewConnection::testConnection()
QString url = txtUrl->text();
QgsGeoNodeRequest geonodeRequest( url, true );

QList<QgsGeoNodeRequest::ServiceLayerDetail> layers = geonodeRequest.getLayers();
QList<QgsGeoNodeRequest::ServiceLayerDetail> layers = geonodeRequest.fetchLayersBlocking();
QApplication::restoreOverrideCursor();

if ( !layers.empty() )
Expand Down

0 comments on commit e1562df

Please sign in to comment.