Skip to content
Permalink
Browse files
Condense duplicate enums
  • Loading branch information
nyalldawson committed Oct 22, 2021
1 parent 9752abe commit 6453d5f35a8a5973489c0f93739e0ce5fcf52c85
@@ -73,6 +73,14 @@ QgsMarkerLineSymbolLayer.FirstVertex = Qgis.MarkerLinePlacement.FirstVertex
QgsMarkerLineSymbolLayer.CentralPoint = Qgis.MarkerLinePlacement.CentralPoint
QgsMarkerLineSymbolLayer.CurvePoint = Qgis.MarkerLinePlacement.CurvePoint

QgsRasterFillSymbolLayer.FillCoordinateMode = Qgis.SymbolCoordinateReference
QgsRasterFillSymbolLayer.Feature = Qgis.SymbolCoordinateReference.Feature
QgsRasterFillSymbolLayer.Viewport = Qgis.SymbolCoordinateReference.Viewport

QgsShapeburstFillSymbolLayer.ShapeburstColorType = Qgis.GradientColorSource
QgsShapeburstFillSymbolLayer.SimpleTwoColor = Qgis.GradientColorSource.SimpleTwoColor
QgsShapeburstFillSymbolLayer.ColorRamp = Qgis.GradientColorSource.ColorRamp

QgsVectorLayer.VertexMarkerType = Qgis.VertexMarkerType
QgsVectorLayer.SemiTransparentCircle = Qgis.VertexMarkerType.SemiTransparentCircle
QgsVectorLayer.SemiTransparentCircle.is_monkey_patched = True
@@ -474,15 +474,12 @@ class QgsShapeburstFillSymbolLayer : QgsFillSymbolLayer
%End
public:

enum ShapeburstColorType
{
SimpleTwoColor,
ColorRamp
};

QgsShapeburstFillSymbolLayer( const QColor &color = DEFAULT_SIMPLEFILL_COLOR, const QColor &color2 = Qt::white,
ShapeburstColorType colorType = SimpleTwoColor,
Qgis::GradientColorSource colorType = Qgis::GradientColorSource::SimpleTwoColor,
int blurRadius = 0, bool useWholeShape = true, double maxDistance = 5 );
%Docstring
Constructor for QgsShapeburstFillSymbolLayer.
%End

~QgsShapeburstFillSymbolLayer();

@@ -622,7 +619,7 @@ Returns the unit for the maximum distance to shade inside of the shape from the
void setDistanceMapUnitScale( const QgsMapUnitScale &scale );
const QgsMapUnitScale &distanceMapUnitScale() const;

void setColorType( ShapeburstColorType colorType );
void setColorType( Qgis::GradientColorSource colorType );
%Docstring
Sets the color mode to use for the shapeburst fill. Shapeburst can either be drawn using a :py:class:`QgsColorRamp` color ramp
or by simply specificing a start and end color. setColorType is used to specify which mode to use for the fill.
@@ -640,7 +637,7 @@ or by simply specificing a start and end color. setColorType is used to specify
.. versionadded:: 2.3
%End

ShapeburstColorType colorType() const;
Qgis::GradientColorSource colorType() const;
%Docstring
Returns the color mode used for the shapeburst fill. Shapeburst can either be drawn using a :py:class:`QgsColorRamp` color ramp
or by simply specificing a start and end color.
@@ -918,12 +915,6 @@ A class for filling symbols with a repeated raster image.
%End
public:

enum FillCoordinateMode
{
Feature,
Viewport,
};

QgsRasterFillSymbolLayer( const QString &imageFilePath = QString() );
%Docstring
Constructor for QgsRasterFillSymbolLayer, using a raster fill from the
@@ -985,7 +976,7 @@ The path to the raster image used for the fill.
.. seealso:: :py:func:`setImageFilePath`
%End

void setCoordinateMode( FillCoordinateMode mode );
void setCoordinateMode( Qgis::SymbolCoordinateReference mode );
%Docstring
Set the coordinate mode for fill. Controls how the top left corner of the image
fill is positioned relative to the feature.
@@ -995,7 +986,7 @@ fill is positioned relative to the feature.
.. seealso:: :py:func:`coordinateMode`
%End

