diff --git a/python/core/auto_additions/qgis.py b/python/core/auto_additions/qgis.py index ec461e6dc58..dee775bce5a 100644 --- a/python/core/auto_additions/qgis.py +++ b/python/core/auto_additions/qgis.py @@ -640,3 +640,8 @@ Qgis.FileOperationFlag.IncludeStyleFile.__doc__ = "Indicates that any associated Qgis.FileOperationFlag.__doc__ = 'File operation flags.\n\n.. versionadded:: 3.22\n\n' + '* ``IncludeMetadataFile``: ' + Qgis.FileOperationFlag.IncludeMetadataFile.__doc__ + '\n' + '* ``IncludeStyleFile``: ' + Qgis.FileOperationFlag.IncludeStyleFile.__doc__ # -- Qgis.FileOperationFlag.baseClass = Qgis +# monkey patching scoped based enum +Qgis.MapLayerProperty.UsersCannotToggleEditing.__doc__ = "Indicates that users are not allowed to toggle editing for this layer. Note that this does not imply that the layer is non-editable (see isEditable(), supportsEditing() ), rather that the editable status of the layer cannot be changed by users manually. Since QGIS 3.22." +Qgis.MapLayerProperty.__doc__ = 'Generic map layer properties.\n\n.. versionadded:: 3.22\n\n' + '* ``UsersCannotToggleEditing``: ' + Qgis.MapLayerProperty.UsersCannotToggleEditing.__doc__ +# -- +Qgis.MapLayerProperty.baseClass = Qgis diff --git a/python/core/auto_generated/annotations/qgsannotationlayer.sip.in b/python/core/auto_generated/annotations/qgsannotationlayer.sip.in index 050a7257c74..d4cf95ac7df 100644 --- a/python/core/auto_generated/annotations/qgsannotationlayer.sip.in +++ b/python/core/auto_generated/annotations/qgsannotationlayer.sip.in @@ -93,6 +93,8 @@ This map contains references to items owned by the layer, and ownership of these with the layer. %End + virtual Qgis::MapLayerProperties properties() const; + virtual QgsAnnotationLayer *clone() const /Factory/; virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) /Factory/; diff --git a/python/core/auto_generated/qgis.sip.in b/python/core/auto_generated/qgis.sip.in index 3e6f66165c0..f04f53f038d 100644 --- a/python/core/auto_generated/qgis.sip.in +++ b/python/core/auto_generated/qgis.sip.in @@ -452,6 +452,13 @@ The development version typedef QFlags FileOperationFlags; + enum class MapLayerProperty + { + UsersCannotToggleEditing, + }; + typedef QFlags MapLayerProperties; + + static const double DEFAULT_SEARCH_RADIUS_MM; static const float DEFAULT_MAPTOPIXEL_THRESHOLD; diff --git a/python/core/auto_generated/qgsmaplayer.sip.in b/python/core/auto_generated/qgsmaplayer.sip.in index 1b36dc8ceb4..260a1451ad1 100644 --- a/python/core/auto_generated/qgsmaplayer.sip.in +++ b/python/core/auto_generated/qgsmaplayer.sip.in @@ -140,6 +140,8 @@ Returns the flags for this layer. For instance, even if the Removable flag is not set, the layer can still be removed with the API but the action will not be listed in the legend menu. +.. seealso:: :py:func:`properties` + .. versionadded:: 3.4 %End @@ -153,7 +155,22 @@ Returns the flags for this layer. For instance, even if the Removable flag is not set, the layer can still be removed with the API but the action will not be listed in the legend menu. +.. seealso:: :py:func:`properties` + .. versionadded:: 3.4 +%End + + virtual Qgis::MapLayerProperties properties() const; +%Docstring +Returns the map layer properties of this layer. + +.. note:: + + :py:func:`~QgsMapLayer.properties` differ from :py:func:`~QgsMapLayer.flags` in that :py:func:`~QgsMapLayer.flags` are user settable, and reflect options that + users can enable for map layers. In contrast :py:func:`~QgsMapLayer.properties` are reflections of inherent capabilities + for the layer, which cannot be directly changed by users. + +.. versionadded:: 3.22 %End static QString extensionPropertyType( PropertyType type ); diff --git a/src/core/annotations/qgsannotationlayer.cpp b/src/core/annotations/qgsannotationlayer.cpp index 1d72a559c92..1a68ca658af 100644 --- a/src/core/annotations/qgsannotationlayer.cpp +++ b/src/core/annotations/qgsannotationlayer.cpp @@ -81,6 +81,12 @@ bool QgsAnnotationLayer::isEmpty() const return mItems.empty(); } +Qgis::MapLayerProperties QgsAnnotationLayer::properties() const +{ + // annotation layers are always editable + return Qgis::MapLayerProperty::UsersCannotToggleEditing; +} + QgsAnnotationLayer *QgsAnnotationLayer::clone() const { const QgsAnnotationLayer::LayerOptions options( mTransformContext ); diff --git a/src/core/annotations/qgsannotationlayer.h b/src/core/annotations/qgsannotationlayer.h index 44a245c46e8..802e9c908dc 100644 --- a/src/core/annotations/qgsannotationlayer.h +++ b/src/core/annotations/qgsannotationlayer.h @@ -117,6 +117,7 @@ class CORE_EXPORT QgsAnnotationLayer : public QgsMapLayer */ QMap items() const { return mItems; } + Qgis::MapLayerProperties properties() const override; QgsAnnotationLayer *clone() const override SIP_FACTORY; QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY; QgsRectangle extent() const override; diff --git a/src/core/qgis.h b/src/core/qgis.h index 8752b4c1ade..f60c2e70483 100644 --- a/src/core/qgis.h +++ b/src/core/qgis.h @@ -706,6 +706,18 @@ class CORE_EXPORT Qgis Q_DECLARE_FLAGS( FileOperationFlags, FileOperationFlag ) Q_ENUM( FileOperationFlag ) + /** + * Generic map layer properties. + * + * \since QGIS 3.22 + */ + enum class MapLayerProperty : int + { + UsersCannotToggleEditing = 1 << 0, //!< Indicates that users are not allowed to toggle editing for this layer. Note that this does not imply that the layer is non-editable (see isEditable(), supportsEditing() ), rather that the editable status of the layer cannot be changed by users manually. Since QGIS 3.22. + }; + Q_DECLARE_FLAGS( MapLayerProperties, MapLayerProperty ) + Q_ENUM( MapLayerProperty ) + /** * Identify search radius in mm * \since QGIS 2.3 diff --git a/src/core/qgsmaplayer.cpp b/src/core/qgsmaplayer.cpp index c53ebd67d19..46f3b4b45ca 100644 --- a/src/core/qgsmaplayer.cpp +++ b/src/core/qgsmaplayer.cpp @@ -155,6 +155,11 @@ void QgsMapLayer::setFlags( QgsMapLayer::LayerFlags flags ) emit flagsChanged(); } +Qgis::MapLayerProperties QgsMapLayer::properties() const +{ + return Qgis::MapLayerProperties(); +} + QString QgsMapLayer::id() const { return mID; diff --git a/src/core/qgsmaplayer.h b/src/core/qgsmaplayer.h index 96816e8efea..65820769c11 100644 --- a/src/core/qgsmaplayer.h +++ b/src/core/qgsmaplayer.h @@ -210,6 +210,9 @@ class CORE_EXPORT QgsMapLayer : public QObject * \note Flags are options specified by the user used for the UI but are not preventing any API call. * For instance, even if the Removable flag is not set, the layer can still be removed with the API * but the action will not be listed in the legend menu. + * + * \see properties() + * * \since QGIS 3.4 */ QgsMapLayer::LayerFlags flags() const; @@ -219,10 +222,24 @@ class CORE_EXPORT QgsMapLayer : public QObject * \note Flags are options specified by the user used for the UI but are not preventing any API call. * For instance, even if the Removable flag is not set, the layer can still be removed with the API * but the action will not be listed in the legend menu. + * + * \see properties() + * * \since QGIS 3.4 */ void setFlags( QgsMapLayer::LayerFlags flags ); + /** + * Returns the map layer properties of this layer. + * + * \note properties() differ from flags() in that flags() are user settable, and reflect options that + * users can enable for map layers. In contrast properties() are reflections of inherent capabilities + * for the layer, which cannot be directly changed by users. + * + * \since QGIS 3.22 + */ + virtual Qgis::MapLayerProperties properties() const; + /** * Returns the extension of a Property. * \returns The extension