Skip to content
Permalink
Browse files

[FEATURE] Add 'shapeburst' fill style. Shapeburst fills implement a b…

…uffered gradient fill, where a gradient is drawn from the boundary of a polygon towards the polygon's centre. Configurable parameters include distance from the boundary to shade, use of color ramps or simple two color gradients, optional blurring of the fill and offsets.
  • Loading branch information
nyalldawson committed Mar 21, 2014
1 parent 793d30c commit 13cbfd138cc394bade5cad1312983f00993bcba1
Showing with 2,042 additions and 0 deletions.
  1. +3 −0 python/core/composer/qgspaperitem.sip
  2. +187 −0 python/core/symbology-ng/qgsfillsymbollayerv2.sip
  3. +5 −0 python/core/symbology-ng/qgssymbollayerv2utils.sip
  4. +29 −0 python/gui/symbology-ng/qgssymbollayerv2widget.sip
  5. +501 −0 src/core/symbology-ng/qgsfillsymbollayerv2.cpp
  6. +215 −0 src/core/symbology-ng/qgsfillsymbollayerv2.h
  7. +2 −0 src/core/symbology-ng/qgssymbollayerv2registry.cpp
  8. +24 −0 src/core/symbology-ng/qgssymbollayerv2utils.cpp
  9. +5 −0 src/core/symbology-ng/qgssymbollayerv2utils.h
  10. +1 −0 src/gui/symbology-ng/qgslayerpropertieswidget.cpp
  11. +233 −0 src/gui/symbology-ng/qgssymbollayerv2widget.cpp
  12. +35 −0 src/gui/symbology-ng/qgssymbollayerv2widget.h
  13. +381 −0 src/ui/symbollayer/widget_shapeburstfill.ui
  14. +1 −0 tests/src/core/CMakeLists.txt
  15. +239 −0 tests/src/core/testqgsshapeburst.cpp
  16. BIN tests/testdata/control_images/expected_shapeburst/expected_shapeburst.png
  17. BIN tests/testdata/control_images/expected_shapeburst_blur/expected_shapeburst_blur.png
  18. BIN tests/testdata/control_images/expected_shapeburst_colors/expected_shapeburst_colors.png
  19. BIN tests/testdata/control_images/expected_shapeburst_from_qml/expected_shapeburst_from_qml.png
  20. BIN ...ontrol_images/expected_shapeburst_maxdistance_mapunit/expected_shapeburst_maxdistance_mapunit.png
  21. BIN ...testdata/control_images/expected_shapeburst_maxdistance_mm/expected_shapeburst_maxdistance_mm.png
  22. BIN tests/testdata/control_images/expected_shapeburst_ramp/expected_shapeburst_ramp.png
  23. +181 −0 tests/testdata/polys_shapeburst_symbol.qml
@@ -2,6 +2,9 @@
* drawn above all other composer items, while the paper item is drawn below all others.*/
class QgsPaperGrid : QGraphicsRectItem
{
%TypeHeaderCode
#include <qgspaperitem.h>
%End
public:
QgsPaperGrid( double x, double y, double width, double height, QgsComposition* composition );
~QgsPaperGrid();
@@ -197,6 +197,193 @@ class QgsGradientFillSymbolLayerV2 : QgsFillSymbolLayerV2

};

class QgsShapeburstFillSymbolLayerV2 : QgsFillSymbolLayerV2
{
%TypeHeaderCode
#include <qgsfillsymbollayerv2.h>
%End

public:

enum ShapeburstColorType
{
SimpleTwoColor,
ColorRamp
};

QgsShapeburstFillSymbolLayerV2( QColor color = DEFAULT_SIMPLEFILL_COLOR,
QColor color2 = Qt::white,
ShapeburstColorType colorType = SimpleTwoColor,
int blurRadius = 0,
bool useWholeShape = true,
double maxDistance = 5 );

virtual ~QgsShapeburstFillSymbolLayerV2();

// static stuff

static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ) /Factory/;

