Skip to content

Commit

Permalink
Simplify getLayers method for geonode client.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni authored and nyalldawson committed Sep 12, 2017
1 parent bdc3d36 commit 500c5c1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
7 changes: 1 addition & 6 deletions python/core/geonode/qgsgeonoderequest.sip
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ class QgsGeoNodeRequest : QObject
:rtype: bool
%End

bool getLayers();
%Docstring
:rtype: bool
%End

QList<QgsServiceLayerDetail> parseLayers( QByteArray layerResponse );
QList<QgsServiceLayerDetail> getLayers();
%Docstring
:rtype: list of QgsServiceLayerDetail
%End
Expand Down
27 changes: 14 additions & 13 deletions src/core/geonode/qgsgeonoderequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ void QgsGeoNodeRequest::abort()
}
}

bool QgsGeoNodeRequest::getLayers()
QList<QgsServiceLayerDetail> QgsGeoNodeRequest::getLayers()
{
return request( QStringLiteral( "/api/layers/" ) );
QList<QgsServiceLayerDetail> layers;
bool success = request( QStringLiteral( "/api/layers/" ) );
if ( !success )
{
return layers;
}
return parseLayers( this->response() );
}

void QgsGeoNodeRequest::replyProgress( qint64 bytesReceived, qint64 bytesTotal )
Expand All @@ -83,7 +89,6 @@ void QgsGeoNodeRequest::setProtocol( const QString &protocol )
mProtocol = protocol;
}


void QgsGeoNodeRequest::replyFinished()
{
QgsMessageLog::logMessage( QStringLiteral( "Reply finished" ), tr( "GeoNode" ) );
Expand Down Expand Up @@ -293,19 +298,17 @@ QList<QgsServiceLayerDetail> QgsGeoNodeRequest::parseLayers( QByteArray layerRes
return layers;
}


QStringList QgsGeoNodeRequest::serviceUrls( QString serviceType )
{
QStringList urls;
bool success = getLayers();

if ( !success )
QList<QgsServiceLayerDetail> layers = getLayers();

if ( layers.empty() )
{
return urls;
}

QList<QgsServiceLayerDetail> layers = parseLayers( this->response() );

Q_FOREACH ( QgsServiceLayerDetail layer, layers )
{
QString url;
Expand Down Expand Up @@ -339,17 +342,16 @@ QStringList QgsGeoNodeRequest::serviceUrls( QString serviceType )
return urls;
}


QgsStringMap QgsGeoNodeRequest::serviceUrlData( QString serviceType )
{
QgsStringMap urls;
bool success = getLayers();

if ( !success )
QList<QgsServiceLayerDetail> layers = getLayers();

if ( layers.empty() )
{
return urls;
}
QList<QgsServiceLayerDetail> layers = parseLayers( this->response() );

Q_FOREACH ( QgsServiceLayerDetail layer, layers )
{
Expand Down Expand Up @@ -386,7 +388,6 @@ QgsStringMap QgsGeoNodeRequest::serviceUrlData( QString serviceType )
return urls;
}


bool QgsGeoNodeRequest::request( QString endPoint )
{
abort();
Expand Down
7 changes: 4 additions & 3 deletions src/core/geonode/qgsgeonoderequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class CORE_EXPORT QgsGeoNodeRequest : public QObject

bool request( QString endPoint );

bool getLayers();

QList<QgsServiceLayerDetail> parseLayers( QByteArray layerResponse );
QList<QgsServiceLayerDetail> getLayers();

// Obtain list of unique URL in the geonode
QStringList serviceUrls( QString serviceType );
Expand All @@ -71,6 +69,9 @@ class CORE_EXPORT QgsGeoNodeRequest : public QObject
QString getProtocol() const;
void setProtocol( const QString &protocol );

private:
QList<QgsServiceLayerDetail> parseLayers( QByteArray layerResponse );

signals:
//! \brief emit a signal to be caught by qgisapp and display a statusQString on status bar
void statusChanged( const QString &statusQString );
Expand Down
5 changes: 3 additions & 2 deletions src/gui/geonode/qgsgeonodenewconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,11 @@ void QgsGeoNodeNewConnection::testConnection()
QApplication::setOverrideCursor( Qt::BusyCursor );
QString url = txtUrl->text();
QgsGeoNodeRequest geonodeRequest( url, true );
bool success = geonodeRequest.getLayers();

QList<QgsServiceLayerDetail> layers = geonodeRequest.getLayers();
QApplication::restoreOverrideCursor();

if ( success )
if ( !layers.empty() )
{
QMessageBox::information( this,
tr( "Test connection" ),
Expand Down
8 changes: 2 additions & 6 deletions src/gui/geonode/qgsgeonodesourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ void QgsGeoNodeSourceSelect::connectToGeonodeConnection()
QgsGeoNodeRequest geonodeRequest( url, true );

QApplication::setOverrideCursor( Qt::WaitCursor );
bool success = geonodeRequest.getLayers();
QList<QgsServiceLayerDetail> layers = geonodeRequest.getLayers();
QApplication::restoreOverrideCursor();

if ( success )
if ( !layers.empty() )
{
QgsMessageLog::logMessage( QStringLiteral( "Success" ), tr( "GeoNode" ) );
}
Expand All @@ -206,10 +206,6 @@ void QgsGeoNodeSourceSelect::connectToGeonodeConnection()
QgsMessageLog::logMessage( QStringLiteral( "Failed" ), tr( "GeoNode" ) );
}

QByteArray ba = geonodeRequest.response();

QList<QgsServiceLayerDetail> layers = geonodeRequest.parseLayers( ba );

if ( mModel )
{
mModel->removeRows( 0, mModel->rowCount() );
Expand Down

0 comments on commit 500c5c1

Please sign in to comment.