Skip to content

Commit

Permalink
Make capabilities methods const, drop unused ones
Browse files Browse the repository at this point in the history
Uses mutable members to retain the lazy capability queries
  • Loading branch information
strk committed Nov 15, 2019
1 parent 3c25e29 commit cc5db6f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 58 deletions.
33 changes: 8 additions & 25 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -208,8 +208,6 @@ QgsPostgresConn::QgsPostgresConn( const QString &conninfo, bool readOnly, bool s
, mPostgresqlVersion( 0 )
, mPostgisVersionMajor( 0 )
, mPostgisVersionMinor( 0 )
, mGistAvailable( false )
, mProjAvailable( false )
, mPointcloudAvailable( false )
, mRasterAvailable( false )
, mUseWkbHex( false )
Expand Down Expand Up @@ -403,7 +401,7 @@ void QgsPostgresConn::unref()
}

/* private */
QStringList QgsPostgresConn::supportedSpatialTypes()
QStringList QgsPostgresConn::supportedSpatialTypes() const
{
QStringList supportedSpatialTypes;

Expand Down Expand Up @@ -960,7 +958,7 @@ bool QgsPostgresConn::getSchemas( QList<QgsPostgresSchemaProperty> &schemas )
/**
* Check to see if GEOS is available
*/
bool QgsPostgresConn::hasGEOS()
bool QgsPostgresConn::hasGEOS() const
{
// make sure info is up to date for the current connection
postgisVersion();
Expand All @@ -970,7 +968,7 @@ bool QgsPostgresConn::hasGEOS()
/**
* Check to see if topology is available
*/
bool QgsPostgresConn::hasTopology()
bool QgsPostgresConn::hasTopology() const
{
// make sure info is up to date for the current connection
postgisVersion();
Expand All @@ -980,7 +978,7 @@ bool QgsPostgresConn::hasTopology()
/**
* Check to see if pointcloud is available
*/
bool QgsPostgresConn::hasPointcloud()
bool QgsPostgresConn::hasPointcloud() const
{
// make sure info is up to date for the current connection
postgisVersion();
Expand All @@ -990,14 +988,14 @@ bool QgsPostgresConn::hasPointcloud()
/**
* Check to see if raster is available
*/
bool QgsPostgresConn::hasRaster()
bool QgsPostgresConn::hasRaster() const
{
// make sure info is up to date for the current connection
postgisVersion();
return mRasterAvailable;
}
/* Functions for determining available features in postGIS */
QString QgsPostgresConn::postgisVersion()
QString QgsPostgresConn::postgisVersion() const
{
QMutexLocker locker( &mLock );
if ( mGotPostgisVersion )
Expand Down Expand Up @@ -1035,37 +1033,22 @@ QString QgsPostgresConn::postgisVersion()
// apparently PostGIS 1.5.2 doesn't report capabilities in postgis_version() anymore
if ( mPostgisVersionMajor > 1 || ( mPostgisVersionMajor == 1 && mPostgisVersionMinor >= 5 ) )
{
result = PQexec( QStringLiteral( "SELECT postgis_geos_version(),postgis_proj_version()" ) );
result = PQexec( QStringLiteral( "SELECT postgis_geos_version()" ) );
mGeosAvailable = result.PQntuples() == 1 && !result.PQgetisnull( 0, 0 );
mProjAvailable = result.PQntuples() == 1 && !result.PQgetisnull( 0, 1 );
QgsDebugMsg( QStringLiteral( "geos:%1 proj:%2" )
.arg( mGeosAvailable ? result.PQgetvalue( 0, 0 ) : "none",
mProjAvailable ? result.PQgetvalue( 0, 1 ) : "none" ) );
mGistAvailable = true;
.arg( mGeosAvailable ? result.PQgetvalue( 0, 0 ) : "none" ) );
}
else
{
// assume no capabilities
mGeosAvailable = false;
mGistAvailable = false;
mProjAvailable = false;

// parse out the capabilities and store them
QStringList geos = postgisParts.filter( QStringLiteral( "GEOS" ) );
if ( geos.size() == 1 )
{
mGeosAvailable = ( geos[0].indexOf( QLatin1String( "=1" ) ) > -1 );
}
QStringList gist = postgisParts.filter( QStringLiteral( "STATS" ) );
if ( gist.size() == 1 )
{
mGistAvailable = ( gist[0].indexOf( QLatin1String( "=1" ) ) > -1 );
}
QStringList proj = postgisParts.filter( QStringLiteral( "PROJ" ) );
if ( proj.size() == 1 )
{
mProjAvailable = ( proj[0].indexOf( QLatin1String( "=1" ) ) > -1 );
}
}

// checking for topology support
Expand Down
54 changes: 21 additions & 33 deletions src/providers/postgres/qgspostgresconn.h
Expand Up @@ -202,37 +202,31 @@ class QgsPostgresConn : public QObject
void unref();

//! Gets postgis version string
QString postgisVersion();
QString postgisVersion() const;

//! Gets status of GEOS capability
bool hasGEOS();
bool hasGEOS() const;

//! Gets status of topology capability
bool hasTopology();
bool hasTopology() const;

//! Gets status of Pointcloud capability
bool hasPointcloud();
bool hasPointcloud() const;

//! Gets status of Raster capability
bool hasRaster();

//! Gets status of GIST capability
bool hasGIST();

//! Gets status of PROJ4 capability
bool hasPROJ();
bool hasRaster() const;

//! encode wkb in hex
bool useWkbHex() { return mUseWkbHex; }
bool useWkbHex() const { return mUseWkbHex; }

//! major PostGIS version
int majorVersion() { return mPostgisVersionMajor; }
int majorVersion() const { return mPostgisVersionMajor; }

//! minor PostGIS version
int minorVersion() { return mPostgisVersionMinor; }
int minorVersion() const { return mPostgisVersionMinor; }

//! PostgreSQL version
int pgVersion() { return mPostgresqlVersion; }
int pgVersion() const { return mPostgresqlVersion; }

//! run a query and free result buffer
bool PQexecNR( const QString &query );
Expand Down Expand Up @@ -395,44 +389,38 @@ class QgsPostgresConn : public QObject
QString mConnInfo;

//! GEOS capability
bool mGeosAvailable;
mutable bool mGeosAvailable;

//! Topology capability
bool mTopologyAvailable;
mutable bool mTopologyAvailable;

//! PostGIS version string
QString mPostgisVersionInfo;
mutable QString mPostgisVersionInfo;

//! Are mPostgisVersionMajor, mPostgisVersionMinor, mGeosAvailable, mGistAvailable, mProjAvailable, mTopologyAvailable valid?
bool mGotPostgisVersion;
//! Are mPostgisVersionMajor, mPostgisVersionMinor, mGeosAvailable, mTopologyAvailable valid?
mutable bool mGotPostgisVersion;

//! PostgreSQL version
int mPostgresqlVersion;
mutable int mPostgresqlVersion;

//! PostGIS major version
int mPostgisVersionMajor;
mutable int mPostgisVersionMajor;

//! PostGIS minor version
int mPostgisVersionMinor;

//! GIST capability
bool mGistAvailable;

//! PROJ4 capability
bool mProjAvailable;
mutable int mPostgisVersionMinor;

//! pointcloud support available
bool mPointcloudAvailable;
mutable bool mPointcloudAvailable;

//! raster support available
bool mRasterAvailable;
mutable bool mRasterAvailable;

//! encode wkb in hex
bool mUseWkbHex;
mutable bool mUseWkbHex;

bool mReadOnly;

QStringList supportedSpatialTypes();
QStringList supportedSpatialTypes() const;

static QMap<QString, QgsPostgresConn *> sConnectionsRW;
static QMap<QString, QgsPostgresConn *> sConnectionsRO;
Expand Down

0 comments on commit cc5db6f

Please sign in to comment.