Skip to content

Commit c65fe0e

Browse files
Gustrynyalldawson
authored andcommittedSep 6, 2018
do not display metadata related to spatial extent if the layer is not spatial
1 parent da39078 commit c65fe0e

File tree

4 files changed

+46
-40
lines changed

4 files changed

+46
-40
lines changed
 

‎python/core/auto_generated/metadata/qgslayermetadataformatter.sip.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ Formats the "Contacts" section according to a ``metadata`` object.
3939
This will return a HTML table.
4040
%End
4141

42-
QString extentSectionHtml() const;
42+
QString extentSectionHtml( const bool showSpatialExtent = true ) const;
4343
%Docstring
44-
Formats the "Extents" section according to a ``metadata`` object.
44+
Formats the "Extents" section according to a ``metadata`` object (extent and temporal).
4545
This will return a HTML table.
46+
47+
:param showSpatialExtent: flag if the spatial extent needs to be displayed. Default to true.
4648
%End
4749

4850
QString identificationSectionHtml() const;

‎src/core/metadata/qgslayermetadataformatter.cpp

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -107,50 +107,53 @@ QString QgsLayerMetadataFormatter::contactsSectionHtml() const
107107
return myMetadata;
108108
}
109109

110-
QString QgsLayerMetadataFormatter::extentSectionHtml() const
110+
QString QgsLayerMetadataFormatter::extentSectionHtml( const bool showSpatialExtent ) const
111111
{
112-
QString myMetadata = QStringLiteral( "<table class=\"list-view\">\n" );
113-
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + QObject::tr( "CRS" ) + QStringLiteral( "</td><td>" );
114-
if ( mMetadata.crs().isValid() )
115-
{
116-
myMetadata += mMetadata.crs().authid() + QStringLiteral( " - " );
117-
myMetadata += mMetadata.crs().description() + QStringLiteral( " - " );
118-
if ( mMetadata.crs().isGeographic() )
119-
myMetadata += QObject::tr( "Geographic" );
120-
else
121-
myMetadata += QObject::tr( "Projected" );
122-
}
123-
myMetadata += QLatin1String( "</td></tr>\n" );
124-
125112
const QgsLayerMetadata::Extent extent = mMetadata.extent();
126-
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + QObject::tr( "Spatial Extent" ) + QStringLiteral( "</td><td>" );
127-
const QList< QgsLayerMetadata::SpatialExtent > spatialExtents = extent.spatialExtents();
128113
bool notFirstRow = false;
129-
for ( const QgsLayerMetadata::SpatialExtent &spatialExtent : spatialExtents )
114+
QString myMetadata = QStringLiteral( "<table class=\"list-view\">\n" );
115+
if ( showSpatialExtent )
130116
{
131-
if ( notFirstRow )
117+
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + QObject::tr( "CRS" ) + QStringLiteral( "</td><td>" );
118+
if ( mMetadata.crs().isValid() )
132119
{
133-
myMetadata += QLatin1String( "<br />\n" );
120+
myMetadata += mMetadata.crs().authid() + QStringLiteral( " - " );
121+
myMetadata += mMetadata.crs().description() + QStringLiteral( " - " );
122+
if ( mMetadata.crs().isGeographic() )
123+
myMetadata += QObject::tr( "Geographic" );
124+
else
125+
myMetadata += QObject::tr( "Projected" );
134126
}
135-
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "CRS" ) + QStringLiteral( ": </strong>" ) + spatialExtent.extentCrs.authid() + QStringLiteral( " - " );
136-
myMetadata += spatialExtent.extentCrs.description() + QStringLiteral( " - " );
137-
if ( spatialExtent.extentCrs.isGeographic() )
138-
myMetadata += QObject::tr( "Geographic" );
139-
else
140-
myMetadata += QObject::tr( "Projected" );
141-
myMetadata += QStringLiteral( "<br />" );
142-
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "X Minimum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.xMinimum() ) + QStringLiteral( "<br />" );
143-
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Y Minimum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.yMinimum() ) + QStringLiteral( "<br />" );
144-
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "X Maximum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.xMaximum() ) + QStringLiteral( "<br />" );
145-
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Y Maximum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.yMaximum() ) + QStringLiteral( "<br />" );
146-
if ( spatialExtent.bounds.zMinimum() || spatialExtent.bounds.zMaximum() )
127+
myMetadata += QLatin1String( "</td></tr>\n" );
128+
129+
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + QObject::tr( "Spatial Extent" ) + QStringLiteral( "</td><td>" );
130+
const QList< QgsLayerMetadata::SpatialExtent > spatialExtents = extent.spatialExtents();
131+
for ( const QgsLayerMetadata::SpatialExtent &spatialExtent : spatialExtents )
147132
{
148-
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Z Minimum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.zMinimum() ) + QStringLiteral( "<br />" );
149-
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Z Maximum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.zMaximum() );
133+
if ( notFirstRow )
134+
{
135+
myMetadata += QLatin1String( "<br />\n" );
136+
}
137+
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "CRS" ) + QStringLiteral( ": </strong>" ) + spatialExtent.extentCrs.authid() + QStringLiteral( " - " );
138+
myMetadata += spatialExtent.extentCrs.description() + QStringLiteral( " - " );
139+
if ( spatialExtent.extentCrs.isGeographic() )
140+
myMetadata += QObject::tr( "Geographic" );
141+
else
142+
myMetadata += QObject::tr( "Projected" );
143+
myMetadata += QStringLiteral( "<br />" );
144+
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "X Minimum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.xMinimum() ) + QStringLiteral( "<br />" );
145+
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Y Minimum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.yMinimum() ) + QStringLiteral( "<br />" );
146+
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "X Maximum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.xMaximum() ) + QStringLiteral( "<br />" );
147+
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Y Maximum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.yMaximum() ) + QStringLiteral( "<br />" );
148+
if ( spatialExtent.bounds.zMinimum() || spatialExtent.bounds.zMaximum() )
149+
{
150+
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Z Minimum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.zMinimum() ) + QStringLiteral( "<br />" );
151+
myMetadata += QStringLiteral( "<strong>" ) + QObject::tr( "Z Maximum" ) + QStringLiteral( ": </strong>" ) + qgsDoubleToString( spatialExtent.bounds.zMaximum() );
152+
}
153+
notFirstRow = true;
150154
}
151-
notFirstRow = true;
155+
myMetadata += QLatin1String( "</td></tr>\n" );
152156
}
153-
myMetadata += QLatin1String( "</td></tr>\n" );
154157
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + QObject::tr( "Temporal Extent" ) + QStringLiteral( "</td><td>" );
155158
const QList< QgsDateTimeRange > temporalExtents = extent.temporalExtents();
156159
notFirstRow = false;

‎src/core/metadata/qgslayermetadataformatter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ class CORE_EXPORT QgsLayerMetadataFormatter
5050
QString contactsSectionHtml() const;
5151

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

5859
/**
5960
* Formats the "Identification" section according to a \a metadata object.

‎src/core/qgsvectorlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4282,7 +4282,7 @@ QString QgsVectorLayer::htmlMetadata() const
42824282

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

42884288
// Start the Access section

0 commit comments

Comments
 (0)
Please sign in to comment.