Skip to content

Commit 3a965e6

Browse files
committed
Attach layer metadata to QgsMapLayer
1 parent 269bfe7 commit 3a965e6

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

python/core/qgsmaplayer.sip

+25
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,23 @@ Return pointer to layer's undo stack
818818
.. seealso:: setAutoRefreshInterval()
819819
%End
820820

821+
virtual const QgsLayerMetadata &metadata() const;
822+
%Docstring
823+
Returns a reference to the layer's metadata store.
824+
.. versionadded:: 3.0
825+
\see setMetadata()
826+
\see metadataChanged()
827+
:rtype: QgsLayerMetadata
828+
%End
829+
830+
virtual void setMetadata( const QgsLayerMetadata &metadata );
831+
%Docstring
832+
Sets the layer's metadata store.
833+
.. versionadded:: 3.0
834+
\see metadata()
835+
\see metadataChanged()
836+
%End
837+
821838
virtual QString htmlMetadata() const;
822839
%Docstring
823840
Obtain a formatted HTML string containing assorted metadata for this layer.
@@ -988,6 +1005,14 @@ Signal emitted when the blend mode is changed, through QgsMapLayer.setBlendMode(
9881005
Emitted when the auto refresh interval changes.
9891006
.. seealso:: setAutoRefreshInterval()
9901007
.. versionadded:: 3.0
1008+
%End
1009+
1010+
void metadataChanged();
1011+
%Docstring
1012+
Emitted when the layer's metadata is changed.
1013+
\see setMetadata()
1014+
\see metadata()
1015+
.. versionadded:: 3.0
9911016
%End
9921017

9931018
protected:

src/core/metadata/qgslayermetadata.h

-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ class CORE_EXPORT QgsLayerMetadata
8080
QStringList mRights;
8181
QString mEncoding;
8282

83-
84-
8583
};
8684

8785
#endif // QGSLAYERMETADATA_H

src/core/qgsmaplayer.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,12 @@ void QgsMapLayer::triggerRepaint( bool deferredUpdate )
16211621
emit repaintRequested( deferredUpdate );
16221622
}
16231623

1624+
void QgsMapLayer::setMetadata( const QgsLayerMetadata &metadata )
1625+
{
1626+
mMetadata = metadata;
1627+
emit metadataChanged();
1628+
}
1629+
16241630
QString QgsMapLayer::htmlMetadata() const
16251631
{
16261632
return QString();

src/core/qgsmaplayer.h

+28
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "qgscoordinatereferencesystem.h"
3535
#include "qgsrendercontext.h"
3636
#include "qgsmaplayerdependency.h"
37+
#include "metadata/qgslayermetadata.h"
3738

3839
class QgsDataProvider;
3940
class QgsMapLayerLegend;
@@ -56,6 +57,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
5657

5758
Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
5859
Q_PROPERTY( int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
60+
Q_PROPERTY( QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
5961

6062
#ifdef SIP_RUN
6163
SIP_CONVERT_TO_SUBCLASS_CODE
@@ -732,6 +734,22 @@ class CORE_EXPORT QgsMapLayer : public QObject
732734
*/
733735
void setAutoRefreshEnabled( bool enabled );
734736

737+
/**
738+
* Returns a reference to the layer's metadata store.
739+
* \since QGIS 3.0
740+
* \see setMetadata()
741+
* \see metadataChanged()
742+
*/
743+
virtual const QgsLayerMetadata &metadata() const { return mMetadata; }
744+
745+
/**
746+
* Sets the layer's \a metadata store.
747+
* \since QGIS 3.0
748+
* \see metadata()
749+
* \see metadataChanged()
750+
*/
751+
virtual void setMetadata( const QgsLayerMetadata &metadata );
752+
735753
/**
736754
* Obtain a formatted HTML string containing assorted metadata for this layer.
737755
* \since QGIS 3.0
@@ -879,6 +897,14 @@ class CORE_EXPORT QgsMapLayer : public QObject
879897
*/
880898
void autoRefreshIntervalChanged( int interval );
881899

900+
/**
901+
* Emitted when the layer's metadata is changed.
902+
* \see setMetadata()
903+
* \see metadata()
904+
* \since QGIS 3.0
905+
*/
906+
void metadataChanged();
907+
882908
protected:
883909
//! Set the extent
884910
virtual void setExtent( const QgsRectangle &rect );
@@ -1019,6 +1045,8 @@ class CORE_EXPORT QgsMapLayer : public QObject
10191045
//! Timer for triggering automatic refreshes of the layer
10201046
QTimer mRefreshTimer;
10211047

1048+
QgsLayerMetadata mMetadata;
1049+
10221050
};
10231051

10241052
Q_DECLARE_METATYPE( QgsMapLayer * )

0 commit comments

Comments
 (0)