Skip to content

Commit

Permalink
Add a new enum for inherent map layer properties, and add property
Browse files Browse the repository at this point in the history
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 3b2e640
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/core/auto_additions/qgis.py
Expand Up @@ -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
Expand Up @@ -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/;
Expand Down
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions python/core/auto_generated/qgsmaplayer.sip.in
Expand Up @@ -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

Expand All @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions src/core/annotations/qgsannotationlayer.cpp
Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/core/annotations/qgsannotationlayer.h
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/core/qgis.h
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions src/core/qgsmaplayer.h
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 3b2e640

Please sign in to comment.