Skip to content

Commit

Permalink
Move enums from QgsVectorLayer to Qgis, promote to enum classes,
Browse files Browse the repository at this point in the history
and fix redundant QgsVectorLayer.VertexMarkerType enum
  • Loading branch information
nyalldawson committed Jul 19, 2021
1 parent cc17c90 commit 2724315
Show file tree
Hide file tree
Showing 30 changed files with 252 additions and 189 deletions.
11 changes: 11 additions & 0 deletions python/core/__init__.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ QgsMarkerLineSymbolLayer.FirstVertex = QgsTemplatedLineSymbolLayerBase.FirstVert
QgsMarkerLineSymbolLayer.CentralPoint = QgsTemplatedLineSymbolLayerBase.CentralPoint
QgsMarkerLineSymbolLayer.CurvePoint = QgsTemplatedLineSymbolLayerBase.CurvePoint

QgsVectorLayer.VertexMarkerType = Qgis.VertexMarkerType
QgsVectorLayer.SemiTransparentCircle = Qgis.VertexMarkerType.SemiTransparentCircle
QgsVectorLayer.SemiTransparentCircle.is_monkey_patched = True
QgsVectorLayer.SemiTransparentCircle.__doc__ = "Semi-transparent circle marker"
QgsVectorLayer.Cross = Qgis.VertexMarkerType.Cross
QgsVectorLayer.Cross.is_monkey_patched = True
QgsVectorLayer.Cross.__doc__ = "Cross marker"
QgsVectorLayer.NoMarker = Qgis.VertexMarkerType.NoMarker
QgsVectorLayer.NoMarker.is_monkey_patched = True
QgsVectorLayer.NoMarker.__doc__ = "No marker"

# Monkey patch static const "QgsDataProvider.SUBLAYER_SEPARATOR" which was removed for QGIS 3.12
QgsDataProvider.SUBLAYER_SEPARATOR = QgsDataProvider.sublayerSeparator()

