Skip to content

Commit

Permalink
Flip symbology from alpha/transparency to opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 30, 2017
1 parent 233a95e commit a326224
Show file tree
Hide file tree
Showing 27 changed files with 324 additions and 252 deletions.
8 changes: 8 additions & 0 deletions doc/api_break.dox
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1837,6 +1837,12 @@ QProgressDialog argument will need to be updated using manually created connecti
signals and the updates to the progress dialog. signals and the updates to the progress dialog.




QgsRasterFillSymbolLayer {#qgis_api_break_3_0_QgsRasterFillSymbolLayer}
-----------------

- alpha() and setAlpha() were removed. Use opacity() and setOpacity() instead.


QgsRasterInterface {#qgis_api_break_3_0_QgsRasterInterface} QgsRasterInterface {#qgis_api_break_3_0_QgsRasterInterface}
------------------ ------------------


Expand Down Expand Up @@ -2108,6 +2114,7 @@ than an integer value
- usedAttributes() now requires a QgsRenderContext argument. - usedAttributes() now requires a QgsRenderContext argument.
- setDataDefinedAngle(), dataDefinedAngle(), setDataDefinedSize(), dataDefinedSize(), setDataDefinedWidth() and dataDefinedWidth() - setDataDefinedAngle(), dataDefinedAngle(), setDataDefinedSize(), dataDefinedSize(), setDataDefinedWidth() and dataDefinedWidth()
now work with QgsProperty objects instead of QgsDataDefined. now work with QgsProperty objects instead of QgsDataDefined.
- alpha() and setAlpha() were removed. Use opacity() and setOpacity() instead.




QgsSymbolLayer (renamed from QgsSymbolLayerV2) {#qgis_api_break_3_0_QgsSymbolLayer} QgsSymbolLayer (renamed from QgsSymbolLayerV2) {#qgis_api_break_3_0_QgsSymbolLayer}
Expand Down Expand Up @@ -2146,6 +2153,7 @@ QgsSymbolRenderContext (renamed from QgsSymbolV2RenderContext) {#qgis_api
- The constructor, setRenderHints() and renderHints() now accept and return a QgsSymbol::RenderHints flag rather - The constructor, setRenderHints() and renderHints() now accept and return a QgsSymbol::RenderHints flag rather
than an integer value than an integer value
- fields() now returns a QgsFields value, not a pointer. - fields() now returns a QgsFields value, not a pointer.
- alpha() and setAlpha() were removed. Use opacity() and setOpacity() instead.




QgsSymbolLayerUtils (renamed from QgsSymbolLayerUtilsV2) {#qgis_api_break_3_0_QgsSymbolLayerUtils} QgsSymbolLayerUtils (renamed from QgsSymbolLayerUtilsV2) {#qgis_api_break_3_0_QgsSymbolLayerUtils}
Expand Down
12 changes: 2 additions & 10 deletions python/core/symbology-ng/qgsfillsymbollayer.sip
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -550,16 +550,8 @@ class QgsRasterFillSymbolLayer: QgsImageFillSymbolLayer
*/ */
FillCoordinateMode coordinateMode() const; FillCoordinateMode coordinateMode() const;


/** Sets the opacity for the raster image used in the fill. void setOpacity( const double opacity );
* @param alpha opacity value between 0 (fully transparent) and 1 (fully opaque) double opacity() const;
* @see alpha
*/
void setAlpha( const double alpha );
/** The opacity for the raster image used in the fill.
* @returns opacity value between 0 (fully transparent) and 1 (fully opaque)
* @see setAlpha
*/
double alpha() const;


/** Sets the offset for the fill. /** Sets the offset for the fill.
* @param offset offset for fill * @param offset offset for fill
Expand Down
24 changes: 5 additions & 19 deletions python/core/symbology-ng/qgssymbol.sip
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -175,10 +175,8 @@ class QgsSymbol
QgsMapUnitScale mapUnitScale() const; QgsMapUnitScale mapUnitScale() const;
void setMapUnitScale( const QgsMapUnitScale &scale ); void setMapUnitScale( const QgsMapUnitScale &scale );


//! Get alpha transparency 1 for opaque, 0 for invisible qreal opacity() const;
qreal alpha() const; void setOpacity( qreal opacity );
//! Set alpha transparency 1 for opaque, 0 for invisible
void setAlpha( qreal alpha );


/** Sets rendering hint flags for the symbol. /** Sets rendering hint flags for the symbol.
* @see renderHints() * @see renderHints()
Expand Down Expand Up @@ -303,17 +301,7 @@ class QgsSymbolRenderContext


public: public:


/** Constructor for QgsSymbolRenderContext QgsSymbolRenderContext( QgsRenderContext &c, QgsUnitTypes::RenderUnit u, qreal opacity = 1.0, bool selected = false, QgsSymbol::RenderHints renderHints = 0, const QgsFeature *f = 0, const QgsFields &fields = QgsFields(), const QgsMapUnitScale &mapUnitScale = QgsMapUnitScale() );
* @param c
* @param u
* @param alpha
* @param selected set to true if symbol should be drawn in a "selected" state
* @param renderHints flags controlling rendering behavior
* @param f
* @param fields
* @param mapUnitScale
*/
QgsSymbolRenderContext( QgsRenderContext &c, QgsUnitTypes::RenderUnit u, qreal alpha = 1.0, bool selected = false, QgsSymbol::RenderHints renderHints = 0, const QgsFeature *f = 0, const QgsFields &fields = QgsFields(), const QgsMapUnitScale &mapUnitScale = QgsMapUnitScale() );
~QgsSymbolRenderContext(); ~QgsSymbolRenderContext();


QgsRenderContext &renderContext(); QgsRenderContext &renderContext();
Expand All @@ -335,10 +323,8 @@ class QgsSymbolRenderContext
QgsMapUnitScale mapUnitScale() const; QgsMapUnitScale mapUnitScale() const;
void setMapUnitScale( const QgsMapUnitScale &scale ); void setMapUnitScale( const QgsMapUnitScale &scale );


//! Get alpha transparency 1 for opaque, 0 for invisible qreal opacity() const;
qreal alpha() const; void setOpacity( qreal opacity );
//! Set alpha transparency 1 for opaque, 0 for invisible
void setAlpha( qreal alpha );


bool selected() const; bool selected() const;
void setSelected( bool selected ); void setSelected( bool selected );
Expand Down
1 change: 0 additions & 1 deletion python/gui/symbology-ng/qgssymbolslistwidget.sip
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class QgsSymbolsListWidget : QWidget
void saveSymbol(); void saveSymbol();
void symbolAddedToStyle( const QString &name, QgsSymbol *symbol ); void symbolAddedToStyle( const QString &name, QgsSymbol *symbol );
void on_mSymbolUnitWidget_changed(); void on_mSymbolUnitWidget_changed();
void on_mTransparencySlider_valueChanged( int value );


//! Pupulates the groups combo box with available tags and smartgroups //! Pupulates the groups combo box with available tags and smartgroups
void populateGroups(); void populateGroups();
Expand Down
12 changes: 10 additions & 2 deletions src/app/qgsprojectproperties.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Line" ), cboStyleLine->currentText() ); QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Line" ), cboStyleLine->currentText() );
QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Fill" ), cboStyleFill->currentText() ); QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Fill" ), cboStyleFill->currentText() );
QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/ColorRamp" ), cboStyleColorRamp->currentText() ); QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/ColorRamp" ), cboStyleColorRamp->currentText() );
QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/AlphaInt" ), ( int )( 255 - ( mTransparencySlider->value() * 2.55 ) ) ); QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Opacity" ), 1.0 - mTransparencySlider->value() / 100.0 );
QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/RandomColors" ), cbxStyleRandomColors->isChecked() ); QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/RandomColors" ), cbxStyleRandomColors->isChecked() );
if ( mTreeProjectColors->isDirty() ) if ( mTreeProjectColors->isDirty() )
{ {
Expand Down Expand Up @@ -1687,7 +1687,15 @@ void QgsProjectProperties::populateStyles()
cbxStyleRandomColors->setChecked( QgsProject::instance()->readBoolEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/RandomColors" ), true ) ); cbxStyleRandomColors->setChecked( QgsProject::instance()->readBoolEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/RandomColors" ), true ) );


