Skip to content

Commit

Permalink
Attach layer metadata to QgsMapLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 3, 2017
1 parent 269bfe7 commit 3a965e6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
25 changes: 25 additions & 0 deletions python/core/qgsmaplayer.sip
Expand Up @@ -818,6 +818,23 @@ Return pointer to layer's undo stack
.. seealso:: setAutoRefreshInterval()
%End

virtual const QgsLayerMetadata &metadata() const;
%Docstring
Returns a reference to the layer's metadata store.
.. versionadded:: 3.0
\see setMetadata()
\see metadataChanged()
:rtype: QgsLayerMetadata
%End

virtual void setMetadata( const QgsLayerMetadata &metadata );
%Docstring
Sets the layer's metadata store.
.. versionadded:: 3.0
\see metadata()
\see metadataChanged()
%End

virtual QString htmlMetadata() const;
%Docstring
Obtain a formatted HTML string containing assorted metadata for this layer.
Expand Down Expand Up @@ -988,6 +1005,14 @@ Signal emitted when the blend mode is changed, through QgsMapLayer.setBlendMode(
Emitted when the auto refresh interval changes.
.. seealso:: setAutoRefreshInterval()
.. versionadded:: 3.0
%End

void metadataChanged();
%Docstring
Emitted when the layer's metadata is changed.
\see setMetadata()
\see metadata()
.. versionadded:: 3.0
%End

protected:
Expand Down
2 changes: 0 additions & 2 deletions src/core/metadata/qgslayermetadata.h
Expand Up @@ -80,8 +80,6 @@ class CORE_EXPORT QgsLayerMetadata
QStringList mRights;
QString mEncoding;



};

#endif // QGSLAYERMETADATA_H
6 changes: 6 additions & 0 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -1621,6 +1621,12 @@ void QgsMapLayer::triggerRepaint( bool deferredUpdate )
emit repaintRequested( deferredUpdate );
}

void QgsMapLayer::setMetadata( const QgsLayerMetadata &metadata )
{
mMetadata = metadata;
emit metadataChanged();
}

QString QgsMapLayer::htmlMetadata() const
{
return QString();
Expand Down
28 changes: 28 additions & 0 deletions src/core/qgsmaplayer.h
Expand Up @@ -34,6 +34,7 @@
#include "qgscoordinatereferencesystem.h"
#include "qgsrendercontext.h"
#include "qgsmaplayerdependency.h"
#include "metadata/qgslayermetadata.h"

class QgsDataProvider;
class QgsMapLayerLegend;
Expand All @@ -56,6 +57,7 @@ class CORE_EXPORT QgsMapLayer : public QObject

Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
Q_PROPERTY( int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
Q_PROPERTY( QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )

#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
Expand Down Expand Up @@ -732,6 +734,22 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
void setAutoRefreshEnabled( bool enabled );

/**
* Returns a reference to the layer's metadata store.
* \since QGIS 3.0
* \see setMetadata()
* \see metadataChanged()
*/
virtual const QgsLayerMetadata &metadata() const { return mMetadata; }

/**
* Sets the layer's \a metadata store.
* \since QGIS 3.0
* \see metadata()
* \see metadataChanged()
*/
virtual void setMetadata( const QgsLayerMetadata &metadata );

/**
* Obtain a formatted HTML string containing assorted metadata for this layer.
* \since QGIS 3.0
Expand Down Expand Up @@ -879,6 +897,14 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
void autoRefreshIntervalChanged( int interval );

/**
* Emitted when the layer's metadata is changed.
* \see setMetadata()
* \see metadata()
* \since QGIS 3.0
*/
void metadataChanged();

protected:
//! Set the extent
virtual void setExtent( const QgsRectangle &rect );
Expand Down Expand Up @@ -1019,6 +1045,8 @@ class CORE_EXPORT QgsMapLayer : public QObject
//! Timer for triggering automatic refreshes of the layer
QTimer mRefreshTimer;

QgsLayerMetadata mMetadata;

};

Q_DECLARE_METATYPE( QgsMapLayer * )
Expand Down

0 comments on commit 3a965e6

Please sign in to comment.