Expand Down
51 changes: 51 additions & 0 deletions python/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,54 @@
Qgis.SublayerPromptMode.__doc__ = 'Specifies how to handle layer sources with multiple sublayers.\n\n.. versionadded:: 3.22\n\n' + '* ``AlwaysAsk``: ' + Qgis.SublayerPromptMode.AlwaysAsk.__doc__ + '\n' + '* ``AskExcludingRasterBands``: ' + Qgis.SublayerPromptMode.AskExcludingRasterBands.__doc__ + '\n' + '* ``NeverAskSkip``: ' + Qgis.SublayerPromptMode.NeverAskSkip.__doc__ + '\n' + '* ``NeverAskLoadAll``: ' + Qgis.SublayerPromptMode.NeverAskLoadAll.__doc__
# --
Qgis.SublayerPromptMode.baseClass = Qgis
QgsVectorLayer.SelectBehavior = Qgis.SelectBehavior
# monkey patching scoped based enum
QgsVectorLayer.SetSelection = Qgis.SelectBehavior.SetSelection
QgsVectorLayer.SetSelection.is_monkey_patched = True
QgsVectorLayer.SetSelection.__doc__ = "Set selection, removing any existing selection"
QgsVectorLayer.AddToSelection = Qgis.SelectBehavior.AddToSelection
QgsVectorLayer.AddToSelection.is_monkey_patched = True
QgsVectorLayer.AddToSelection.__doc__ = "Add selection to current selection"
QgsVectorLayer.IntersectSelection = Qgis.SelectBehavior.IntersectSelection
QgsVectorLayer.IntersectSelection.is_monkey_patched = True
QgsVectorLayer.IntersectSelection.__doc__ = "Modify current selection to include only select features which match"
QgsVectorLayer.RemoveFromSelection = Qgis.SelectBehavior.RemoveFromSelection
QgsVectorLayer.RemoveFromSelection.is_monkey_patched = True
QgsVectorLayer.RemoveFromSelection.__doc__ = "Remove from current selection"
Qgis.SelectBehavior.__doc__ = 'Specifies how a selection should be applied.\n\n.. versionadded:: 3.22\n\n' + '* ``SetSelection``: ' + Qgis.SelectBehavior.SetSelection.__doc__ + '\n' + '* ``AddToSelection``: ' + Qgis.SelectBehavior.AddToSelection.__doc__ + '\n' + '* ``IntersectSelection``: ' + Qgis.SelectBehavior.IntersectSelection.__doc__ + '\n' + '* ``RemoveFromSelection``: ' + Qgis.SelectBehavior.RemoveFromSelection.__doc__
# --
Qgis.SelectBehavior.baseClass = Qgis
QgsVectorLayer.EditResult = Qgis.VectorEditResult
# monkey patching scoped based enum
QgsVectorLayer.Success = Qgis.VectorEditResult.Success
QgsVectorLayer.Success.is_monkey_patched = True
QgsVectorLayer.Success.__doc__ = "Edit operation was successful"
QgsVectorLayer.EmptyGeometry = Qgis.VectorEditResult.EmptyGeometry
QgsVectorLayer.EmptyGeometry.is_monkey_patched = True
QgsVectorLayer.EmptyGeometry.__doc__ = "Edit operation resulted in an empty geometry"
QgsVectorLayer.EditFailed = Qgis.VectorEditResult.EditFailed
QgsVectorLayer.EditFailed.is_monkey_patched = True
QgsVectorLayer.EditFailed.__doc__ = "Edit operation failed"
QgsVectorLayer.FetchFeatureFailed = Qgis.VectorEditResult.FetchFeatureFailed
QgsVectorLayer.FetchFeatureFailed.is_monkey_patched = True
QgsVectorLayer.FetchFeatureFailed.__doc__ = "Unable to fetch requested feature"
QgsVectorLayer.InvalidLayer = Qgis.VectorEditResult.InvalidLayer
QgsVectorLayer.InvalidLayer.is_monkey_patched = True
QgsVectorLayer.InvalidLayer.__doc__ = "Edit failed due to invalid layer"
Qgis.VectorEditResult.__doc__ = 'Specifies the result of a vector layer edit operation\n\n.. versionadded:: 3.22\n\n' + '* ``Success``: ' + Qgis.VectorEditResult.Success.__doc__ + '\n' + '* ``EmptyGeometry``: ' + Qgis.VectorEditResult.EmptyGeometry.__doc__ + '\n' + '* ``EditFailed``: ' + Qgis.VectorEditResult.EditFailed.__doc__ + '\n' + '* ``FetchFeatureFailed``: ' + Qgis.VectorEditResult.FetchFeatureFailed.__doc__ + '\n' + '* ``InvalidLayer``: ' + Qgis.VectorEditResult.InvalidLayer.__doc__
# --
Qgis.VectorEditResult.baseClass = Qgis
QgsSymbolLayerUtils.VertexMarkerType = Qgis.VertexMarkerType
# monkey patching scoped based enum
QgsSymbolLayerUtils.SemiTransparentCircle = Qgis.VertexMarkerType.SemiTransparentCircle
QgsSymbolLayerUtils.SemiTransparentCircle.is_monkey_patched = True
QgsSymbolLayerUtils.SemiTransparentCircle.__doc__ = "Semi-transparent circle marker"
QgsSymbolLayerUtils.Cross = Qgis.VertexMarkerType.Cross
QgsSymbolLayerUtils.Cross.is_monkey_patched = True
QgsSymbolLayerUtils.Cross.__doc__ = "Cross marker"
QgsSymbolLayerUtils.NoMarker = Qgis.VertexMarkerType.NoMarker
QgsSymbolLayerUtils.NoMarker.is_monkey_patched = True
QgsSymbolLayerUtils.NoMarker.__doc__ = "No marker"
Qgis.VertexMarkerType.__doc__ = 'Editing vertex markers, used for showing vertices during a edit operation.\n\n.. versionadded:: 3.22\n\n' + '* ``SemiTransparentCircle``: ' + Qgis.VertexMarkerType.SemiTransparentCircle.__doc__ + '\n' + '* ``Cross``: ' + Qgis.VertexMarkerType.Cross.__doc__ + '\n' + '* ``NoMarker``: ' + Qgis.VertexMarkerType.NoMarker.__doc__
# --
Qgis.VertexMarkerType.baseClass = Qgis
3 changes: 0 additions & 3 deletions python/core/auto_additions/qgsvectorlayer.py

This file was deleted.

