Skip to content
Permalink
Browse files
Move enums from QgsVectorLayer to Qgis, promote to enum classes,
and fix redundant QgsVectorLayer.VertexMarkerType enum
  • Loading branch information
nyalldawson committed Jul 19, 2021
1 parent cc17c90 commit 2724315a991f33128b36cd6419820efc903fbd9e
Showing with 252 additions and 189 deletions.
  1. +11 −0 python/core/__init__.py.in
  2. +51 −0 python/core/auto_additions/qgis.py
  3. +0 −3 python/core/auto_additions/qgsvectorlayer.py
  4. +24 −0 python/core/auto_generated/qgis.sip.in
  5. +2 −1 python/core/auto_generated/symbology/qgsrenderer.sip.in
  6. +2 −2 python/core/auto_generated/symbology/qgssymbol.sip.in
  7. +1 −8 python/core/auto_generated/symbology/qgssymbollayerutils.sip.in
  8. +5 −29 python/core/auto_generated/vector/qgsvectorlayer.sip.in
  9. +1 −1 python/core/auto_generated/vector/qgsvectorlayereditutils.sip.in
  10. +1 −1 src/analysis/processing/qgsalgorithmextractbylocation.cpp
  11. +4 −4 src/app/qgsmaptoolselect.cpp
  12. +27 −27 src/app/qgsmaptoolselectutils.cpp
  13. +5 −5 src/app/qgsmaptoolselectutils.h
  14. +4 −4 src/app/vertextool/qgsvertextool.cpp
  15. +42 −0 src/core/qgis.h
  16. +2 −3 src/core/symbology/qgsrenderer.cpp
  17. +3 −2 src/core/symbology/qgsrenderer.h
  18. +3 −3 src/core/symbology/qgssymbol.cpp
  19. +2 −2 src/core/symbology/qgssymbol.h
  20. +4 −4 src/core/symbology/qgssymbollayerutils.cpp
  21. +1 −9 src/core/symbology/qgssymbollayerutils.h
  22. +32 −27 src/core/vector/qgsvectorlayer.cpp
  23. +5 −34 src/core/vector/qgsvectorlayer.h
  24. +5 −5 src/core/vector/qgsvectorlayereditutils.cpp
  25. +1 −1 src/core/vector/qgsvectorlayereditutils.h
  26. +3 −3 src/core/vector/qgsvectorlayerrenderer.cpp
  27. +1 −1 src/core/vector/qgsvectorlayerrenderer.h
  28. +5 −5 src/gui/qgsattributeform.cpp
  29. +1 −1 src/gui/qgsattributeform.h
  30. +4 −4 src/gui/qgsexpressionselectiondialog.cpp
@@ -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()

@@ -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

This file was deleted.

@@ -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;
@@ -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
@@ -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

@@ -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.
@@ -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

@@ -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 );

@@ -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.)

@@ -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
{

@@ -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)

@@ -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.

@@ -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.
@@ -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.

@@ -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.)

@@ -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.

@@ -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" ) ) );
@@ -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 );

0 comments on commit 2724315

Please sign in to comment.