// implemented from base classes

QString layerType() const;

void startRender( QgsSymbolV2RenderContext& context );

void stopRender( QgsSymbolV2RenderContext& context );

void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );

QgsStringMap properties() const;

QgsSymbolLayerV2* clone() const /Factory/;

double estimateMaxBleed() const;

/**Sets the blur radius, which controls the amount of blurring applied to the fill.
* @param blurRadius Radius for fill blur. Values between 0 - 17 are valid, where higher values results in a stronger blur. Set to 0 to disable blur.
* @note added in 2.3
* @see blurRadius
*/
void setBlurRadius( int blurRadius );
/**Returns the blur radius, which controls the amount of blurring applied to the fill.
* @returns Integer representing the radius for fill blur. Higher values indicate a stronger blur. A 0 value indicates that blurring is disabled.
* @note added in 2.3
* @see setBlurRadius
*/
int blurRadius() const;

/**Sets whether the shapeburst fill should be drawn using the entire shape.
* @param useWholeShape Set to true if shapeburst should cover entire shape. If false, setMaxDistance is used to calculate how far from the boundary of the shape should
* be shaded
* @note added in 2.3
* @see useWholeShape
* @see setMaxDistance
*/
void setUseWholeShape( double useWholeShape );
/**Returns whether the shapeburst fill is set to cover the entire shape.
* @returns True if shapeburst fill will cover the entire shape. If false, shapeburst is drawn to a distance of maxDistance from the polygon's boundary.
* @note added in 2.3
* @see setUseWholeShape
* @see maxDistance
*/
double useWholeShape() const;

/**Sets the maximum distance to shape inside of the shape from the polygon's boundary.
* @param maxDistance distance from boundary to shade. setUseWholeShape must be set to false for this parameter to take effect. Distance unit is controlled by setDistanceUnit.
* @note added in 2.3
* @see maxDistance
* @see setUseWholeShape
* @see setDistanceUnit
*/
void setMaxDistance( double maxDistance );
/**Returns the maximum distance from the shape's boundary which is shaded. This parameter is only effective if useWholeShape is false.
* @returns the maximum distance from the polygon's boundary which is shaded. Distance units are indicated by distanceUnit.
* @note added in 2.3
* @see useWholeShape
* @see setMaxDistance
* @see distanceUnit
*/
double maxDistance() const;

/**Sets the unit for the maximum distance to shade inside of the shape from the polygon's boundary.
* @param unit distance unit for the maximum distance
* @note added in 2.3
* @see setMaxDistance
* @see distanceUnit
*/
void setDistanceUnit( QgsSymbolV2::OutputUnit unit );
/**Returns the unit for the maximum distance to shade inside of the shape from the polygon's boundary.
* @returns distance unit for the maximum distance
* @note added in 2.3
* @see maxDistance
* @see setDistanceUnit
*/
QgsSymbolV2::OutputUnit distanceUnit() const;

/**Sets the color mode to use for the shapeburst fill. Shapeburst can either be drawn using a QgsVectorColorRampV2 color ramp
* or by simply specificing a start and end color. setColorType is used to specify which mode to use for the fill.
* @param colorType color type to use for shapeburst fill
* @note added in 2.3
* @see colorType
* @see setColor
* @see setColor2
* @see setColorRamp
*/
void setColorType( ShapeburstColorType colorType );
/**Returns the color mode used for the shapeburst fill. Shapeburst can either be drawn using a QgsVectorColorRampV2 color ramp
* or by simply specificing a start and end color.
* @returns current color mode used for the shapeburst fill
* @note added in 2.3
* @see setColorType
* @see color
* @see color2
* @see colorRamp
*/
ShapeburstColorType colorType() const;