24 changes: 24 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,30 @@ The development version
NeverAskLoadAll,
};

enum class SelectBehavior
{
SetSelection,
AddToSelection,
IntersectSelection,
RemoveFromSelection,
};

enum class VectorEditResult
{
Success,
EmptyGeometry,
EditFailed,
FetchFeatureFailed,
InvalidLayer,
};

enum class VertexMarkerType
{
SemiTransparentCircle,
Cross,
NoMarker,
};

static const double DEFAULT_SEARCH_RADIUS_MM;

static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
Expand Down
3 changes: 2 additions & 1 deletion python/core/auto_generated/symbology/qgsrenderer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ If supported by the renderer, return classification attribute for the use in leg
.. versionadded:: 2.6
%End

void setVertexMarkerAppearance( int type, double size );
void setVertexMarkerAppearance( Qgis::VertexMarkerType type, double size );
%Docstring
Sets type and size of editing vertex markers for subsequent rendering
%End
Expand Down Expand Up @@ -603,6 +603,7 @@ to store all common base class properties in the DOM ``element``.




static void convertSymbolSizeScale( QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field );
%Docstring

Expand Down
4 changes: 2 additions & 2 deletions python/core/auto_generated/symbology/qgssymbol.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ and returns ``True`` if any of the layers returned ``True``.
Will be removed in QGIS 4.0
%End

void renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false, int currentVertexMarkerType = 0, double currentVertexMarkerSize = 0.0 ) throw( QgsCsException );
void renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false, Qgis::VertexMarkerType currentVertexMarkerType = Qgis::VertexMarkerType::SemiTransparentCircle, double currentVertexMarkerSize = 0.0 ) throw( QgsCsException );
%Docstring
Render a feature. Before calling this the :py:func:`~QgsSymbol.startRender` method should be called to initialize
the rendering process. After rendering all features :py:func:`~QgsSymbol.stopRender` must be called.
Expand Down Expand Up @@ -688,7 +688,7 @@ This is required for layers that generate their own geometry from other
information in the rendering context.
%End

void renderVertexMarker( QPointF pt, QgsRenderContext &context, int currentVertexMarkerType, double currentVertexMarkerSize );
void renderVertexMarker( QPointF pt, QgsRenderContext &context, Qgis::VertexMarkerType currentVertexMarkerType, double currentVertexMarkerSize );
%Docstring
Render editing vertex marker at specified point

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ class QgsSymbolLayerUtils
%End
public:

enum VertexMarkerType
{
SemiTransparentCircle,
Cross,
NoMarker
};

static QString encodeColor( const QColor &color );
static QColor decodeColor( const QString &str );

Expand Down Expand Up @@ -317,7 +310,7 @@ Returns a pixmap preview for a color ramp.

static void drawStippledBackground( QPainter *painter, QRect rect );

static void drawVertexMarker( double x, double y, QPainter &p, QgsSymbolLayerUtils::VertexMarkerType type, int markerSize );
static void drawVertexMarker( double x, double y, QPainter &p, Qgis::VertexMarkerType type, int markerSize );
%Docstring
Draws a vertex symbol at (painter) coordinates x, y. (Useful to assist vertex editing.)

Expand Down
34 changes: 5 additions & 29 deletions python/core/auto_generated/vector/qgsvectorlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -341,23 +341,6 @@ Provider to display vector data in a GRASS GIS layer.
%End
public:

enum EditResult
{
Success,
EmptyGeometry,
EditFailed,
FetchFeatureFailed,
InvalidLayer,
};

enum SelectBehavior
{
SetSelection,
AddToSelection,
IntersectSelection,
RemoveFromSelection,
};

