Skip to content

Commit

Permalink
[postgres] Automatically populate layer metadata
Browse files Browse the repository at this point in the history
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 7dd5caf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ QgsPostgresProvider::QgsPostgresProvider( QString const &uri )
{
disconnectDb();
}

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

QgsPostgresProvider::~QgsPostgresProvider()
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand Down
3 changes: 3 additions & 0 deletions src/providers/postgres/qgspostgresprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -447,6 +448,8 @@ class QgsPostgresProvider : public QgsVectorDataProvider

bool mCheckPrimaryKeyUnicity = true;

QgsLayerMetadata mLayerMetadata;

std::unique_ptr< QgsPostgresListener > mListener;
};

Expand Down

0 comments on commit 7dd5caf

Please sign in to comment.