/**Sets the color ramp used to draw the shapeburst fill. Color ramps are only used if setColorType is set ShapeburstColorType::ColorRamp.
* @param ramp color ramp to use for shapeburst fill
* @note added in 2.3
* @see setColorType
* @see colorRamp
*/
void setColorRamp( QgsVectorColorRampV2* ramp );
/**Returns the color ramp used for the shapeburst fill. The color ramp is only used if the colorType is set to ShapeburstColorType::ColorRamp
* @returns a QgsVectorColorRampV2 color ramp
* @note added in 2.3
* @see setColorRamp
* @see colorType
*/
QgsVectorColorRampV2* colorRamp();

/**Sets the color for the endpoint of the shapeburst fill. This color is only used if setColorType is set ShapeburstColorType::SimpleTwoColor.
* @param color2 QColor to use for endpoint of gradient
* @note added in 2.3
* @see setColorType
* @see color2
*/
void setColor2( QColor color2 );
/**Returns the color used for the endpoint of the shapeburst fill. This color is only used if the colorType is set to ShapeburstColorType::SimpleTwoColor
* @returns a QColor indicating the color of the endpoint of the gradient
* @note added in 2.3
* @see setColor2
* @see colorType
*/
QColor color2() const;

/**Sets the offset for the shapeburst fill.
* @param offset QPointF indicating the horizontal/vertical offset amount
* @note added in 2.3
* @see offset
* @see setOffsetUnit
*/
void setOffset( QPointF offset );
/**Returns the offset for the shapeburst fill.
* @returns a QPointF indicating the horizontal/vertical offset amount
* @note added in 2.3
* @see setOffset
* @see offsetUnit
*/
QPointF offset() const;

/**Sets the units used for the offset for the shapeburst fill.
* @param unit units for fill offset
* @note added in 2.3
* @see setOffset
* @see offsetUnit
*/
void setOffsetUnit( QgsSymbolV2::OutputUnit unit );
/**Returns the units used for the offset of the shapeburst fill.
* @returns units used for the fill offset
* @note added in 2.3
* @see offset
* @see setOffsetUnit
*/
QgsSymbolV2::OutputUnit offsetUnit() const;

};

/**Base class for polygon renderers generating texture images*/
class QgsImageFillSymbolLayer: QgsFillSymbolLayerV2
{
@@ -204,6 +204,11 @@ class QgsSymbolLayerV2Utils
*/
static void blurImageInPlace( QImage& image, const QRect& rect, int radius, bool alphaOnly );

/** Converts a QColor into a premultiplied ARGB QColor value using a specified alpha value
* @note added in 2.3
*/
static void premultiplyColor( QColor& rgb, int alpha );

/**Sorts the passed list in requested order*/
static void sortVariantList( QList<QVariant>& list, Qt::SortOrder order );
/**Returns a point on the line from startPoint to directionPoint that is a certain distance away from the starting point*/
@@ -145,6 +145,35 @@ class QgsGradientFillSymbolLayerV2Widget : QgsSymbolLayerV2Widget
void on_mSpinAngle_valueChanged( double value );
};

///////////

class QgsShapeburstFillSymbolLayerV2Widget : QgsSymbolLayerV2Widget
{
%TypeHeaderCode
#include <qgssymbollayerv2widget.h>
%End
public:
QgsShapeburstFillSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent = NULL );

static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) /Factory/;

// from base class
virtual void setSymbolLayer( QgsSymbolLayerV2* layer );
virtual QgsSymbolLayerV2* symbolLayer();

public slots:
void setColor( const QColor& color );
void setColor2( const QColor& color );
void colorModeChanged();
void on_mSpinBlurRadius_valueChanged( int value );
void on_mSpinMaxDistance_valueChanged( double value );
void on_mDistanceUnitComboBox_currentIndexChanged( int index );
void on_mRadioUseWholeShape_toggled( bool value );
void applyColorRamp();
void offsetChanged();
void on_mOffsetUnitComboBox_currentIndexChanged( int index );
void on_mDataDefinedPropertiesButton_clicked();
};

///////////

0 comments on commit 13cbfd1

Please sign in to comment.
You can’t perform that action at this time.