Skip to content
Permalink
Browse files
Add a new enum for inherent map layer properties, and add property
to annotation layers to reflect that while these are editable
users are not able to toggle edits on them (they are ALWAYS
editable!)

Note that we can't use the existing QgsMapLayer::LayerFlag enum here,
as that has a different meaning (flags which are set by users
at runtime)
  • Loading branch information
nyalldawson committed Aug 18, 2021
1 parent 3f7fc06 commit 3b2e640ceef284ac588086ad79620c3a53a61638
@@ -640,3 +640,8 @@
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
@@ -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/;
@@ -452,6 +452,13 @@ The development version
typedef QFlags<Qgis::FileOperationFlag> FileOperationFlags;


enum class MapLayerProperty
{
UsersCannotToggleEditing,
};
typedef QFlags<Qgis::MapLayerProperty> MapLayerProperties;


static const double DEFAULT_SEARCH_RADIUS_MM;

static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
@@ -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 );
@@ -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 );
@@ -117,6 +117,7 @@ class CORE_EXPORT QgsAnnotationLayer : public QgsMapLayer
*/
QMap<QString, QgsAnnotationItem *> 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;
@@ -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
@@ -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;
@@ -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

0 comments on commit 3b2e640

Please sign in to comment.