mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Simplify getLayers method for geonode client.
This commit is contained in:
parent
bdc3d36601
commit
500c5c1108
@ -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
|
||||
|
@ -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 )
|
||||
@ -83,7 +89,6 @@ void QgsGeoNodeRequest::setProtocol( const QString &protocol )
|
||||
mProtocol = protocol;
|
||||
}
|
||||
|
||||
|
||||
void QgsGeoNodeRequest::replyFinished()
|
||||
{
|
||||
QgsMessageLog::logMessage( QStringLiteral( "Reply finished" ), tr( "GeoNode" ) );
|
||||
@ -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;
|
||||
@ -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 )
|
||||
{
|
||||
@ -386,7 +388,6 @@ QgsStringMap QgsGeoNodeRequest::serviceUrlData( QString serviceType )
|
||||
return urls;
|
||||
}
|
||||
|
||||
|
||||
bool QgsGeoNodeRequest::request( QString endPoint )
|
||||
{
|
||||
abort();
|
||||
|
@ -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 );
|
||||
@ -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 );
|
||||
|
@ -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" ),
|
||||
|
@ -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" ) );
|
||||
}
|
||||
@ -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() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user