Skip to content

Commit

Permalink
Merge pull request #6390 from nyalldawson/provider_metadata
Browse files Browse the repository at this point in the history
Support reading layer metadata from data provider
  • Loading branch information
nyalldawson committed Feb 20, 2018
2 parents 2571de3 + 1da2da2 commit e3fbb4c
Show file tree
Hide file tree
Showing 23 changed files with 492 additions and 22 deletions.
2 changes: 2 additions & 0 deletions python/core/geometry/qgsbox3d.sip.in
Expand Up @@ -223,6 +223,8 @@ will be performed on the x/y extent of the box only.
Converts the box to a 2D rectangle.
%End

bool operator==( const QgsBox3d &other ) const;

};

/************************************************************************
Expand Down
15 changes: 15 additions & 0 deletions python/core/metadata/qgslayermetadata.sip.in
Expand Up @@ -50,6 +50,8 @@ using QgsNativeMetadataValidator.
QgsCoordinateReferenceSystem extentCrs;

QgsBox3d bounds;

bool operator==( const QgsLayerMetadata::SpatialExtent &other ) const;
};

struct Extent
Expand Down Expand Up @@ -87,6 +89,8 @@ Sets the temporal ``extents`` of the resource.
.. seealso:: :py:func:`temporalExtents`
%End

bool operator==( const QgsLayerMetadata::Extent &other ) const;


};

Expand All @@ -101,6 +105,9 @@ Constructor for Constraint.
QString type;

QString constraint;

bool operator==( const QgsLayerMetadata::Constraint &other ) const;

};

typedef QList< QgsLayerMetadata::Constraint > ConstraintList;
Expand All @@ -125,6 +132,8 @@ Constructor for Address.
QString postalCode;

QString country;

bool operator==( const QgsLayerMetadata::Address &other ) const;
};

struct Contact
Expand All @@ -150,6 +159,8 @@ Constructor for Contact.
QString email;

QString role;

bool operator==( const QgsLayerMetadata::Contact &other ) const;
};

typedef QList< QgsLayerMetadata::Contact > ContactList;
Expand All @@ -176,6 +187,8 @@ Constructor for Link.
QString mimeType;

QString size;

bool operator==( const QgsLayerMetadata::Link &other ) const;
};

typedef QList< QgsLayerMetadata::Link > LinkList;
Expand Down Expand Up @@ -618,6 +631,8 @@ Stores state in Dom node
:return: true if successful
%End

bool operator==( const QgsLayerMetadata &metadataOther ) const;

};


Expand Down
23 changes: 23 additions & 0 deletions python/core/qgsdataprovider.sip.in
Expand Up @@ -362,6 +362,29 @@ The default implementation does nothing.
%End


virtual QgsLayerMetadata layerMetadata() const;
%Docstring
Returns layer metadata collected from the provider's source.

Individual data providers must implement this method if they support collecting metadata.

.. seealso:: :py:func:`writeLayerMetadata`

.. versionadded:: 3.0
%End

virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata );
%Docstring
Writes layer ``metadata`` to the underlying provider source. Support depends
on individual provider capabilities.

Returns true if metadata was successfully written to the data provider.

.. seealso:: :py:func:`layerMetadata`

.. versionadded:: 3.0
%End

signals:

void fullExtentCalculated();
Expand Down
2 changes: 2 additions & 0 deletions python/core/qgsrange.sip.in
Expand Up @@ -243,6 +243,8 @@ Returns true if this range contains a specified ``element``.
Returns true if this range overlaps another range.
%End

bool operator==( const QgsTemporalRange<T> &other ) const;

};


Expand Down
2 changes: 2 additions & 0 deletions python/core/qgsvectordataprovider.sip.in
Expand Up @@ -48,6 +48,8 @@ of feature and attribute information from a spatial datasource.
ChangeFeatures,
RenameAttributes,
FastTruncate,
ReadLayerMetadata,
WriteLayerMetadata,
};

typedef QFlags<QgsVectorDataProvider::Capability> Capabilities;
Expand Down
21 changes: 21 additions & 0 deletions python/core/raster/qgsrasterdataprovider.sip.in
Expand Up @@ -69,13 +69,31 @@ Base class for raster data providers.
#include "qgsrasterdataprovider.h"
%End
public:

enum ProviderCapability
{
NoProviderCapabilities,
ReadLayerMetadata,
WriteLayerMetadata,
};

typedef QFlags<QgsRasterDataProvider::ProviderCapability> ProviderCapabilities;


QgsRasterDataProvider();

QgsRasterDataProvider( const QString &uri );

virtual QgsRasterInterface *clone() const = 0;


virtual QgsRasterDataProvider::ProviderCapabilities providerCapabilities() const;
%Docstring
Returns flags containing the supported capabilities of the data provider.

.. versionadded:: 3.0
%End

virtual bool setInput( QgsRasterInterface *input );
%Docstring
It makes no sense to set input on provider */
Expand Down Expand Up @@ -425,6 +443,9 @@ Copy member variables from other raster data provider. Useful for implementation

};