struct LayerOptions
{

Expand Down Expand Up @@ -647,7 +630,7 @@ Returns the number of features that are selected in this layer.
.. seealso:: :py:func:`selectedFeatureIds`
%End

void selectByRect( QgsRectangle &rect, QgsVectorLayer::SelectBehavior behavior = QgsVectorLayer::SetSelection );
void selectByRect( QgsRectangle &rect, Qgis::SelectBehavior behavior = Qgis::SelectBehavior::SetSelection );
%Docstring
Selects features found within the search rectangle (in layer's coordinates)

Expand All @@ -662,7 +645,7 @@ Selects features found within the search rectangle (in layer's coordinates)
.. seealso:: :py:func:`selectByIds`
%End

void selectByExpression( const QString &expression, QgsVectorLayer::SelectBehavior behavior = QgsVectorLayer::SetSelection );
void selectByExpression( const QString &expression, Qgis::SelectBehavior behavior = Qgis::SelectBehavior::SetSelection );
%Docstring
Selects matching features using an expression.

Expand All @@ -677,7 +660,7 @@ Selects matching features using an expression.
.. versionadded:: 2.16
%End

void selectByIds( const QgsFeatureIds &ids, QgsVectorLayer::SelectBehavior behavior = QgsVectorLayer::SetSelection );
void selectByIds( const QgsFeatureIds &ids, Qgis::SelectBehavior behavior = Qgis::SelectBehavior::SetSelection );
%Docstring
Selects matching features using a list of feature IDs. Will emit the
:py:func:`~QgsVectorLayer.selectionChanged` signal with the clearAndSelect flag set.
Expand Down Expand Up @@ -1262,7 +1245,7 @@ to the given coordinates.
changes can be discarded by calling :py:func:`~QgsVectorLayer.rollBack`.
%End

EditResult deleteVertex( QgsFeatureId featureId, int vertex );
Qgis::VectorEditResult deleteVertex( QgsFeatureId featureId, int vertex );
%Docstring
Deletes a vertex from a feature.

Expand Down Expand Up @@ -2186,14 +2169,7 @@ Finish edit command and add it to undo/redo stack
Destroy active command and reverts all changes in it
%End

enum VertexMarkerType
{
SemiTransparentCircle,
Cross,
NoMarker
};

static void drawVertexMarker( double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize );
static void drawVertexMarker( double x, double y, QPainter &p, Qgis::VertexMarkerType type, int vertexSize );
%Docstring
Draws a vertex symbol at (screen) coordinates x, y. (Useful to assist vertex editing.)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ to the given coordinates
available in Python bindings as moveVertexV2
%End

QgsVectorLayer::EditResult deleteVertex( QgsFeatureId featureId, int vertex );
Qgis::VectorEditResult deleteVertex( QgsFeatureId featureId, int vertex );
%Docstring
Deletes a vertex from a feature.

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmextractbylocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ QVariantMap QgsSelectByLocationAlgorithm::processAlgorithm( const QVariantMap &p
if ( !selectLayer )
throw QgsProcessingException( QObject::tr( "Could not load source layer for INPUT" ) );

QgsVectorLayer::SelectBehavior method = static_cast< QgsVectorLayer::SelectBehavior >( parameterAsEnum( parameters, QStringLiteral( "METHOD" ), context ) );
Qgis::SelectBehavior method = static_cast< Qgis::SelectBehavior >( parameterAsEnum( parameters, QStringLiteral( "METHOD" ), context ) );
std::unique_ptr< QgsFeatureSource > intersectSource( parameterAsSource( parameters, QStringLiteral( "INTERSECT" ), context ) );
if ( !intersectSource )
throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "INTERSECT" ) ) );
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsmaptoolselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ bool QgsMapToolSelect::populateContextMenuWithEvent( QMenu *menu, QgsMapMouseEve
modifiers = event->modifiers();
mapPoint = event->mapPoint();
}
QgsVectorLayer::SelectBehavior behavior = QgsVectorLayer::SetSelection;
Qgis::SelectBehavior behavior = Qgis::SelectBehavior::SetSelection;
if ( modifiers & Qt::ShiftModifier && modifiers & Qt::ControlModifier )
behavior = QgsVectorLayer::IntersectSelection;
behavior = Qgis::SelectBehavior::IntersectSelection;
else if ( modifiers & Qt::ShiftModifier )
behavior = QgsVectorLayer::AddToSelection;
behavior = Qgis::SelectBehavior::AddToSelection;
else if ( modifiers & Qt::ControlModifier )
behavior = QgsVectorLayer::RemoveFromSelection;
behavior = Qgis::SelectBehavior::RemoveFromSelection;

QgsRectangle r = QgsMapToolSelectUtils::expandSelectRectangle( mapPoint, mCanvas, vlayer );

Expand Down
Loading

0 comments on commit 2724315

Please sign in to comment.