Skip to content
Permalink
Browse files

do not display metadata related to spatial extent if the layer is not…

… spatial
  • Loading branch information
Gustry authored and nyalldawson committed Sep 6, 2018
1 parent da39078 commit c65fe0e07c0c750956776c9d360c5bbfb2191798
@@ -39,10 +39,12 @@ Formats the "Contacts" section according to a ``metadata`` object.
This will return a HTML table.
%End

QString extentSectionHtml() const;
QString extentSectionHtml( const bool showSpatialExtent = true ) const;
%Docstring
Formats the "Extents" section according to a ``metadata`` object.
Formats the "Extents" section according to a ``metadata`` object (extent and temporal).
This will return a HTML table.

:param showSpatialExtent: flag if the spatial extent needs to be displayed. Default to true.
%End

QString identificationSectionHtml() const;
@@ -107,50 +107,53 @@ QString QgsLayerMetadataFormatter::contactsSectionHtml() const
return myMetadata;
}

QString QgsLayerMetadataFormatter::extentSectionHtml() const
QString QgsLayerMetadataFormatter::extentSectionHtml( const bool showSpatialExtent ) const
{
QString myMetadata = QStringLiteral( "<table class=\"list-view\">\n" );
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + QObject::tr( "CRS" ) + QStringLiteral( "</td><td>" );
if ( mMetadata.crs().isValid() )
{
myMetadata += mMetadata.crs().authid() + QStringLiteral( " - " );
myMetadata += mMetadata.crs().description() + QStringLiteral( " - " );
if ( mMetadata.crs().isGeographic() )
myMetadata += QObject::tr( "Geographic" );
else
myMetadata += QObject::tr( "Projected" );
}
myMetadata += QLatin1String( "</td></tr>\n" );

const QgsLayerMetadata::Extent extent = mMetadata.extent();
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + QObject::tr( "Spatial Extent" ) + QStringLiteral( "</td><td>" );
const QList< QgsLayerMetadata::SpatialExtent > spatialExtents = extent.spatialExtents();
bool notFirstRow = false;
for ( const QgsLayerMetadata::SpatialExtent &spatialExtent : spatialExtents )
QString myMetadata = QStringLiteral( "<table class=\"list-view\">\n" );
if ( showSpatialExtent )
{
if ( notFirstRow )
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + QObject::tr( "CRS" ) + QStringLiteral( "</td><td>" );
if ( mMetadata.crs().isValid() )
{
myMetadata += QLatin1String( "<br />\n" );
myMetadata += mMetadata.crs().authid() + QStringLiteral( " - " );
myMetadata += mMetadata.crs().description() + QStringLiteral( " - " );
if ( mMetadata.crs().isGeographic() )
myMetadata += QObject::tr( "Geographic" );
else
myMetadata += QObject::tr( "Projected" );
}
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "CRS" ) + QStringLiteral( ": </strong>" ) + spatialExtent.extentCrs.authid() + QStringLiteral( " - " );
myMetadata += spatialExtent.extentCrs.description() + QStringLiteral( " - " );
if ( spatialExtent.extentCrs.isGeographic() )
myMetadata += QObject::tr( "Geographic" );
else
myMetadata += QObject::tr( "Projected" );
myMetadata += QStringLiteral( "<br />" );
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "X Minimum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.xMinimum() ) + QStringLiteral( "<br />" );
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Y Minimum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.yMinimum() ) + QStringLiteral( "<br />" );
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "X Maximum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.xMaximum() ) + QStringLiteral( "<br />" );
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Y Maximum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.yMaximum() ) + QStringLiteral( "<br />" );
if ( spatialExtent.bounds.zMinimum() || spatialExtent.bounds.zMaximum() )
myMetadata += QLatin1String( "</td></tr>\n" );

myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + QObject::tr( "Spatial Extent" ) + QStringLiteral( "</td><td>" );
const QList< QgsLayerMetadata::SpatialExtent > spatialExtents = extent.spatialExtents();
for ( const QgsLayerMetadata::SpatialExtent &spatialExtent : spatialExtents )
{
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Z Minimum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.zMinimum() ) + QStringLiteral( "<br />" );
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Z Maximum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.zMaximum() );
if ( notFirstRow )
{
myMetadata += QLatin1String( "<br />\n" );
}
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "CRS" ) + QStringLiteral( ": </strong>" ) + spatialExtent.extentCrs.authid() + QStringLiteral( " - " );
myMetadata += spatialExtent.extentCrs.description() + QStringLiteral( " - " );
if ( spatialExtent.extentCrs.isGeographic() )
myMetadata += QObject::tr( "Geographic" );
else
myMetadata += QObject::tr( "Projected" );
myMetadata += QStringLiteral( "<br />" );
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "X Minimum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.xMinimum() ) + QStringLiteral( "<br />" );
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Y Minimum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.yMinimum() ) + QStringLiteral( "<br />" );
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "X Maximum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.xMaximum() ) + QStringLiteral( "<br />" );
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Y Maximum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.yMaximum() ) + QStringLiteral( "<br />" );
if ( spatialExtent.bounds.zMinimum() || spatialExtent.bounds.zMaximum() )
{
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Z Minimum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.zMinimum() ) + QStringLiteral( "<br />" );
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Z Maximum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.zMaximum() );
}
notFirstRow = true;
}
notFirstRow = true;
myMetadata += QLatin1String( "</td></tr>\n" );
}
myMetadata += QLatin1String( "</td></tr>\n" );
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + QObject::tr( "Temporal Extent" ) + QStringLiteral( "</td><td>" );
const QList< QgsDateTimeRange > temporalExtents = extent.temporalExtents();
notFirstRow = false;
@@ -50,10 +50,11 @@ class CORE_EXPORT QgsLayerMetadataFormatter
QString contactsSectionHtml() const;

/**
* Formats the "Extents" section according to a \a metadata object.
* Formats the "Extents" section according to a \a metadata object (extent and temporal).
* This will return a HTML table.
* \param showSpatialExtent flag if the spatial extent needs to be displayed. Default to true.
*/
QString extentSectionHtml() const;
QString extentSectionHtml( const bool showSpatialExtent = true ) const;

/**
* Formats the "Identification" section according to a \a metadata object.
@@ -4282,7 +4282,7 @@ QString QgsVectorLayer::htmlMetadata() const

// extent section
myMetadata += QStringLiteral( "<h1>" ) + tr( "Extent" ) + QStringLiteral( "</h1>\n<hr>\n" );
myMetadata += htmlFormatter.extentSectionHtml( );
myMetadata += htmlFormatter.extentSectionHtml( isSpatial() );
myMetadata += QLatin1String( "<br><br>\n" );

// Start the Access section

0 comments on commit c65fe0e

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