FillCoordinateMode coordinateMode() const;
Qgis::SymbolCoordinateReference coordinateMode() const;
%Docstring
Coordinate mode for fill. Controls how the top left corner of the image
fill is positioned relative to the feature.
@@ -1029,7 +1029,7 @@ QgsMapUnitScale QgsGradientFillSymbolLayer::mapUnitScale() const

//QgsShapeburstFillSymbolLayer

QgsShapeburstFillSymbolLayer::QgsShapeburstFillSymbolLayer( const QColor &color, const QColor &color2, ShapeburstColorType colorType,
QgsShapeburstFillSymbolLayer::QgsShapeburstFillSymbolLayer( const QColor &color, const QColor &color2, Qgis::GradientColorSource colorType,
int blurRadius, bool useWholeShape, double maxDistance )
: mBlurRadius( blurRadius )
, mUseWholeShape( useWholeShape )
@@ -1045,7 +1045,7 @@ QgsShapeburstFillSymbolLayer::~QgsShapeburstFillSymbolLayer() = default;
QgsSymbolLayer *QgsShapeburstFillSymbolLayer::create( const QVariantMap &props )
{
//default to a two-color gradient
ShapeburstColorType colorType = QgsShapeburstFillSymbolLayer::SimpleTwoColor;
Qgis::GradientColorSource colorType = Qgis::GradientColorSource::SimpleTwoColor;
QColor color = DEFAULT_SIMPLEFILL_COLOR, color2 = Qt::white;
int blurRadius = 0;
bool useWholeShape = true;
@@ -1055,7 +1055,7 @@ QgsSymbolLayer *QgsShapeburstFillSymbolLayer::create( const QVariantMap &props )
//update fill properties from props
if ( props.contains( QStringLiteral( "color_type" ) ) )
{
colorType = static_cast< ShapeburstColorType >( props[QStringLiteral( "color_type" )].toInt() );
colorType = static_cast< Qgis::GradientColorSource >( props[QStringLiteral( "color_type" )].toInt() );
}
if ( props.contains( QStringLiteral( "shapeburst_color" ) ) )
{
@@ -1273,7 +1273,7 @@ void QgsShapeburstFillSymbolLayer::renderPolygon( const QPolygonF &points, const

//if we are using the two color mode, create a gradient ramp
std::unique_ptr< QgsGradientColorRamp > twoColorGradientRamp;
if ( mColorType == QgsShapeburstFillSymbolLayer::SimpleTwoColor )
if ( mColorType == Qgis::GradientColorSource::SimpleTwoColor )
{
twoColorGradientRamp = std::make_unique< QgsGradientColorRamp >( color1, color2 );
}
@@ -1368,7 +1368,7 @@ void QgsShapeburstFillSymbolLayer::renderPolygon( const QPolygonF &points, const
double *dtArray = distanceTransform( fillImage.get(), context.renderContext() );

//copy distance transform values back to QImage, shading by appropriate color ramp
dtArrayToQImage( dtArray, fillImage.get(), mColorType == QgsShapeburstFillSymbolLayer::SimpleTwoColor ? twoColorGradientRamp.get() : mGradientRamp.get(),
dtArrayToQImage( dtArray, fillImage.get(), mColorType == Qgis::GradientColorSource::SimpleTwoColor ? twoColorGradientRamp.get() : mGradientRamp.get(),
context.renderContext(), useWholeShape, outputPixelMaxDist );
if ( context.opacity() < 1 )
{
@@ -1609,7 +1609,7 @@ QVariantMap QgsShapeburstFillSymbolLayer::properties() const
QVariantMap map;
map[QStringLiteral( "color" )] = QgsSymbolLayerUtils::encodeColor( mColor );
map[QStringLiteral( "gradient_color2" )] = QgsSymbolLayerUtils::encodeColor( mColor2 );
map[QStringLiteral( "color_type" )] = QString::number( mColorType );
map[QStringLiteral( "color_type" )] = QString::number( static_cast< int >( mColorType ) );
map[QStringLiteral( "blur_radius" )] = QString::number( mBlurRadius );
map[QStringLiteral( "use_whole_shape" )] = QString::number( mUseWholeShape );
map[QStringLiteral( "max_distance" )] = QString::number( mMaxDistance );
@@ -4156,7 +4156,7 @@ QgsRasterFillSymbolLayer::~QgsRasterFillSymbolLayer() = default;

QgsSymbolLayer *QgsRasterFillSymbolLayer::create( const QVariantMap &properties )
{
FillCoordinateMode mode = QgsRasterFillSymbolLayer::Feature;
Qgis::SymbolCoordinateReference mode = Qgis::SymbolCoordinateReference::Feature;
double alpha = 1.0;
QPointF offset;
double angle = 0.0;
@@ -4169,7 +4169,7 @@ QgsSymbolLayer *QgsRasterFillSymbolLayer::create( const QVariantMap &properties
}
if ( properties.contains( QStringLiteral( "coordinate_mode" ) ) )
{
mode = static_cast< FillCoordinateMode >( properties[QStringLiteral( "coordinate_mode" )].toInt() );
mode = static_cast< Qgis::SymbolCoordinateReference >( properties[QStringLiteral( "coordinate_mode" )].toInt() );
}
if ( properties.contains( QStringLiteral( "alpha" ) ) )
{
@@ -4262,7 +4262,7 @@ void QgsRasterFillSymbolLayer::renderPolygon( const QPolygonF &points, const QVe
offset.setY( context.renderContext().convertToPainterUnits( offset.y(), mOffsetUnit, mOffsetMapUnitScale ) );
p->translate( offset );
}
if ( mCoordinateMode == Feature )
if ( mCoordinateMode == Qgis::SymbolCoordinateReference::Feature )
{
QRectF boundingRect = points.boundingRect();
mBrush.setTransform( mBrush.transform().translate( boundingRect.left() - mBrush.transform().dx(),
@@ -4290,7 +4290,7 @@ QVariantMap QgsRasterFillSymbolLayer::properties() const
{
QVariantMap map;
map[QStringLiteral( "imageFile" )] = mImageFilePath;
map[QStringLiteral( "coordinate_mode" )] = QString::number( mCoordinateMode );
map[QStringLiteral( "coordinate_mode" )] = QString::number( static_cast< int >( mCoordinateMode ) );
map[QStringLiteral( "alpha" )] = QString::number( mOpacity );
map[QStringLiteral( "offset" )] = QgsSymbolLayerUtils::encodePoint( mOffset );
map[QStringLiteral( "offset_unit" )] = QgsUnitTypes::encodeUnit( mOffsetUnit );
@@ -4335,7 +4335,7 @@ void QgsRasterFillSymbolLayer::setImageFilePath( const QString &imagePath )
mImageFilePath = imagePath;
}

void QgsRasterFillSymbolLayer::setCoordinateMode( const QgsRasterFillSymbolLayer::FillCoordinateMode mode )
void QgsRasterFillSymbolLayer::setCoordinateMode( const Qgis::SymbolCoordinateReference mode )
{
mCoordinateMode = mode;
}
@@ -487,14 +487,11 @@ class CORE_EXPORT QgsShapeburstFillSymbolLayer : public QgsFillSymbolLayer
{
public:

enum ShapeburstColorType
{
SimpleTwoColor,
ColorRamp
};

/**
* Constructor for QgsShapeburstFillSymbolLayer.
*/
QgsShapeburstFillSymbolLayer( const QColor &color = DEFAULT_SIMPLEFILL_COLOR, const QColor &color2 = Qt::white,
ShapeburstColorType colorType = SimpleTwoColor,
Qgis::GradientColorSource colorType = Qgis::GradientColorSource::SimpleTwoColor,
int blurRadius = 0, bool useWholeShape = true, double maxDistance = 5 );

~QgsShapeburstFillSymbolLayer() override;
@@ -617,7 +614,7 @@ class CORE_EXPORT QgsShapeburstFillSymbolLayer : public QgsFillSymbolLayer
* \see setColorRamp
* \since QGIS 2.3
*/
void setColorType( ShapeburstColorType colorType ) { mColorType = colorType; }
void setColorType( Qgis::GradientColorSource colorType ) { mColorType = colorType; }

/**
* Returns the color mode used for the shapeburst fill. Shapeburst can either be drawn using a QgsColorRamp color ramp
@@ -629,7 +626,7 @@ class CORE_EXPORT QgsShapeburstFillSymbolLayer : public QgsFillSymbolLayer
* \see colorRamp
* \since QGIS 2.3
*/
ShapeburstColorType colorType() const { return mColorType; }
Qgis::GradientColorSource colorType() const { return mColorType; }

/**
* Sets the color \a ramp used to draw the shapeburst fill. Color ramps are only used if setColorType is set ShapeburstColorType::ColorRamp.
@@ -743,7 +740,7 @@ class CORE_EXPORT QgsShapeburstFillSymbolLayer : public QgsFillSymbolLayer
QgsUnitTypes::RenderUnit mDistanceUnit = QgsUnitTypes::RenderMillimeters;
QgsMapUnitScale mDistanceMapUnitScale;

ShapeburstColorType mColorType = SimpleTwoColor;
Qgis::GradientColorSource mColorType = Qgis::GradientColorSource::SimpleTwoColor;
QColor mColor2;

bool mIgnoreRings = false;
@@ -869,13 +866,6 @@ class CORE_EXPORT QgsRasterFillSymbolLayer: public QgsImageFillSymbolLayer
{
public:

//! Fill coordinate modes, dictates fill tiling behavior
enum FillCoordinateMode
{
Feature, //!< Tiling is based on feature bounding box
Viewport, //!< Tiling is based on complete map viewport
};

/**
* Constructor for QgsRasterFillSymbolLayer, using a raster fill from the
* specified \a imageFilePath.
@@ -931,15 +921,15 @@ class CORE_EXPORT QgsRasterFillSymbolLayer: public QgsImageFillSymbolLayer
* \param mode coordinate mode
* \see coordinateMode
*/
void setCoordinateMode( FillCoordinateMode mode );
void setCoordinateMode( Qgis::SymbolCoordinateReference mode );

/**
* Coordinate mode for fill. Controls how the top left corner of the image
* fill is positioned relative to the feature.
* \returns coordinate mode
* \see setCoordinateMode
*/
FillCoordinateMode coordinateMode() const { return mCoordinateMode; }
Qgis::SymbolCoordinateReference coordinateMode() const { return mCoordinateMode; }

/**
* Sets the \a opacity for the raster image used in the fill.
@@ -1073,7 +1063,7 @@ class CORE_EXPORT QgsRasterFillSymbolLayer: public QgsImageFillSymbolLayer

//! Path to the image file
QString mImageFilePath;
FillCoordinateMode mCoordinateMode = QgsRasterFillSymbolLayer::Feature;
Qgis::SymbolCoordinateReference mCoordinateMode = Qgis::SymbolCoordinateReference::Feature;
double mOpacity = 1.0;

QPointF mOffset;
@@ -356,7 +356,7 @@ bool QgsMapBoxGlStyleConverter::parseFillLayer( const QVariantMap &jsonLayer, Qg
rasterFill->setImageFilePath( sprite );
rasterFill->setWidth( spriteSize.width() );
rasterFill->setWidthUnit( context.targetUnit() );
rasterFill->setCoordinateMode( QgsRasterFillSymbolLayer::Viewport );
rasterFill->setCoordinateMode( Qgis::SymbolCoordinateReference::Viewport );

if ( rasterOpacity >= 0 )
{
@@ -1691,7 +1691,7 @@ void QgsShapeburstFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer )
btnChangeColor2->setColor( mLayer->color2() );
btnChangeColor2->blockSignals( false );

if ( mLayer->colorType() == QgsShapeburstFillSymbolLayer::SimpleTwoColor )
if ( mLayer->colorType() == Qgis::GradientColorSource::SimpleTwoColor )
{
radioTwoColor->setChecked( true );
btnColorRamp->setEnabled( false );
@@ -1800,11 +1800,11 @@ void QgsShapeburstFillSymbolLayerWidget::colorModeChanged()

if ( radioTwoColor->isChecked() )
{
mLayer->setColorType( QgsShapeburstFillSymbolLayer::SimpleTwoColor );
mLayer->setColorType( Qgis::GradientColorSource::SimpleTwoColor );
}
else
{
mLayer->setColorType( QgsShapeburstFillSymbolLayer::ColorRamp );
mLayer->setColorType( Qgis::GradientColorSource::ColorRamp );
}
emit changed();
}
@@ -4117,10 +4117,10 @@ void QgsRasterFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer )
cboCoordinateMode->blockSignals( true );
switch ( mLayer->coordinateMode() )
{
case QgsRasterFillSymbolLayer::Viewport:
case Qgis::SymbolCoordinateReference::Viewport:
cboCoordinateMode->setCurrentIndex( 1 );
break;
case QgsRasterFillSymbolLayer::Feature:
case Qgis::SymbolCoordinateReference::Feature:
default:
cboCoordinateMode->setCurrentIndex( 0 );
break;
@@ -4169,11 +4169,11 @@ void QgsRasterFillSymbolLayerWidget::setCoordinateMode( int index )
{
case 0:
//feature coordinate mode
mLayer->setCoordinateMode( QgsRasterFillSymbolLayer::Feature );
mLayer->setCoordinateMode( Qgis::SymbolCoordinateReference::Feature );
break;
case 1:
//viewport coordinate mode
mLayer->setCoordinateMode( QgsRasterFillSymbolLayer::Viewport );
mLayer->setCoordinateMode( Qgis::SymbolCoordinateReference::Viewport );
break;
}

@@ -141,7 +141,7 @@ void TestQgsRasterFill::init()
mRasterFill->setImageFilePath( mTestDataDir + QStringLiteral( "sample_image.png" ) );
mRasterFill->setWidth( 30.0 );
mRasterFill->setWidthUnit( QgsUnitTypes::RenderPixels );
mRasterFill->setCoordinateMode( QgsRasterFillSymbolLayer::Feature );
mRasterFill->setCoordinateMode( Qgis::SymbolCoordinateReference::Feature );
mRasterFill->setOpacity( 1.0 );
mRasterFill->setOffset( QPointF( 0, 0 ) );
}
@@ -161,7 +161,7 @@ void TestQgsRasterFill::rasterFillSymbol()
void TestQgsRasterFill::coordinateMode()
{
mReport += QLatin1String( "<h2>Raster fill viewport mode</h2>\n" );
mRasterFill->setCoordinateMode( QgsRasterFillSymbolLayer::Viewport );
mRasterFill->setCoordinateMode( Qgis::SymbolCoordinateReference::Viewport );
const bool result = imageCheck( QStringLiteral( "rasterfill_viewport" ) );
QVERIFY( result );
}
@@ -205,7 +205,7 @@ void TestQgsRasterFill::percentageCoordinateMode()
mReport += QLatin1String( "<h2>Raster fill percentage viewport mode</h2>\n" );
mRasterFill->setWidthUnit( QgsUnitTypes::RenderPercentage );
mRasterFill->setWidth( 6.3 );
mRasterFill->setCoordinateMode( QgsRasterFillSymbolLayer::Viewport );
mRasterFill->setCoordinateMode( Qgis::SymbolCoordinateReference::Viewport );
const bool result = imageCheck( QStringLiteral( "rasterfill_viewport_percentage" ) );
QVERIFY( result );
}
@@ -162,9 +162,9 @@ void TestQgsShapeburst::shapeburstSymbolRamp()
gradientRamp->setStops( stops );

mShapeburstFill->setColorRamp( gradientRamp );
mShapeburstFill->setColorType( QgsShapeburstFillSymbolLayer::ColorRamp );
mShapeburstFill->setColorType( Qgis::GradientColorSource::ColorRamp );
QVERIFY( imageCheck( "shapeburst_ramp" ) );
mShapeburstFill->setColorType( QgsShapeburstFillSymbolLayer::SimpleTwoColor );
mShapeburstFill->setColorType( Qgis::GradientColorSource::SimpleTwoColor );
}

void TestQgsShapeburst::shapeburstBlur()

0 comments on commit 6453d5f

Please sign in to comment.