Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Split QgsGeoNodeConnection into two classes
Move utility functions to QgsGeoNodeConnectionUtils
  • Loading branch information
nyalldawson committed Sep 12, 2017
1 parent b7683f2 commit 378a9e9
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 142 deletions.
3 changes: 1 addition & 2 deletions python/core/core_auto.sip
Expand Up @@ -284,8 +284,6 @@
%Include fieldformatter/qgsrelationreferencefieldformatter.sip
%Include fieldformatter/qgsvaluemapfieldformatter.sip
%Include fieldformatter/qgsvaluerelationfieldformatter.sip
%Include geonode/qgsgeonodeconnection.sip
%Include geonode/qgsgeonoderequest.sip
%Include gps/qgsqtlocationconnection.sip
%Include gps/qgsgpsconnectionregistry.sip
%Include qgsapplication.sip
Expand Down Expand Up @@ -384,6 +382,7 @@
%Include raster/qgsrasterdataprovider.sip
%Include raster/qgsrasterinterface.sip
%Include geometry/qgspoint.sip
%Include geonode/qgsgeonoderequest.sip
%Include gps/qgsgpsconnection.sip
%Include gps/qgsgpsdetector.sip
%Include gps/qgsnmeaconnection.sip
Expand Down
86 changes: 0 additions & 86 deletions python/core/geonode/qgsgeonodeconnection.sip
@@ -1,86 +0,0 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/geonode/qgsgeonodeconnection.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsGeoNodeConnection
{
%Docstring
!
GeoNode Connections management
%End

%TypeHeaderCode
#include "qgsgeonodeconnection.h"
%End
public:
explicit QgsGeoNodeConnection( const QString &connName );
%Docstring
Constructor
%End

~QgsGeoNodeConnection();
%Docstring
Destructor
%End

QString connName() const;
%Docstring
:rtype: str
%End
void setConnName( const QString &connName );

QgsDataSourceUri uri() const;
%Docstring
:rtype: QgsDataSourceUri
%End
void setUri( const QgsDataSourceUri &uri );

static QStringList connectionList();
%Docstring
Retrieve all geonode connection
:rtype: list of str
%End

static void deleteConnection( const QString &name );
%Docstring
Delete connection with name, name
%End

static QString selectedConnection();
%Docstring
Get selected connection
:rtype: str
%End

static void setSelectedConnection( const QString &name );
%Docstring
Set selected connection
%End

static QString pathGeoNodeConnection();
%Docstring
:rtype: str
%End

static QString pathGeoNodeConnectionDetails();
%Docstring
:rtype: str
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/geonode/qgsgeonodeconnection.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 2 additions & 0 deletions python/core/qgsdataitem.sip
Expand Up @@ -257,6 +257,8 @@ Create path component replacing path separators
:rtype: str
%End

void setActions( QList<QAction *> actions );

static void deleteLater( QVector<QgsDataItem *> &items );

void moveToThread( QThread *targetThread );
Expand Down
57 changes: 31 additions & 26 deletions src/core/geonode/qgsgeonodeconnection.cpp
Expand Up @@ -18,18 +18,17 @@
#include "qgslogger.h"
#include "qgsdatasourceuri.h"

const QString QgsGeoNodeConnection::sPathGeoNodeConnection = "qgis/connections-geonode";
const QString QgsGeoNodeConnection::sPathGeoNodeConnectionDetails = "qgis/GeoNode";
const QString QgsGeoNodeConnectionUtils::sPathGeoNodeConnection = "qgis/connections-geonode";
const QString QgsGeoNodeConnectionUtils::sPathGeoNodeConnectionDetails = "qgis/GeoNode";

QgsGeoNodeConnection::QgsGeoNodeConnection( const QString &connName )
: mConnName( connName )
{
QgsSettings settings;


// settings.Section
QString key = sPathGeoNodeConnection + QStringLiteral( "/" ) + mConnName;
QString credentialsKey = sPathGeoNodeConnectionDetails + QStringLiteral( "/" ) + mConnName;
QString key = QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/" ) + mConnName;
QString credentialsKey = QgsGeoNodeConnectionUtils::pathGeoNodeConnectionDetails() + QStringLiteral( "/" ) + mConnName;

mUri.setParam( QStringLiteral( "url" ), settings.value( key + QStringLiteral( "/url" ), QString(), QgsSettings::Providers ).toString() );

Expand Down Expand Up @@ -61,55 +60,61 @@ QgsDataSourceUri QgsGeoNodeConnection::uri() const
return mUri;
}

QStringList QgsGeoNodeConnection::connectionList()
QString QgsGeoNodeConnection::connName() const
{
return mConnName;
}

void QgsGeoNodeConnection::setConnName( const QString &connName )
{
mConnName = connName;
}

void QgsGeoNodeConnection::setUri( const QgsDataSourceUri &uri )
{
mUri = uri;
}


//
// QgsGeoNodeConnectionUtils
//


QStringList QgsGeoNodeConnectionUtils::connectionList()
{
QgsSettings settings;
// Add Section manually
settings.beginGroup( QStringLiteral( "providers/qgis/connections-geonode" ) );
return settings.childGroups();
}

void QgsGeoNodeConnection::deleteConnection( const QString &name )
void QgsGeoNodeConnectionUtils::deleteConnection( const QString &name )
{
QgsSettings settings;
// Add Section manually
settings.remove( QStringLiteral( "providers/qgis/connections-geonode/" ) + name );
settings.remove( QStringLiteral( "providers/qgis/geonode/" ) + name );
}

QString QgsGeoNodeConnection::selectedConnection()
QString QgsGeoNodeConnectionUtils::selectedConnection()
{
QgsSettings settings;
return settings.value( QStringLiteral( "qgis/connections-geonode/selected" ), QString(), QgsSettings::Providers ).toString();
}

void QgsGeoNodeConnection::setSelectedConnection( const QString &name )
void QgsGeoNodeConnectionUtils::setSelectedConnection( const QString &name )
{
QgsSettings settings;
settings.setValue( QStringLiteral( "qgis/connections-geonode/selected" ), name, QgsSettings::Providers );
}

QString QgsGeoNodeConnection::pathGeoNodeConnection()
QString QgsGeoNodeConnectionUtils::pathGeoNodeConnection()
{
return sPathGeoNodeConnection;
}

QString QgsGeoNodeConnection::pathGeoNodeConnectionDetails()
QString QgsGeoNodeConnectionUtils::pathGeoNodeConnectionDetails()
{
return sPathGeoNodeConnectionDetails;
}

QString QgsGeoNodeConnection::connName() const
{
return mConnName;
}

void QgsGeoNodeConnection::setConnName( const QString &connName )
{
mConnName = connName;
}

void QgsGeoNodeConnection::setUri( const QgsDataSourceUri &uri )
{
mUri = uri;
}
22 changes: 16 additions & 6 deletions src/core/geonode/qgsgeonodeconnection.h
Expand Up @@ -19,9 +19,10 @@
#include "qgis_core.h"
#include "qgsdatasourceuri.h"

SIP_NO_FILE

/*!
* \brief GeoNode Connections management
* \brief GeoNode Connections management
*/
class CORE_EXPORT QgsGeoNodeConnection
{
Expand All @@ -39,6 +40,19 @@ class CORE_EXPORT QgsGeoNodeConnection
QgsDataSourceUri uri() const;
void setUri( const QgsDataSourceUri &uri );

private:

//! The connection name
QString mConnName;

//! Property of mUri
QgsDataSourceUri mUri;
};

class CORE_EXPORT QgsGeoNodeConnectionUtils
{
public:

//! Retrieve all geonode connection
static QStringList connectionList();

Expand All @@ -56,15 +70,11 @@ class CORE_EXPORT QgsGeoNodeConnection
static QString pathGeoNodeConnectionDetails();

private:

// Path in QSetting
static const QString sPathGeoNodeConnection;
static const QString sPathGeoNodeConnectionDetails;

//! The connection name
QString mConnName;

//! Property of mUri
QgsDataSourceUri mUri;
};


Expand Down
4 changes: 2 additions & 2 deletions src/gui/geonode/qgsgeonodenewconnection.cpp
Expand Up @@ -33,8 +33,8 @@ QgsGeoNodeNewConnection::QgsGeoNodeNewConnection( QWidget *parent, const QString
{
setupUi( this );

mBaseKey = QgsGeoNodeConnection::pathGeoNodeConnection();
mCredentialsBaseKey = QgsGeoNodeConnection::pathGeoNodeConnection();
mBaseKey = QgsGeoNodeConnectionUtils::pathGeoNodeConnection();
mCredentialsBaseKey = QgsGeoNodeConnectionUtils::pathGeoNodeConnection();

mAuthConfigSelect = new QgsAuthConfigSelect( this );
tabAuth->insertTab( 1, mAuthConfigSelect, tr( "Configurations" ) );
Expand Down
6 changes: 3 additions & 3 deletions src/gui/geonode/qgsgeonodesourceselect.cpp
Expand Up @@ -118,7 +118,7 @@ void QgsGeoNodeSourceSelect::deleteConnectionsEntryList()
QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
if ( result == QMessageBox::Ok )
{
QgsGeoNodeConnection::deleteConnection( cmbConnections->currentText() );
QgsGeoNodeConnectionUtils::deleteConnection( cmbConnections->currentText() );
cmbConnections->removeItem( cmbConnections->currentIndex() );
if ( mModel )
{
Expand Down Expand Up @@ -148,14 +148,14 @@ void QgsGeoNodeSourceSelect::deleteConnectionsEntryList()
void QgsGeoNodeSourceSelect::populateConnectionList()
{
cmbConnections->clear();
cmbConnections->addItems( QgsGeoNodeConnection::connectionList() );
cmbConnections->addItems( QgsGeoNodeConnectionUtils::connectionList() );

setConnectionListPosition();
}

void QgsGeoNodeSourceSelect::setConnectionListPosition()
{
QString toSelect = QgsGeoNodeConnection::selectedConnection();
QString toSelect = QgsGeoNodeConnectionUtils::selectedConnection();

cmbConnections->setCurrentIndex( cmbConnections->findText( toSelect ) );

Expand Down
4 changes: 2 additions & 2 deletions src/providers/ows/qgsgeonodedataitems.cpp
Expand Up @@ -229,7 +229,7 @@ QVector<QgsDataItem *> QgsGeoNodeRootItem::createChildren()
{
QVector<QgsDataItem *> connections;

Q_FOREACH ( const QString &connName, QgsGeoNodeConnection::connectionList() )
Q_FOREACH ( const QString &connName, QgsGeoNodeConnectionUtils::connectionList() )
{
QgsGeoNodeConnection *connection = nullptr;
connection = new QgsGeoNodeConnection( connName );
Expand Down Expand Up @@ -270,7 +270,7 @@ QgsDataItem *QgsGeoNodeDataItemProvider::createDataItem( const QString &path, Qg
if ( path.startsWith( QLatin1String( "geonode:/" ) ) )
{
QString connectionName = path.split( '/' ).last();
if ( QgsGeoNodeConnection::connectionList().contains( connectionName ) )
if ( QgsGeoNodeConnectionUtils::connectionList().contains( connectionName ) )
{
QgsGeoNodeConnection *connection = new QgsGeoNodeConnection( connectionName );
return new QgsGeoNodeConnectionItem( parentItem, QStringLiteral( "GeoNode" ), path, connection );
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ows/qgsgeonodedataitems.h
Expand Up @@ -36,7 +36,7 @@ class QgsGeoNodeConnectionItem : public QgsDataCollectionItem
void editConnection();
void deleteConnection()
{
QgsGeoNodeConnection::deleteConnection( name() );
QgsGeoNodeConnectionUtils::deleteConnection( name() );
mParent->refresh();
};

Expand Down
4 changes: 2 additions & 2 deletions src/providers/wfs/qgswfsdataitems.cpp
Expand Up @@ -220,7 +220,7 @@ QgsDataItem *QgsWfsDataItemProvider::createDataItem( const QString &path, QgsDat
else if ( path.startsWith( QLatin1String( "geonode:/" ) ) )
{
QString connectionName = path.split( '/' ).last();
if ( QgsGeoNodeConnection::connectionList().contains( connectionName ) )
if ( QgsGeoNodeConnectionUtils::connectionList().contains( connectionName ) )
{
QgsGeoNodeConnection connection( connectionName );

Expand All @@ -244,7 +244,7 @@ QVector<QgsDataItem *> QgsWfsDataItemProvider::createDataItems( const QString &p
if ( path.startsWith( QLatin1String( "geonode:/" ) ) )
{
QString connectionName = path.split( '/' ).last();
if ( QgsGeoNodeConnection::connectionList().contains( connectionName ) )
if ( QgsGeoNodeConnectionUtils::connectionList().contains( connectionName ) )
{
QgsGeoNodeConnection connection( connectionName );

Expand Down
6 changes: 3 additions & 3 deletions src/providers/wms/qgswmsdataitems.cpp
Expand Up @@ -559,7 +559,7 @@ QVector<QgsDataItem *> QgsWmsDataItemProvider::createDataItems( const QString &p
if ( path.startsWith( QLatin1String( "geonode:/" ) ) )
{
QString connectionName = path.split( '/' ).last();
if ( QgsGeoNodeConnection::connectionList().contains( connectionName ) )
if ( QgsGeoNodeConnectionUtils::connectionList().contains( connectionName ) )
{
QgsGeoNodeConnection connection( connectionName );

Expand All @@ -575,7 +575,7 @@ QVector<QgsDataItem *> QgsWmsDataItemProvider::createDataItems( const QString &p
QgsDebugMsg( encodedUri );
QgsDataSourceUri uri;
QgsSettings settings;
QString key( connection.pathGeoNodeConnection() + "/" + connectionName );
QString key( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + "/" + connectionName );

QString dpiMode = settings.value( key + "/wms/dpiMode", "all", QgsSettings::Providers ).toString();
uri.setParam( QStringLiteral( "url" ), encodedUri );
Expand Down Expand Up @@ -605,7 +605,7 @@ QVector<QgsDataItem *> QgsXyzTileDataItemProvider::createDataItems( const QStrin
if ( path.startsWith( QLatin1String( "geonode:/" ) ) )
{
QString connectionName = path.split( '/' ).last();
if ( QgsGeoNodeConnection::connectionList().contains( connectionName ) )
if ( QgsGeoNodeConnectionUtils::connectionList().contains( connectionName ) )
{
QgsGeoNodeConnection connection( connectionName );

Expand Down

0 comments on commit 378a9e9

Please sign in to comment.