// alpha transparency // alpha transparency
int transparencyInt = ( 255 - QgsProject::instance()->readNumEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/AlphaInt" ), 255 ) ) / 2.55; int transparencyInt = 255;
bool ok = false;
double alpha = QgsProject::instance()->readDoubleEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/AlphaInt" ), 255, &ok );
if ( ok )
transparencyInt = alpha;
double newOpacity = QgsProject::instance()->readDoubleEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Opacity" ), 1.0, &ok );
if ( ok )
transparencyInt = 255 - newOpacity * 255.0;

mTransparencySlider->setValue( transparencyInt ); mTransparencySlider->setValue( transparencyInt );
} }


Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposermapoverview.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void QgsComposerMapOverview::createDefaultFrameSymbol()
properties.insert( QStringLiteral( "style" ), QStringLiteral( "solid" ) ); properties.insert( QStringLiteral( "style" ), QStringLiteral( "solid" ) );
properties.insert( QStringLiteral( "style_border" ), QStringLiteral( "no" ) ); properties.insert( QStringLiteral( "style_border" ), QStringLiteral( "no" ) );
mFrameSymbol = QgsFillSymbol::createSimple( properties ); mFrameSymbol = QgsFillSymbol::createSimple( properties );
mFrameSymbol->setAlpha( 0.3 ); mFrameSymbol->setOpacity( 0.3 );
} }