QFlags<QgsRasterDataProvider::ProviderCapability> operator|(QgsRasterDataProvider::ProviderCapability f1, QFlags<QgsRasterDataProvider::ProviderCapability> f2);



/************************************************************************
* This file has been generated automatically from *
Expand Down
35 changes: 30 additions & 5 deletions python/gui/qgsmetadatawidget.sip.in
Expand Up @@ -26,16 +26,46 @@ class QgsMetadataWidget : QWidget
QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer = 0 );
%Docstring
Constructor for the wizard.

If ``layer`` is set, then this constructor automatically sets the widget's metadata() to match
the layer's metadata..

.. seealso:: :py:func:`setMetadata`
%End

void setMetadata( const QgsLayerMetadata &metadata );
%Docstring
Sets the ``metadata`` to display in the widget.

This method can be called after constructing a QgsMetadataWidget in order
to set the displayed metadata to custom, non-layer based metadata.

.. seealso:: :py:func:`metadata`
%End

QgsLayerMetadata metadata();
%Docstring
Returns a QgsLayerMetadata object representing the current state of the widget.

.. seealso:: :py:func:`saveMetadata`
%End

void saveMetadata( QgsLayerMetadata &layerMetadata );
%Docstring
Save all fields in a QgsLayerMetadata object.

.. seealso:: :py:func:`metadata`

.. seealso:: :py:func:`acceptMetadata`

.. seealso:: :py:func:`checkMetadata`
%End

bool checkMetadata();
%Docstring
Check if values in the wizard are correct.

.. seealso:: :py:func:`saveMetadata`
%End

void crsChanged();
Expand All @@ -46,11 +76,6 @@ If the CRS is updated.
void acceptMetadata();
%Docstring
Saves the metadata to the layer.
%End

virtual void setMetadata( const QgsLayerMetadata &metadata );
%Docstring
Sets the layer's ``metadata`` store.
%End

static QMap<QString, QString> parseLanguages();
Expand Down
7 changes: 7 additions & 0 deletions src/core/geometry/qgsbox3d.cpp
Expand Up @@ -117,3 +117,10 @@ bool QgsBox3d::contains( const QgsPoint &p ) const
else
return true;
}

bool QgsBox3d::operator==( const QgsBox3d &other ) const
{
return mBounds2d == other.mBounds2d &&
qgsDoubleNear( mZmin, other.mZmin ) &&
qgsDoubleNear( mZmax, other.mZmax );
}
2 changes: 2 additions & 0 deletions src/core/geometry/qgsbox3d.h
Expand Up @@ -202,6 +202,8 @@ class CORE_EXPORT QgsBox3d
*/
QgsRectangle toRectangle() const { return mBounds2d; }

bool operator==( const QgsBox3d &other ) const;

private:

QgsRectangle mBounds2d;
Expand Down
70 changes: 70 additions & 0 deletions src/core/metadata/qgslayermetadata.cpp
Expand Up @@ -767,3 +767,73 @@ void QgsLayerMetadata::Extent::setTemporalExtents( const QList<QgsDateTimeRange>
{
mTemporalExtents = temporalExtents;
}

bool QgsLayerMetadata::Extent::operator==( const QgsLayerMetadata::Extent &other ) const
{
return mSpatialExtents == other.mSpatialExtents && mTemporalExtents == other.mTemporalExtents;
}

bool QgsLayerMetadata::operator==( const QgsLayerMetadata &metadataOther ) const
{
return ( ( mIdentifier == metadataOther.mIdentifier ) &&
( mParentIdentifier == metadataOther.mParentIdentifier ) &&
( mLanguage == metadataOther.mLanguage ) &&
( mType == metadataOther.mType ) &&
( mTitle == metadataOther.mTitle ) &&
( mAbstract == metadataOther.mAbstract ) &&
( mFees == metadataOther.mFees ) &&
( mConstraints == metadataOther.mConstraints ) &&
( mRights == metadataOther.mRights ) &&
( mLicenses == metadataOther.mLicenses ) &&
( mHistory == metadataOther.mHistory ) &&
( mEncoding == metadataOther.mEncoding ) &&
( mCrs == metadataOther.mCrs ) &&
( mExtent == metadataOther.mExtent ) &&
( mKeywords == metadataOther.mKeywords ) &&
( mContacts == metadataOther.mContacts ) &&
( mLinks == metadataOther.mLinks ) );
}

bool QgsLayerMetadata::SpatialExtent::operator==( const QgsLayerMetadata::SpatialExtent &other ) const
{
return extentCrs == other.extentCrs &&
bounds == other.bounds;
}

bool QgsLayerMetadata::Constraint::operator==( const QgsLayerMetadata::Constraint &other ) const
{
return type == other.type && constraint == other.constraint;
}

bool QgsLayerMetadata::Contact::operator==( const QgsLayerMetadata::Contact &other ) const
{
return name == other.name &&
organization == other.organization &&
position == other.position &&
addresses == other.addresses &&
voice == other.voice &&
fax == other.fax &&
email == other.email &&
role == other.role;
}

bool QgsLayerMetadata::Link::operator==( const QgsLayerMetadata::Link &other ) const
{
return name == other.name &&
type == other.type &&
description == other.description &&
url == other.url &&
format == other.format &&
mimeType == other.mimeType &&
size == other.size;
}

bool QgsLayerMetadata::Address::operator==( const QgsLayerMetadata::Address &other ) const
{
return type == other.type &&
address == other.address &&
city == other.city &&
administrativeArea == other.administrativeArea &&
postalCode == other.postalCode &&
country == other.country;
}
15 changes: 15 additions & 0 deletions src/core/metadata/qgslayermetadata.h
Expand Up @@ -84,6 +84,8 @@ class CORE_EXPORT QgsLayerMetadata
* \see extentCrs
*/
QgsBox3d bounds;

bool operator==( const QgsLayerMetadata::SpatialExtent &other ) const;
};

/**
Expand Down Expand Up @@ -120,6 +122,8 @@ class CORE_EXPORT QgsLayerMetadata
*/
void setTemporalExtents( const QList< QgsDateTimeRange > &extents );

bool operator==( const QgsLayerMetadata::Extent &other ) const;

#ifndef SIP_RUN
private:

Expand Down Expand Up @@ -154,6 +158,9 @@ class CORE_EXPORT QgsLayerMetadata
* Free-form constraint string.
*/
QString constraint;

bool operator==( const QgsLayerMetadata::Constraint &other ) const;

};

/**
Expand Down Expand Up @@ -209,6 +216,8 @@ class CORE_EXPORT QgsLayerMetadata
* Free-form country string.
*/
QString country;

bool operator==( const QgsLayerMetadata::Address &other ) const;
};

/**
Expand Down Expand Up @@ -266,6 +275,8 @@ class CORE_EXPORT QgsLayerMetadata
* E.g. 'custodian', 'owner', 'distributor', etc.
*/
QString role;

bool operator==( const QgsLayerMetadata::Contact &other ) const;
};

/**
Expand Down Expand Up @@ -324,6 +335,8 @@ class CORE_EXPORT QgsLayerMetadata
* Estimated size (in bytes) of the online resource response.
*/
QString size;

bool operator==( const QgsLayerMetadata::Link &other ) const;
};

/**
Expand Down Expand Up @@ -726,6 +739,8 @@ class CORE_EXPORT QgsLayerMetadata
*/
bool writeMetadataXml( QDomElement &metadataElement, QDomDocument &document ) const;

bool operator==( const QgsLayerMetadata &metadataOther ) const;

private:

/*
Expand Down

0 comments on commit e3fbb4c

Please sign in to comment.