23#include <QRegularExpression>
26#include "moc_qgslayermetadata.cpp"
28using namespace Qt::StringLiterals;
47 mConstraints << constraint;
107 layer->
setCustomProperty( u
"metadata/extent"_s, QVariant::fromValue( mExtent ) );
115 layer->
setCustomProperty( u
"metadata/constraints"_s, QVariant::fromValue( mConstraints ) );
130 mRights = layer->
customProperty( u
"metadata/rights"_s ).toStringList();
131 mLicenses = layer->
customProperty( u
"metadata/licenses"_s ).toStringList();
133 mEncoding = layer->
customProperty( u
"metadata/encoding"_s ).toString();
134 const QString crsAuthId = layer->
customProperty( u
"metadata/crs"_s ).toString();
151 mnl = metadataElement.namedItem( u
"fees"_s );
152 mFees = mnl.toElement().text();
155 const QDomNodeList constraintsList = metadataElement.elementsByTagName( u
"constraints"_s );
156 mConstraints.clear();
157 for (
int i = 0; i < constraintsList.size(); i++ )
159 mnl = constraintsList.at( i );
160 mne = mnl.toElement();
165 const QDomNodeList rightsNodeList = metadataElement.elementsByTagName( u
"rights"_s );
166 QStringList rightsList;
167 for (
int i = 0; i < rightsNodeList.size(); i++ )
169 mnl = rightsNodeList.at( i );
170 mne = mnl.toElement();
172 rightsList.append( right );
177 const QDomNodeList licensesNodeList = metadataElement.elementsByTagName( u
"license"_s );
178 QStringList licensesList;
179 for (
int i = 0; i < licensesNodeList.size(); i++ )
181 mnl = licensesNodeList.at( i );
182 mne = mnl.toElement();
183 licensesList.append( mne.text() );
188 mnl = metadataElement.namedItem( u
"encoding"_s );
189 mEncoding = mnl.toElement().text();
192 mnl = metadataElement.namedItem( u
"crs"_s );
193 if ( !mCrs.readXml( mnl ) )
197 mnl = metadataElement.namedItem( u
"extent"_s );
201 const QDomNodeList spatialList = mnl.toElement().elementsByTagName( u
"spatial"_s );
202 QList< QgsLayerMetadata::SpatialExtent > metadataSpatialExtents;
203 for (
int i = 0; i < spatialList.size(); i++ )
205 mnl = spatialList.at( i );
206 mne = mnl.toElement();
216 metadataSpatialExtents.append( se );
221 mnl = metadataElement.namedItem( u
"extent"_s );
222 const QDomNodeList temporalList = mnl.toElement().elementsByTagName( u
"temporal"_s );
223 QList<QgsDateTimeRange> metadataDates;
224 for (
int j = 0; j < temporalList.size(); j++ )
226 mnl = temporalList.at( j );
227 const QDomNodeList instantList = mnl.toElement().elementsByTagName( u
"instant"_s );
228 for (
int i = 0; i < instantList.size(); i++ )
230 mnl = instantList.at( i );
231 const QDateTime d = QDateTime::fromString( mnl.toElement().text(), Qt::ISODate );
233 metadataDates << date;
235 const QDomNodeList periodList = mnl.toElement().elementsByTagName( u
"period"_s );
236 for (
int i = 0; i < periodList.size(); i++ )
238 const QDomNode begin = periodList.at( i ).namedItem( u
"start"_s );
239 const QDomNode end = periodList.at( i ).namedItem( u
"end"_s );
240 const QDateTime beginDate = QDateTime::fromString( begin.toElement().text(), Qt::ISODate );
241 const QDateTime endDate = QDateTime::fromString( end.toElement().text(), Qt::ISODate );
243 metadataDates << date;
257 QDomElement
fees = document.createElement( u
"fees"_s );
258 const QDomText feesText = document.createTextNode( mFees );
259 fees.appendChild( feesText );
260 metadataElement.appendChild(
fees );
265 QDomElement constraintElement = document.createElement( u
"constraints"_s );
266 constraintElement.setAttribute( u
"type"_s, constraint.type );
267 const QDomText constraintText = document.createTextNode( constraint.constraint );
268 constraintElement.appendChild( constraintText );
269 metadataElement.appendChild( constraintElement );
273 for (
const QString &right : mRights )
275 QDomElement rightElement = document.createElement( u
"rights"_s );
276 const QDomText rightText = document.createTextNode( right );
277 rightElement.appendChild( rightText );
278 metadataElement.appendChild( rightElement );
282 for (
const QString &license : mLicenses )
284 QDomElement licenseElement = document.createElement( u
"license"_s );
285 const QDomText licenseText = document.createTextNode( license );
286 licenseElement.appendChild( licenseText );
287 metadataElement.appendChild( licenseElement );
291 QDomElement
encoding = document.createElement( u
"encoding"_s );
292 const QDomText encodingText = document.createTextNode( mEncoding );
293 encoding.appendChild( encodingText );
294 metadataElement.appendChild(
encoding );
297 QDomElement crsElement = document.createElement( u
"crs"_s );
298 mCrs.writeXml( crsElement, document );
299 metadataElement.appendChild( crsElement );
302 QDomElement extentElement = document.createElement( u
"extent"_s );
308 QDomElement spatialElement = document.createElement( u
"spatial"_s );
310 spatialElement.setAttribute( u
"dimensions"_s, u
"2"_s );
311 spatialElement.setAttribute( u
"crs"_s, spatialExtent.extentCrs.authid() );
312 spatialElement.setAttribute( u
"minx"_s,
qgsDoubleToString( spatialExtent.bounds.xMinimum() ) );
313 spatialElement.setAttribute( u
"miny"_s,
qgsDoubleToString( spatialExtent.bounds.yMinimum() ) );
314 spatialElement.setAttribute( u
"minz"_s,
qgsDoubleToString( spatialExtent.bounds.zMinimum() ) );
315 spatialElement.setAttribute( u
"maxx"_s,
qgsDoubleToString( spatialExtent.bounds.xMaximum() ) );
316 spatialElement.setAttribute( u
"maxy"_s,
qgsDoubleToString( spatialExtent.bounds.yMaximum() ) );
317 spatialElement.setAttribute( u
"maxz"_s,
qgsDoubleToString( spatialExtent.bounds.zMaximum() ) );
318 extentElement.appendChild( spatialElement );
325 QDomElement temporalElement = document.createElement( u
"temporal"_s );
326 if ( temporalExtent.isInstant() )
328 QDomElement instantElement = document.createElement( u
"instant"_s );
329 const QDomText instantText = document.createTextNode( temporalExtent.begin().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
330 instantElement.appendChild( instantText );
331 temporalElement.appendChild( instantElement );
335 QDomElement periodElement = document.createElement( u
"period"_s );
336 QDomElement startElement = document.createElement( u
"start"_s );
337 QDomElement endElement = document.createElement( u
"end"_s );
338 const QDomText startText = document.createTextNode( temporalExtent.begin().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
339 const QDomText endText = document.createTextNode( temporalExtent.end().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
340 startElement.appendChild( startText );
341 endElement.appendChild( endText );
342 periodElement.appendChild( startElement );
343 periodElement.appendChild( endElement );
344 temporalElement.appendChild( periodElement );
346 extentElement.appendChild( temporalElement );
349 metadataElement.appendChild( extentElement );
358 for (
const QString &right : std::as_const( mRights ) )
370 if ( !otherLayerMetadata->fees().isEmpty() )
371 mFees = otherLayerMetadata->fees();
373 if ( !otherLayerMetadata->constraints().isEmpty() )
374 mConstraints = otherLayerMetadata->constraints();
376 if ( !otherLayerMetadata->rights().isEmpty() )
377 mRights = otherLayerMetadata->rights();
379 if ( !otherLayerMetadata->licenses().isEmpty() )
380 mLicenses = otherLayerMetadata->licenses();
382 if ( !otherLayerMetadata->encoding().isEmpty() )
383 mEncoding = otherLayerMetadata->encoding();
385 if ( otherLayerMetadata->crs().isValid() )
386 mCrs = otherLayerMetadata->crs();
388 if ( !otherLayerMetadata->extent().spatialExtents().isEmpty() )
389 mExtent.setSpatialExtents( otherLayerMetadata->extent().spatialExtents() );
391 if ( !otherLayerMetadata->extent().temporalExtents().isEmpty() )
392 mExtent.setTemporalExtents( otherLayerMetadata->extent().temporalExtents() );
413 return mSpatialExtents;
423 return mTemporalExtents;
433 return mSpatialExtents == other.mSpatialExtents && mTemporalExtents == other.mTemporalExtents;
439 && mFees == other.mFees
440 && mConstraints == other.mConstraints
441 && mRights == other.mRights
442 && mLicenses == other.mLicenses
443 && mEncoding == other.mEncoding
444 && mCrs == other.mCrs
445 && mExtent == other.mExtent;
450 if ( searchString.trimmed().isEmpty() )
460 const QList<QStringList> keyVals {
keywords().values() };
461 for (
const QStringList &kws : std::as_const( keyVals ) )
463 for (
const QString &kw : std::as_const( kws ) )
465 if ( kw.contains( searchString, Qt::CaseSensitivity::CaseInsensitive ) )
473 for (
const QString &cat : std::as_const( constCat ) )
475 if ( cat.contains( searchString, Qt::CaseSensitivity::CaseInsensitive ) )
486 for (
const QRegularExpression &re : std::as_const( searchReList ) )
488 if ( re.match(
title() ).hasMatch() || re.match(
identifier() ).hasMatch() || re.match(
abstract() ).hasMatch() )
493 const QList<QStringList> keyVals {
keywords().values() };
494 for (
const QStringList &kws : std::as_const( keyVals ) )
496 for (
const QString &kw : std::as_const( kws ) )
498 if ( re.match( kw ).hasMatch() )
506 for (
const QString &cat : std::as_const( constCat ) )
508 if ( re.match( cat ).hasMatch() )
A 3-dimensional box composed of x, y, z coordinates.
void setZMinimum(double z)
Sets the minimum z value.
void setYMaximum(double y)
Sets the maximum y value.
void setZMaximum(double z)
Sets the maximum z value.
void setXMaximum(double x)
Sets the maximum x value.
void setYMinimum(double y)
Sets the minimum y value.
void setXMinimum(double x)
Sets the minimum x value.
Represents a coordinate reference system (CRS).
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
Base class for all map layer types.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
Translates a string using the Qt QTranslator mechanism.
A container for the context for various read/write operations on objects.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
Used for the collecting of strings from projects for translation and creation of ts files.
void registerTranslation(const QString &context, const QString &source)
Registers the source to be translated.
QList< QgsAbstractMetadataBase::Link > LinkList
A list of links.
QList< QgsAbstractMetadataBase::Contact > ContactList
A list of contacts.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.