QgsComposerMapOverview::~QgsComposerMapOverview() QgsComposerMapOverview::~QgsComposerMapOverview()
Expand Down
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfexport.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ void QgsDxfExport::writeBlocks()
continue; continue;


// if point symbol layer and no data defined properties: write block // if point symbol layer and no data defined properties: write block
QgsSymbolRenderContext ctx( ct, QgsUnitTypes::RenderMapUnits, slIt->second->alpha(), false, slIt->second->renderHints(), nullptr ); QgsSymbolRenderContext ctx( ct, QgsUnitTypes::RenderMapUnits, slIt->second->opacity(), false, slIt->second->renderHints(), nullptr );
ml->startRender( ctx ); ml->startRender( ctx );


// markers with data defined properties are inserted inline // markers with data defined properties are inserted inline
Expand Down
63 changes: 32 additions & 31 deletions src/core/symbology-ng/qgsfillsymbollayer.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -232,20 +232,20 @@ QString QgsSimpleFillSymbolLayer::layerType() const
void QgsSimpleFillSymbolLayer::startRender( QgsSymbolRenderContext &context ) void QgsSimpleFillSymbolLayer::startRender( QgsSymbolRenderContext &context )
{ {
QColor fillColor = mColor; QColor fillColor = mColor;
fillColor.setAlphaF( context.alpha() * mColor.alphaF() ); fillColor.setAlphaF( context.opacity() * mColor.alphaF() );
mBrush = QBrush( fillColor, mBrushStyle ); mBrush = QBrush( fillColor, mBrushStyle );


QColor selColor = context.renderContext().selectionColor(); QColor selColor = context.renderContext().selectionColor();
QColor selPenColor = selColor == mColor ? selColor : mStrokeColor; QColor selPenColor = selColor == mColor ? selColor : mStrokeColor;
if ( ! SELECTION_IS_OPAQUE ) selColor.setAlphaF( context.alpha() ); if ( ! SELECTION_IS_OPAQUE ) selColor.setAlphaF( context.opacity() );
mSelBrush = QBrush( selColor ); mSelBrush = QBrush( selColor );
// N.B. unless a "selection line color" is implemented in addition to the "selection color" option // N.B. unless a "selection line color" is implemented in addition to the "selection color" option
// this would mean symbols with "no fill" look the same whether or not they are selected // this would mean symbols with "no fill" look the same whether or not they are selected
if ( SELECT_FILL_STYLE ) if ( SELECT_FILL_STYLE )
mSelBrush.setStyle( mBrushStyle ); mSelBrush.setStyle( mBrushStyle );


QColor strokeColor = mStrokeColor; QColor strokeColor = mStrokeColor;
strokeColor.setAlphaF( context.alpha() * mStrokeColor.alphaF() ); strokeColor.setAlphaF( context.opacity() * mStrokeColor.alphaF() );
mPen = QPen( strokeColor ); mPen = QPen( strokeColor );
mSelPen = QPen( selPenColor ); mSelPen = QPen( selPenColor );
mPen.setStyle( mStrokeStyle ); mPen.setStyle( mStrokeStyle );
Expand Down Expand Up @@ -767,9 +767,9 @@ void QgsGradientFillSymbolLayer::applyGradient( const QgsSymbolRenderContext &co
{ {
//update alpha of gradient colors //update alpha of gradient colors
QColor fillColor = color; QColor fillColor = color;
fillColor.setAlphaF( context.alpha() * fillColor.alphaF() ); fillColor.setAlphaF( context.opacity() * fillColor.alphaF() );
QColor fillColor2 = color2; QColor fillColor2 = color2;
fillColor2.setAlphaF( context.alpha() * fillColor2.alphaF() ); fillColor2.setAlphaF( context.opacity() * fillColor2.alphaF() );


//rotate reference points //rotate reference points
QPointF rotatedReferencePoint1 = !qgsDoubleNear( angle, 0.0 ) ? rotateReferencePoint( referencePoint1, angle ) : referencePoint1; QPointF rotatedReferencePoint1 = !qgsDoubleNear( angle, 0.0 ) ? rotateReferencePoint( referencePoint1, angle ) : referencePoint1;
Expand Down Expand Up @@ -817,7 +817,7 @@ void QgsGradientFillSymbolLayer::applyGradient( const QgsSymbolRenderContext &co
{ {
//color ramp gradient //color ramp gradient
QgsGradientColorRamp *gradRamp = static_cast<QgsGradientColorRamp *>( gradientRamp ); QgsGradientColorRamp *gradRamp = static_cast<QgsGradientColorRamp *>( gradientRamp );
gradRamp->addStopsToGradient( &gradient, context.alpha() ); gradRamp->addStopsToGradient( &gradient, context.opacity() );
} }
else else
{ {
Expand All @@ -833,7 +833,8 @@ void QgsGradientFillSymbolLayer::applyGradient( const QgsSymbolRenderContext &co
void QgsGradientFillSymbolLayer::startRender( QgsSymbolRenderContext &context ) void QgsGradientFillSymbolLayer::startRender( QgsSymbolRenderContext &context )
{ {
QColor selColor = context.renderContext().selectionColor(); QColor selColor = context.renderContext().selectionColor();
if ( ! SELECTION_IS_OPAQUE ) selColor.setAlphaF( context.alpha() ); if ( ! SELECTION_IS_OPAQUE )
selColor.setAlphaF( context.opacity() );
mSelBrush = QBrush( selColor ); mSelBrush = QBrush( selColor );
} }


Expand Down Expand Up @@ -1125,7 +1126,8 @@ void QgsShapeburstFillSymbolLayer::startRender( QgsSymbolRenderContext &context
{ {
//TODO - check this //TODO - check this
QColor selColor = context.renderContext().selectionColor(); QColor selColor = context.renderContext().selectionColor();
if ( ! SELECTION_IS_OPAQUE ) selColor.setAlphaF( context.alpha() ); if ( ! SELECTION_IS_OPAQUE )
selColor.setAlphaF( context.opacity() );
mSelBrush = QBrush( selColor ); mSelBrush = QBrush( selColor );
} }


Expand Down Expand Up @@ -1237,7 +1239,7 @@ void QgsShapeburstFillSymbolLayer::renderPolygon( const QPolygonF &points, QList


//copy distance transform values back to QImage, shading by appropriate color ramp //copy distance transform values back to QImage, shading by appropriate color ramp
dtArrayToQImage( dtArray, fillImage, mColorType == QgsShapeburstFillSymbolLayer::SimpleTwoColor ? mTwoColorGradientRamp : mGradientRamp, dtArrayToQImage( dtArray, fillImage, mColorType == QgsShapeburstFillSymbolLayer::SimpleTwoColor ? mTwoColorGradientRamp : mGradientRamp,
context.alpha(), useWholeShape, outputPixelMaxDist ); context.opacity(), useWholeShape, outputPixelMaxDist );


//clean up some variables //clean up some variables
delete [] dtArray; delete [] dtArray;
Expand Down Expand Up @@ -1962,10 +1964,10 @@ void QgsSVGFillSymbolLayer::applyPattern( QBrush &brush, const QString &svgFileP
} }


QTransform brushTransform; QTransform brushTransform;
if ( !qgsDoubleNear( context.alpha(), 1.0 ) ) if ( !qgsDoubleNear( context.opacity(), 1.0 ) )
{ {
QImage transparentImage = fitsInCache ? patternImage.copy() : mSvgPattern->copy(); QImage transparentImage = fitsInCache ? patternImage.copy() : mSvgPattern->copy();
QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.alpha() ); QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.opacity() );
brush.setTextureImage( transparentImage ); brush.setTextureImage( transparentImage );
} }
else else
Expand Down Expand Up @@ -2771,10 +2773,10 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolRenderContext &
patternImage = patternImage.copy( xBuffer, yBuffer, patternImage.width() - 2 * xBuffer, patternImage.height() - 2 * yBuffer ); patternImage = patternImage.copy( xBuffer, yBuffer, patternImage.width() - 2 * xBuffer, patternImage.height() - 2 * yBuffer );


//set image to mBrush //set image to mBrush
if ( !qgsDoubleNear( context.alpha(), 1.0 ) ) if ( !qgsDoubleNear( context.opacity(), 1.0 ) )
{ {
QImage transparentImage = patternImage.copy(); QImage transparentImage = patternImage.copy();
QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.alpha() ); QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.opacity() );
brush.setTextureImage( transparentImage ); brush.setTextureImage( transparentImage );
} }
else else
Expand Down Expand Up @@ -3185,10 +3187,10 @@ void QgsPointPatternFillSymbolLayer::applyPattern( const QgsSymbolRenderContext
mMarkerSymbol->stopRender( pointRenderContext ); mMarkerSymbol->stopRender( pointRenderContext );
} }


if ( !qgsDoubleNear( context.alpha(), 1.0 ) ) if ( !qgsDoubleNear( context.opacity(), 1.0 ) )
{ {
QImage transparentImage = patternImage.copy(); QImage transparentImage = patternImage.copy();
QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.alpha() ); QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.opacity() );
brush.setTextureImage( transparentImage ); brush.setTextureImage( transparentImage );
} }
else else
Expand Down Expand Up @@ -3418,7 +3420,7 @@ QColor QgsCentroidFillSymbolLayer::color() const


void QgsCentroidFillSymbolLayer::startRender( QgsSymbolRenderContext &context ) void QgsCentroidFillSymbolLayer::startRender( QgsSymbolRenderContext &context )
{ {
mMarker->setAlpha( context.alpha() ); mMarker->setOpacity( context.opacity() );
mMarker->startRender( context.renderContext(), context.fields() ); mMarker->startRender( context.renderContext(), context.fields() );


mCurrentFeatureId = -1; mCurrentFeatureId = -1;
Expand Down Expand Up @@ -3590,7 +3592,6 @@ QgsRasterFillSymbolLayer::QgsRasterFillSymbolLayer( const QString &imageFilePath
: QgsImageFillSymbolLayer() : QgsImageFillSymbolLayer()
, mImageFilePath( imageFilePath ) , mImageFilePath( imageFilePath )
, mCoordinateMode( QgsRasterFillSymbolLayer::Feature ) , mCoordinateMode( QgsRasterFillSymbolLayer::Feature )
, mAlpha( 1.0 )
, mOffsetUnit( QgsUnitTypes::RenderMillimeters ) , mOffsetUnit( QgsUnitTypes::RenderMillimeters )
, mWidth( 0.0 ) , mWidth( 0.0 )
, mWidthUnit( QgsUnitTypes::RenderPixels ) , mWidthUnit( QgsUnitTypes::RenderPixels )
Expand Down Expand Up @@ -3633,7 +3634,7 @@ QgsSymbolLayer *QgsRasterFillSymbolLayer::create( const QgsStringMap &properties
} }
QgsRasterFillSymbolLayer *symbolLayer = new QgsRasterFillSymbolLayer( imagePath ); QgsRasterFillSymbolLayer *symbolLayer = new QgsRasterFillSymbolLayer( imagePath );
symbolLayer->setCoordinateMode( mode ); symbolLayer->setCoordinateMode( mode );
symbolLayer->setAlpha( alpha ); symbolLayer->setOpacity( alpha );
symbolLayer->setOffset( offset ); symbolLayer->setOffset( offset );
symbolLayer->setAngle( angle ); symbolLayer->setAngle( angle );
symbolLayer->setWidth( width ); symbolLayer->setWidth( width );
Expand Down Expand Up @@ -3701,7 +3702,7 @@ void QgsRasterFillSymbolLayer::renderPolygon( const QPolygonF &points, QList<QPo


void QgsRasterFillSymbolLayer::startRender( QgsSymbolRenderContext &context ) void QgsRasterFillSymbolLayer::startRender( QgsSymbolRenderContext &context )
{ {
applyPattern( mBrush, mImageFilePath, mWidth, mAlpha, context ); applyPattern( mBrush, mImageFilePath, mWidth, mOpacity, context );
} }


void QgsRasterFillSymbolLayer::stopRender( QgsSymbolRenderContext &context ) void QgsRasterFillSymbolLayer::stopRender( QgsSymbolRenderContext &context )
Expand All @@ -3714,7 +3715,7 @@ QgsStringMap QgsRasterFillSymbolLayer::properties() const
QgsStringMap map; QgsStringMap map;
map[QStringLiteral( "imageFile" )] = mImageFilePath; map[QStringLiteral( "imageFile" )] = mImageFilePath;
map[QStringLiteral( "coordinate_mode" )] = QString::number( mCoordinateMode ); map[QStringLiteral( "coordinate_mode" )] = QString::number( mCoordinateMode );
map[QStringLiteral( "alpha" )] = QString::number( mAlpha ); map[QStringLiteral( "alpha" )] = QString::number( mOpacity );
map[QStringLiteral( "offset" )] = QgsSymbolLayerUtils::encodePoint( mOffset ); map[QStringLiteral( "offset" )] = QgsSymbolLayerUtils::encodePoint( mOffset );
map[QStringLiteral( "offset_unit" )] = QgsUnitTypes::encodeUnit( mOffsetUnit ); map[QStringLiteral( "offset_unit" )] = QgsUnitTypes::encodeUnit( mOffsetUnit );
map[QStringLiteral( "offset_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mOffsetMapUnitScale ); map[QStringLiteral( "offset_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mOffsetMapUnitScale );
Expand All @@ -3729,7 +3730,7 @@ QgsRasterFillSymbolLayer *QgsRasterFillSymbolLayer::clone() const
{ {
QgsRasterFillSymbolLayer *sl = new QgsRasterFillSymbolLayer( mImageFilePath ); QgsRasterFillSymbolLayer *sl = new QgsRasterFillSymbolLayer( mImageFilePath );
sl->setCoordinateMode( mCoordinateMode ); sl->setCoordinateMode( mCoordinateMode );
sl->setAlpha( mAlpha ); sl->setOpacity( mOpacity );
sl->setOffset( mOffset ); sl->setOffset( mOffset );
sl->setOffsetUnit( mOffsetUnit ); sl->setOffsetUnit( mOffsetUnit );
sl->setOffsetMapUnitScale( mOffsetMapUnitScale ); sl->setOffsetMapUnitScale( mOffsetMapUnitScale );
Expand Down Expand Up @@ -3757,9 +3758,9 @@ void QgsRasterFillSymbolLayer::setCoordinateMode( const QgsRasterFillSymbolLayer
mCoordinateMode = mode; mCoordinateMode = mode;
} }


void QgsRasterFillSymbolLayer::setAlpha( const double alpha ) void QgsRasterFillSymbolLayer::setOpacity( const double opacity )
{ {
mAlpha = alpha; mOpacity = opacity;
} }


void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext &context ) void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext &context )
Expand All @@ -3769,10 +3770,10 @@ void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext


bool hasWidthExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyWidth ); bool hasWidthExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyWidth );
bool hasFileExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyFile ); bool hasFileExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyFile );
bool hasAlphaExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyAlpha ); bool hasOpacityExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyOpacity );
bool hasAngleExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyAngle ); bool hasAngleExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyAngle );


