Skip to content
Permalink
Browse files

[postgres] Automatically populate layer metadata

Not much is available to automatically populate, but we can
set the abstract to match the table comment, the crs, and datatype.
  • Loading branch information
nyalldawson committed Mar 14, 2018
1 parent f55347f commit 7dd5cafc00f5aa925be85e61c15de7e6fbc2602b
Showing with 17 additions and 0 deletions.
  1. +14 −0 src/providers/postgres/qgspostgresprovider.cpp
  2. +3 −0 src/providers/postgres/qgspostgresprovider.h
@@ -278,6 +278,9 @@ QgsPostgresProvider::QgsPostgresProvider( QString const &uri )
{
disconnectDb();
}

mLayerMetadata.setType( QStringLiteral( "dataset" ) );
mLayerMetadata.setCrs( crs() );
}

QgsPostgresProvider::~QgsPostgresProvider()
@@ -653,6 +656,11 @@ QgsWkbTypes::Type QgsPostgresProvider::wkbType() const
return mRequestedGeomType != QgsWkbTypes::Unknown ? mRequestedGeomType : mDetectedGeomType;
}

QgsLayerMetadata QgsPostgresProvider::layerMetadata() const
{
return mLayerMetadata;
}

QgsField QgsPostgresProvider::field( int index ) const
{
if ( index < 0 || index >= mAttributeFields.count() )
@@ -713,7 +721,10 @@ bool QgsPostgresProvider::loadFields()
sql = QStringLiteral( "SELECT description FROM pg_description WHERE objoid=%1 AND objsubid=0" ).arg( tableoid );
tresult = connectionRO()->PQexec( sql );
if ( tresult.PQntuples() > 0 )
{
mDataComment = tresult.PQgetvalue( 0, 0 );
mLayerMetadata.setAbstract( mDataComment );
}
}

// Populate the field vector for this layer. The field vector contains
@@ -1254,6 +1265,9 @@ bool QgsPostgresProvider::hasSufficientPermsAndCapabilities()
// supports circular geometries
mEnabledCapabilities |= QgsVectorDataProvider::CircularGeometries;

// supports layer metadata
mEnabledCapabilities |= QgsVectorDataProvider::ReadLayerMetadata;

if ( ( mEnabledCapabilities & QgsVectorDataProvider::ChangeGeometries ) &&
( mEnabledCapabilities & QgsVectorDataProvider::ChangeAttributeValues ) &&
mSpatialColType != SctTopoGeometry )
@@ -98,6 +98,7 @@ class QgsPostgresProvider : public QgsVectorDataProvider
QgsCoordinateReferenceSystem crs() const override;
QgsFeatureIterator getFeatures( const QgsFeatureRequest &request ) const override;
QgsWkbTypes::Type wkbType() const override;
QgsLayerMetadata layerMetadata() const override;

/**
* Return the number of layers for the current data source
@@ -447,6 +448,8 @@ class QgsPostgresProvider : public QgsVectorDataProvider

bool mCheckPrimaryKeyUnicity = true;

QgsLayerMetadata mLayerMetadata;

std::unique_ptr< QgsPostgresListener > mListener;
};

0 comments on commit 7dd5caf

Please sign in to comment.
You can’t perform that action at this time.