if ( !hasWidthExpression && !hasAngleExpression && !hasAlphaExpression && !hasFileExpression ) if ( !hasWidthExpression && !hasAngleExpression && !hasOpacityExpression && !hasFileExpression )
{ {
return; //no data defined settings return; //no data defined settings
} }
Expand All @@ -3786,7 +3787,7 @@ void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext
mNextAngle = nextAngle; mNextAngle = nextAngle;
} }


if ( !hasWidthExpression && !hasAlphaExpression && !hasFileExpression ) if ( !hasWidthExpression && !hasOpacityExpression && !hasFileExpression )
{ {
return; //nothing further to do return; //nothing further to do
} }
Expand All @@ -3797,19 +3798,19 @@ void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext
context.setOriginalValueVariable( mWidth ); context.setOriginalValueVariable( mWidth );
width = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyWidth, context.renderContext().expressionContext(), width ); width = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyWidth, context.renderContext().expressionContext(), width );
} }
double alpha = mAlpha; double opacity = mOpacity;
if ( hasAlphaExpression ) if ( hasOpacityExpression )
{ {
context.setOriginalValueVariable( mAlpha ); context.setOriginalValueVariable( mOpacity );
alpha = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyAlpha, context.renderContext().expressionContext(), alpha ); opacity = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyOpacity, context.renderContext().expressionContext(), opacity * 100 ) / 100.0;
} }
QString file = mImageFilePath; QString file = mImageFilePath;
if ( hasFileExpression ) if ( hasFileExpression )
{ {
context.setOriginalValueVariable( mImageFilePath ); context.setOriginalValueVariable( mImageFilePath );
file = mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyFile, context.renderContext().expressionContext(), file ); file = mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyFile, context.renderContext().expressionContext(), file );
} }
applyPattern( mBrush, file, width, alpha, context ); applyPattern( mBrush, file, width, opacity, context );
} }


void QgsRasterFillSymbolLayer::applyPattern( QBrush &brush, const QString &imageFilePath, const double width, const double alpha, const QgsSymbolRenderContext &context ) void QgsRasterFillSymbolLayer::applyPattern( QBrush &brush, const QString &imageFilePath, const double width, const double alpha, const QgsSymbolRenderContext &context )
Expand Down
Loading

0 comments on commit a326224

Please sign in to comment.