diff --git a/doc/api_break.dox b/doc/api_break.dox index b344f68229d..83dbc71973f 100644 --- a/doc/api_break.dox +++ b/doc/api_break.dox @@ -1837,6 +1837,12 @@ QProgressDialog argument will need to be updated using manually created connecti 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} ------------------ @@ -2108,6 +2114,7 @@ than an integer value - usedAttributes() now requires a QgsRenderContext argument. - setDataDefinedAngle(), dataDefinedAngle(), setDataDefinedSize(), dataDefinedSize(), setDataDefinedWidth() and dataDefinedWidth() 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} @@ -2146,6 +2153,7 @@ QgsSymbolRenderContext (renamed from QgsSymbolV2RenderContext) {#qgis_api - The constructor, setRenderHints() and renderHints() now accept and return a QgsSymbol::RenderHints flag rather than an integer value - 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} diff --git a/python/core/symbology-ng/qgsfillsymbollayer.sip b/python/core/symbology-ng/qgsfillsymbollayer.sip index d3ed7e271c2..9b72414450e 100644 --- a/python/core/symbology-ng/qgsfillsymbollayer.sip +++ b/python/core/symbology-ng/qgsfillsymbollayer.sip @@ -550,16 +550,8 @@ class QgsRasterFillSymbolLayer: QgsImageFillSymbolLayer */ FillCoordinateMode coordinateMode() const; - /** Sets the opacity for the raster image used in the fill. - * @param alpha opacity value between 0 (fully transparent) and 1 (fully opaque) - * @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; + void setOpacity( const double opacity ); + double opacity() const; /** Sets the offset for the fill. * @param offset offset for fill diff --git a/python/core/symbology-ng/qgssymbol.sip b/python/core/symbology-ng/qgssymbol.sip index 88d8432da6c..86717d1633a 100644 --- a/python/core/symbology-ng/qgssymbol.sip +++ b/python/core/symbology-ng/qgssymbol.sip @@ -175,10 +175,8 @@ class QgsSymbol QgsMapUnitScale mapUnitScale() const; void setMapUnitScale( const QgsMapUnitScale &scale ); - //! Get alpha transparency 1 for opaque, 0 for invisible - qreal alpha() const; - //! Set alpha transparency 1 for opaque, 0 for invisible - void setAlpha( qreal alpha ); + qreal opacity() const; + void setOpacity( qreal opacity ); /** Sets rendering hint flags for the symbol. * @see renderHints() @@ -303,17 +301,7 @@ class QgsSymbolRenderContext public: - /** Constructor for QgsSymbolRenderContext - * @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( 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() ); ~QgsSymbolRenderContext(); QgsRenderContext &renderContext(); @@ -335,10 +323,8 @@ class QgsSymbolRenderContext QgsMapUnitScale mapUnitScale() const; void setMapUnitScale( const QgsMapUnitScale &scale ); - //! Get alpha transparency 1 for opaque, 0 for invisible - qreal alpha() const; - //! Set alpha transparency 1 for opaque, 0 for invisible - void setAlpha( qreal alpha ); + qreal opacity() const; + void setOpacity( qreal opacity ); bool selected() const; void setSelected( bool selected ); diff --git a/python/gui/symbology-ng/qgssymbolslistwidget.sip b/python/gui/symbology-ng/qgssymbolslistwidget.sip index 48746c4154e..695893777a6 100644 --- a/python/gui/symbology-ng/qgssymbolslistwidget.sip +++ b/python/gui/symbology-ng/qgssymbolslistwidget.sip @@ -35,7 +35,6 @@ class QgsSymbolsListWidget : QWidget void saveSymbol(); void symbolAddedToStyle( const QString &name, QgsSymbol *symbol ); void on_mSymbolUnitWidget_changed(); - void on_mTransparencySlider_valueChanged( int value ); //! Pupulates the groups combo box with available tags and smartgroups void populateGroups(); diff --git a/src/app/qgsprojectproperties.cpp b/src/app/qgsprojectproperties.cpp index a1050922c90..a9d6006b147 100644 --- a/src/app/qgsprojectproperties.cpp +++ b/src/app/qgsprojectproperties.cpp @@ -1133,7 +1133,7 @@ void QgsProjectProperties::apply() QgsProject::instance()->writeEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Line" ), cboStyleLine->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( "/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() ); if ( mTreeProjectColors->isDirty() ) { @@ -1687,7 +1687,15 @@ void QgsProjectProperties::populateStyles() cbxStyleRandomColors->setChecked( QgsProject::instance()->readBoolEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/RandomColors" ), true ) ); // 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 ); } diff --git a/src/core/composer/qgscomposermapoverview.cpp b/src/core/composer/qgscomposermapoverview.cpp index cdb3694d8c3..123d6a05108 100644 --- a/src/core/composer/qgscomposermapoverview.cpp +++ b/src/core/composer/qgscomposermapoverview.cpp @@ -58,7 +58,7 @@ void QgsComposerMapOverview::createDefaultFrameSymbol() properties.insert( QStringLiteral( "style" ), QStringLiteral( "solid" ) ); properties.insert( QStringLiteral( "style_border" ), QStringLiteral( "no" ) ); mFrameSymbol = QgsFillSymbol::createSimple( properties ); - mFrameSymbol->setAlpha( 0.3 ); + mFrameSymbol->setOpacity( 0.3 ); } QgsComposerMapOverview::~QgsComposerMapOverview() diff --git a/src/core/dxf/qgsdxfexport.cpp b/src/core/dxf/qgsdxfexport.cpp index d639447b8ae..f776304892a 100644 --- a/src/core/dxf/qgsdxfexport.cpp +++ b/src/core/dxf/qgsdxfexport.cpp @@ -897,7 +897,7 @@ void QgsDxfExport::writeBlocks() continue; // 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 ); // markers with data defined properties are inserted inline diff --git a/src/core/symbology-ng/qgsfillsymbollayer.cpp b/src/core/symbology-ng/qgsfillsymbollayer.cpp index 7efdaa4edd5..777f15cc04f 100644 --- a/src/core/symbology-ng/qgsfillsymbollayer.cpp +++ b/src/core/symbology-ng/qgsfillsymbollayer.cpp @@ -232,12 +232,12 @@ QString QgsSimpleFillSymbolLayer::layerType() const void QgsSimpleFillSymbolLayer::startRender( QgsSymbolRenderContext &context ) { QColor fillColor = mColor; - fillColor.setAlphaF( context.alpha() * mColor.alphaF() ); + fillColor.setAlphaF( context.opacity() * mColor.alphaF() ); mBrush = QBrush( fillColor, mBrushStyle ); QColor selColor = context.renderContext().selectionColor(); 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 ); // 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 @@ -245,7 +245,7 @@ void QgsSimpleFillSymbolLayer::startRender( QgsSymbolRenderContext &context ) mSelBrush.setStyle( mBrushStyle ); QColor strokeColor = mStrokeColor; - strokeColor.setAlphaF( context.alpha() * mStrokeColor.alphaF() ); + strokeColor.setAlphaF( context.opacity() * mStrokeColor.alphaF() ); mPen = QPen( strokeColor ); mSelPen = QPen( selPenColor ); mPen.setStyle( mStrokeStyle ); @@ -767,9 +767,9 @@ void QgsGradientFillSymbolLayer::applyGradient( const QgsSymbolRenderContext &co { //update alpha of gradient colors QColor fillColor = color; - fillColor.setAlphaF( context.alpha() * fillColor.alphaF() ); + fillColor.setAlphaF( context.opacity() * fillColor.alphaF() ); QColor fillColor2 = color2; - fillColor2.setAlphaF( context.alpha() * fillColor2.alphaF() ); + fillColor2.setAlphaF( context.opacity() * fillColor2.alphaF() ); //rotate reference points QPointF rotatedReferencePoint1 = !qgsDoubleNear( angle, 0.0 ) ? rotateReferencePoint( referencePoint1, angle ) : referencePoint1; @@ -817,7 +817,7 @@ void QgsGradientFillSymbolLayer::applyGradient( const QgsSymbolRenderContext &co { //color ramp gradient QgsGradientColorRamp *gradRamp = static_cast( gradientRamp ); - gradRamp->addStopsToGradient( &gradient, context.alpha() ); + gradRamp->addStopsToGradient( &gradient, context.opacity() ); } else { @@ -833,7 +833,8 @@ void QgsGradientFillSymbolLayer::applyGradient( const QgsSymbolRenderContext &co void QgsGradientFillSymbolLayer::startRender( QgsSymbolRenderContext &context ) { QColor selColor = context.renderContext().selectionColor(); - if ( ! SELECTION_IS_OPAQUE ) selColor.setAlphaF( context.alpha() ); + if ( ! SELECTION_IS_OPAQUE ) + selColor.setAlphaF( context.opacity() ); mSelBrush = QBrush( selColor ); } @@ -1125,7 +1126,8 @@ void QgsShapeburstFillSymbolLayer::startRender( QgsSymbolRenderContext &context { //TODO - check this QColor selColor = context.renderContext().selectionColor(); - if ( ! SELECTION_IS_OPAQUE ) selColor.setAlphaF( context.alpha() ); + if ( ! SELECTION_IS_OPAQUE ) + selColor.setAlphaF( context.opacity() ); mSelBrush = QBrush( selColor ); } @@ -1237,7 +1239,7 @@ void QgsShapeburstFillSymbolLayer::renderPolygon( const QPolygonF &points, QList //copy distance transform values back to QImage, shading by appropriate color ramp dtArrayToQImage( dtArray, fillImage, mColorType == QgsShapeburstFillSymbolLayer::SimpleTwoColor ? mTwoColorGradientRamp : mGradientRamp, - context.alpha(), useWholeShape, outputPixelMaxDist ); + context.opacity(), useWholeShape, outputPixelMaxDist ); //clean up some variables delete [] dtArray; @@ -1962,10 +1964,10 @@ void QgsSVGFillSymbolLayer::applyPattern( QBrush &brush, const QString &svgFileP } QTransform brushTransform; - if ( !qgsDoubleNear( context.alpha(), 1.0 ) ) + if ( !qgsDoubleNear( context.opacity(), 1.0 ) ) { QImage transparentImage = fitsInCache ? patternImage.copy() : mSvgPattern->copy(); - QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.alpha() ); + QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.opacity() ); brush.setTextureImage( transparentImage ); } else @@ -2771,10 +2773,10 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolRenderContext & patternImage = patternImage.copy( xBuffer, yBuffer, patternImage.width() - 2 * xBuffer, patternImage.height() - 2 * yBuffer ); //set image to mBrush - if ( !qgsDoubleNear( context.alpha(), 1.0 ) ) + if ( !qgsDoubleNear( context.opacity(), 1.0 ) ) { QImage transparentImage = patternImage.copy(); - QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.alpha() ); + QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.opacity() ); brush.setTextureImage( transparentImage ); } else @@ -3185,10 +3187,10 @@ void QgsPointPatternFillSymbolLayer::applyPattern( const QgsSymbolRenderContext mMarkerSymbol->stopRender( pointRenderContext ); } - if ( !qgsDoubleNear( context.alpha(), 1.0 ) ) + if ( !qgsDoubleNear( context.opacity(), 1.0 ) ) { QImage transparentImage = patternImage.copy(); - QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.alpha() ); + QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.opacity() ); brush.setTextureImage( transparentImage ); } else @@ -3418,7 +3420,7 @@ QColor QgsCentroidFillSymbolLayer::color() const void QgsCentroidFillSymbolLayer::startRender( QgsSymbolRenderContext &context ) { - mMarker->setAlpha( context.alpha() ); + mMarker->setOpacity( context.opacity() ); mMarker->startRender( context.renderContext(), context.fields() ); mCurrentFeatureId = -1; @@ -3590,7 +3592,6 @@ QgsRasterFillSymbolLayer::QgsRasterFillSymbolLayer( const QString &imageFilePath : QgsImageFillSymbolLayer() , mImageFilePath( imageFilePath ) , mCoordinateMode( QgsRasterFillSymbolLayer::Feature ) - , mAlpha( 1.0 ) , mOffsetUnit( QgsUnitTypes::RenderMillimeters ) , mWidth( 0.0 ) , mWidthUnit( QgsUnitTypes::RenderPixels ) @@ -3633,7 +3634,7 @@ QgsSymbolLayer *QgsRasterFillSymbolLayer::create( const QgsStringMap &properties } QgsRasterFillSymbolLayer *symbolLayer = new QgsRasterFillSymbolLayer( imagePath ); symbolLayer->setCoordinateMode( mode ); - symbolLayer->setAlpha( alpha ); + symbolLayer->setOpacity( alpha ); symbolLayer->setOffset( offset ); symbolLayer->setAngle( angle ); symbolLayer->setWidth( width ); @@ -3701,7 +3702,7 @@ void QgsRasterFillSymbolLayer::renderPolygon( const QPolygonF &points, QListsetCoordinateMode( mCoordinateMode ); - sl->setAlpha( mAlpha ); + sl->setOpacity( mOpacity ); sl->setOffset( mOffset ); sl->setOffsetUnit( mOffsetUnit ); sl->setOffsetMapUnitScale( mOffsetMapUnitScale ); @@ -3757,9 +3758,9 @@ void QgsRasterFillSymbolLayer::setCoordinateMode( const QgsRasterFillSymbolLayer mCoordinateMode = mode; } -void QgsRasterFillSymbolLayer::setAlpha( const double alpha ) +void QgsRasterFillSymbolLayer::setOpacity( const double opacity ) { - mAlpha = alpha; + mOpacity = opacity; } void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext &context ) @@ -3769,10 +3770,10 @@ void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext bool hasWidthExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyWidth ); bool hasFileExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyFile ); - bool hasAlphaExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyAlpha ); + bool hasOpacityExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyOpacity ); bool hasAngleExpression = mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyAngle ); - if ( !hasWidthExpression && !hasAngleExpression && !hasAlphaExpression && !hasFileExpression ) + if ( !hasWidthExpression && !hasAngleExpression && !hasOpacityExpression && !hasFileExpression ) { return; //no data defined settings } @@ -3786,7 +3787,7 @@ void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext mNextAngle = nextAngle; } - if ( !hasWidthExpression && !hasAlphaExpression && !hasFileExpression ) + if ( !hasWidthExpression && !hasOpacityExpression && !hasFileExpression ) { return; //nothing further to do } @@ -3797,11 +3798,11 @@ void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext context.setOriginalValueVariable( mWidth ); width = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyWidth, context.renderContext().expressionContext(), width ); } - double alpha = mAlpha; - if ( hasAlphaExpression ) + double opacity = mOpacity; + if ( hasOpacityExpression ) { - context.setOriginalValueVariable( mAlpha ); - alpha = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyAlpha, context.renderContext().expressionContext(), alpha ); + context.setOriginalValueVariable( mOpacity ); + opacity = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyOpacity, context.renderContext().expressionContext(), opacity * 100 ) / 100.0; } QString file = mImageFilePath; if ( hasFileExpression ) @@ -3809,7 +3810,7 @@ void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext context.setOriginalValueVariable( mImageFilePath ); 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 ) diff --git a/src/core/symbology-ng/qgsfillsymbollayer.h b/src/core/symbology-ng/qgsfillsymbollayer.h index 9992714f919..e06d5fbeb9f 100644 --- a/src/core/symbology-ng/qgsfillsymbollayer.h +++ b/src/core/symbology-ng/qgsfillsymbollayer.h @@ -694,17 +694,19 @@ class CORE_EXPORT QgsRasterFillSymbolLayer: public QgsImageFillSymbolLayer */ FillCoordinateMode coordinateMode() const { return mCoordinateMode; } - /** Sets the opacity for the raster image used in the fill. - * \param alpha opacity value between 0 (fully transparent) and 1 (fully opaque) - * \see alpha + /** + * Sets the \a opacity for the raster image used in the fill. + * \param opacity opacity value between 0 (fully transparent) and 1 (fully opaque) + * \see opacity() */ - void setAlpha( const double alpha ); + void setOpacity( const double opacity ); - /** The opacity for the raster image used in the fill. + /** + * Returns the opacity for the raster image used in the fill. * \returns opacity value between 0 (fully transparent) and 1 (fully opaque) - * \see setAlpha + * \see setOpacity() */ - double alpha() const { return mAlpha; } + double opacity() const { return mOpacity; } /** Sets the offset for the fill. * \param offset offset for fill @@ -809,7 +811,7 @@ class CORE_EXPORT QgsRasterFillSymbolLayer: public QgsImageFillSymbolLayer //! Path to the image file QString mImageFilePath; FillCoordinateMode mCoordinateMode; - double mAlpha; + double mOpacity = 1.0; QPointF mOffset; QgsUnitTypes::RenderUnit mOffsetUnit; @@ -824,7 +826,7 @@ class CORE_EXPORT QgsRasterFillSymbolLayer: public QgsImageFillSymbolLayer private: //! Applies the image pattern to the brush - void applyPattern( QBrush &brush, const QString &imageFilePath, const double width, const double alpha, + void applyPattern( QBrush &brush, const QString &imageFilePath, const double width, const double opacity, const QgsSymbolRenderContext &context ); }; diff --git a/src/core/symbology-ng/qgslinesymbollayer.cpp b/src/core/symbology-ng/qgslinesymbollayer.cpp index fc2e220bea1..a13e143b4e0 100644 --- a/src/core/symbology-ng/qgslinesymbollayer.cpp +++ b/src/core/symbology-ng/qgslinesymbollayer.cpp @@ -190,7 +190,7 @@ QString QgsSimpleLineSymbolLayer::layerType() const void QgsSimpleLineSymbolLayer::startRender( QgsSymbolRenderContext &context ) { QColor penColor = mColor; - penColor.setAlphaF( mColor.alphaF() * context.alpha() ); + penColor.setAlphaF( mColor.alphaF() * context.opacity() ); mPen.setColor( penColor ); double scaledWidth = context.renderContext().convertToPainterUnits( mWidth, mWidthUnit, mWidthMapUnitScale ); mPen.setWidthF( scaledWidth ); @@ -227,7 +227,7 @@ void QgsSimpleLineSymbolLayer::startRender( QgsSymbolRenderContext &context ) mSelPen = mPen; QColor selColor = context.renderContext().selectionColor(); if ( ! SELECTION_IS_OPAQUE ) - selColor.setAlphaF( context.alpha() ); + selColor.setAlphaF( context.opacity() ); mSelPen.setColor( selColor ); } @@ -800,7 +800,7 @@ QColor QgsMarkerLineSymbolLayer::color() const void QgsMarkerLineSymbolLayer::startRender( QgsSymbolRenderContext &context ) { - mMarker->setAlpha( context.alpha() ); + mMarker->setOpacity( context.opacity() ); // if being rotated, it gets initialized with every line segment QgsSymbol::RenderHints hints = 0; diff --git a/src/core/symbology-ng/qgsmarkersymbollayer.cpp b/src/core/symbology-ng/qgsmarkersymbollayer.cpp index 336d9553c93..c5b0ef3f8a6 100644 --- a/src/core/symbology-ng/qgsmarkersymbollayer.cpp +++ b/src/core/symbology-ng/qgsmarkersymbollayer.cpp @@ -802,8 +802,8 @@ void QgsSimpleMarkerSymbolLayer::startRender( QgsSymbolRenderContext &context ) QColor brushColor = mColor; QColor penColor = mStrokeColor; - brushColor.setAlphaF( mColor.alphaF() * context.alpha() ); - penColor.setAlphaF( mStrokeColor.alphaF() * context.alpha() ); + brushColor.setAlphaF( mColor.alphaF() * context.opacity() ); + penColor.setAlphaF( mStrokeColor.alphaF() * context.opacity() ); mBrush = QBrush( brushColor ); mPen = QPen( penColor ); @@ -813,10 +813,10 @@ void QgsSimpleMarkerSymbolLayer::startRender( QgsSymbolRenderContext &context ) QColor selBrushColor = context.renderContext().selectionColor(); QColor selPenColor = selBrushColor == mColor ? selBrushColor : mStrokeColor; - if ( context.alpha() < 1 ) + if ( context.opacity() < 1 ) { - selBrushColor.setAlphaF( context.alpha() ); - selPenColor.setAlphaF( context.alpha() ); + selBrushColor.setAlphaF( context.opacity() ); + selPenColor.setAlphaF( context.opacity() ); } mSelBrush = QBrush( selBrushColor ); mSelPen = QPen( selPenColor ); @@ -1979,10 +1979,10 @@ void QgsSvgMarkerSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext if ( fitsInCache && img.width() > 1 ) { //consider transparency - if ( !qgsDoubleNear( context.alpha(), 1.0 ) ) + if ( !qgsDoubleNear( context.opacity(), 1.0 ) ) { QImage transparentImage = img.copy(); - QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.alpha() ); + QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.opacity() ); p->drawImage( -transparentImage.width() / 2.0, -transparentImage.height() / 2.0, transparentImage ); hwRatio = static_cast< double >( transparentImage.height() ) / static_cast< double >( transparentImage.width() ); } @@ -1996,7 +1996,7 @@ void QgsSvgMarkerSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext if ( usePict || !fitsInCache ) { - p->setOpacity( context.alpha() ); + p->setOpacity( context.opacity() ); const QPicture &pct = QgsApplication::svgCache()->svgAsPicture( path, size, fillColor, strokeColor, strokeWidth, context.renderContext().scaleFactor(), context.renderContext().forceVectorOutput() ); @@ -2540,8 +2540,8 @@ void QgsFontMarkerSymbolLayer::startRender( QgsSymbolRenderContext &context ) QColor brushColor = mColor; QColor penColor = mStrokeColor; - brushColor.setAlphaF( mColor.alphaF() * context.alpha() ); - penColor.setAlphaF( mStrokeColor.alphaF() * context.alpha() ); + brushColor.setAlphaF( mColor.alphaF() * context.opacity() ); + penColor.setAlphaF( mStrokeColor.alphaF() * context.opacity() ); mBrush = QBrush( brushColor ); mPen = QPen( penColor ); @@ -2667,7 +2667,7 @@ void QgsFontMarkerSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContex brushColor = mDataDefinedProperties.valueAsColor( QgsSymbolLayer::PropertyFillColor, context.renderContext().expressionContext(), brushColor ); } brushColor = context.selected() ? context.renderContext().selectionColor() : brushColor; - brushColor.setAlphaF( brushColor.alphaF() * context.alpha() ); + brushColor.setAlphaF( brushColor.alphaF() * context.opacity() ); mBrush.setColor( brushColor ); QColor penColor = mStrokeColor; @@ -2676,7 +2676,7 @@ void QgsFontMarkerSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContex context.setOriginalValueVariable( QgsSymbolLayerUtils::encodeColor( mStrokeColor ) ); penColor = mDataDefinedProperties.valueAsColor( QgsSymbolLayer::PropertyStrokeColor, context.renderContext().expressionContext(), penColor ); } - penColor.setAlphaF( penColor.alphaF() * context.alpha() ); + penColor.setAlphaF( penColor.alphaF() * context.opacity() ); double penWidth = context.renderContext().convertToPainterUnits( mStrokeWidth, mStrokeWidthUnit, mStrokeWidthMapUnitScale ); if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyStrokeWidth ) ) diff --git a/src/core/symbology-ng/qgssymbol.cpp b/src/core/symbology-ng/qgssymbol.cpp index 6ab63e4913b..f57a4384f4e 100644 --- a/src/core/symbology-ng/qgssymbol.cpp +++ b/src/core/symbology-ng/qgssymbol.cpp @@ -79,7 +79,6 @@ QgsProperty scaleWholeSymbol( double scaleFactorX, double scaleFactorY, const Qg QgsSymbol::QgsSymbol( SymbolType type, const QgsSymbolLayerList &layers ) : mType( type ) , mLayers( layers ) - , mAlpha( 1.0 ) , mRenderHints( 0 ) , mClipFeaturesToExtent( true ) , mLayer( nullptr ) @@ -296,8 +295,17 @@ QgsSymbol *QgsSymbol::defaultSymbol( QgsWkbTypes::GeometryType geomType ) } } - // set alpha transparency - s->setAlpha( QgsProject::instance()->readDoubleEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/AlphaInt" ), 255 ) / 255.0 ); + // set opacity + double opacity = 1.0; + bool ok = false; + // upgrade old setting + double alpha = QgsProject::instance()->readDoubleEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/AlphaInt" ), 255, &ok ); + if ( ok ) + opacity = alpha / 255.0; + double newOpacity = QgsProject::instance()->readDoubleEntry( QStringLiteral( "DefaultStyles" ), QStringLiteral( "/Opacity" ), 1.0, &ok ); + if ( ok ) + opacity = newOpacity; + s->setOpacity( opacity ); // set random color, it project prefs allow if ( defaultSymbol == QLatin1String( "" ) || @@ -375,9 +383,9 @@ bool QgsSymbol::changeSymbolLayer( int index, QgsSymbolLayer *layer ) void QgsSymbol::startRender( QgsRenderContext &context, const QgsFields &fields ) { - mSymbolRenderContext.reset( new QgsSymbolRenderContext( context, outputUnit(), mAlpha, false, mRenderHints, nullptr, fields, mapUnitScale() ) ); + mSymbolRenderContext.reset( new QgsSymbolRenderContext( context, outputUnit(), mOpacity, false, mRenderHints, nullptr, fields, mapUnitScale() ) ); - QgsSymbolRenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints, nullptr, fields, mapUnitScale() ); + QgsSymbolRenderContext symbolContext( context, outputUnit(), mOpacity, false, mRenderHints, nullptr, fields, mapUnitScale() ); std::unique_ptr< QgsExpressionContextScope > scope( QgsExpressionContextUtils::updateSymbolScope( this, new QgsExpressionContextScope() ) ); mSymbolRenderContext->setExpressionContextScope( scope.release() ); @@ -435,7 +443,7 @@ void QgsSymbol::drawPreviewIcon( QPainter *painter, QSize size, QgsRenderContext { QgsRenderContext context = customContext ? *customContext : QgsRenderContext::fromQPainter( painter ); context.setForceVectorOutput( true ); - QgsSymbolRenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints, nullptr, QgsFields(), mapUnitScale() ); + QgsSymbolRenderContext symbolContext( context, outputUnit(), mOpacity, false, mRenderHints, nullptr, QgsFields(), mapUnitScale() ); Q_FOREACH ( QgsSymbolLayer *layer, mLayers ) { @@ -568,7 +576,7 @@ QString QgsSymbol::dump() const void QgsSymbol::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const { - props[ QStringLiteral( "alpha" )] = QString::number( alpha() ); + props[ QStringLiteral( "alpha" )] = QString::number( opacity() ); double scaleFactor = 1.0; props[ QStringLiteral( "uom" )] = QgsSymbolLayerUtils::encodeSldUom( outputUnit(), &scaleFactor ); props[ QStringLiteral( "uomScale" )] = ( !qgsDoubleNear( scaleFactor, 1.0 ) ? qgsDoubleToString( scaleFactor ) : QLatin1String( "" ) ); @@ -991,11 +999,11 @@ void QgsSymbol::renderVertexMarker( QPointF pt, QgsRenderContext &context, int c //////////////////// -QgsSymbolRenderContext::QgsSymbolRenderContext( QgsRenderContext &c, QgsUnitTypes::RenderUnit u, qreal alpha, bool selected, QgsSymbol::RenderHints renderHints, const QgsFeature *f, const QgsFields &fields, const QgsMapUnitScale &mapUnitScale ) +QgsSymbolRenderContext::QgsSymbolRenderContext( QgsRenderContext &c, QgsUnitTypes::RenderUnit u, qreal opacity, bool selected, QgsSymbol::RenderHints renderHints, const QgsFeature *f, const QgsFields &fields, const QgsMapUnitScale &mapUnitScale ) : mRenderContext( c ) , mOutputUnit( u ) , mMapUnitScale( mapUnitScale ) - , mAlpha( alpha ) + , mOpacity( opacity ) , mSelected( selected ) , mRenderHints( renderHints ) , mFeature( f ) @@ -1432,7 +1440,7 @@ void QgsMarkerSymbol::renderPointUsingLayer( QgsMarkerSymbolLayer *layer, QPoint void QgsMarkerSymbol::renderPoint( QPointF point, const QgsFeature *f, QgsRenderContext &context, int layerIdx, bool selected ) { - QgsSymbolRenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, QgsFields(), mapUnitScale() ); + QgsSymbolRenderContext symbolContext( context, outputUnit(), mOpacity, selected, mRenderHints, f, QgsFields(), mapUnitScale() ); symbolContext.setGeometryPartCount( symbolRenderContext()->geometryPartCount() ); symbolContext.setGeometryPartNum( symbolRenderContext()->geometryPartNum() ); @@ -1469,7 +1477,7 @@ void QgsMarkerSymbol::renderPoint( QPointF point, const QgsFeature *f, QgsRender QRectF QgsMarkerSymbol::bounds( QPointF point, QgsRenderContext &context, const QgsFeature &feature ) const { - QgsSymbolRenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints, &feature, feature.fields(), mapUnitScale() ); + QgsSymbolRenderContext symbolContext( context, outputUnit(), mOpacity, false, mRenderHints, &feature, feature.fields(), mapUnitScale() ); QRectF bound; Q_FOREACH ( QgsSymbolLayer *layer, mLayers ) @@ -1489,7 +1497,7 @@ QRectF QgsMarkerSymbol::bounds( QPointF point, QgsRenderContext &context, const QgsMarkerSymbol *QgsMarkerSymbol::clone() const { QgsMarkerSymbol *cloneSymbol = new QgsMarkerSymbol( cloneLayers() ); - cloneSymbol->setAlpha( mAlpha ); + cloneSymbol->setOpacity( mOpacity ); cloneSymbol->setLayer( mLayer ); cloneSymbol->setClipFeaturesToExtent( mClipFeaturesToExtent ); return cloneSymbol; @@ -1643,7 +1651,7 @@ void QgsLineSymbol::renderPolyline( const QPolygonF &points, const QgsFeature *f { //save old painter QPainter *renderPainter = context.painter(); - QgsSymbolRenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, QgsFields(), mapUnitScale() ); + QgsSymbolRenderContext symbolContext( context, outputUnit(), mOpacity, selected, mRenderHints, f, QgsFields(), mapUnitScale() ); symbolContext.setOriginalGeometryType( QgsWkbTypes::LineGeometry ); symbolContext.setGeometryPartCount( symbolRenderContext()->geometryPartCount() ); symbolContext.setGeometryPartNum( symbolRenderContext()->geometryPartNum() ); @@ -1706,7 +1714,7 @@ void QgsLineSymbol::renderPolylineUsingLayer( QgsLineSymbolLayer *layer, const Q QgsLineSymbol *QgsLineSymbol::clone() const { QgsLineSymbol *cloneSymbol = new QgsLineSymbol( cloneLayers() ); - cloneSymbol->setAlpha( mAlpha ); + cloneSymbol->setOpacity( mOpacity ); cloneSymbol->setLayer( mLayer ); cloneSymbol->setClipFeaturesToExtent( mClipFeaturesToExtent ); return cloneSymbol; @@ -1724,7 +1732,7 @@ QgsFillSymbol::QgsFillSymbol( const QgsSymbolLayerList &layers ) void QgsFillSymbol::renderPolygon( const QPolygonF &points, QList *rings, const QgsFeature *f, QgsRenderContext &context, int layerIdx, bool selected ) { - QgsSymbolRenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, QgsFields(), mapUnitScale() ); + QgsSymbolRenderContext symbolContext( context, outputUnit(), mOpacity, selected, mRenderHints, f, QgsFields(), mapUnitScale() ); symbolContext.setOriginalGeometryType( QgsWkbTypes::PolygonGeometry ); symbolContext.setGeometryPartCount( symbolRenderContext()->geometryPartCount() ); symbolContext.setGeometryPartNum( symbolRenderContext()->geometryPartNum() ); @@ -1824,7 +1832,7 @@ QList *QgsFillSymbol::translateRings( const QList *rings, QgsFillSymbol *QgsFillSymbol::clone() const { QgsFillSymbol *cloneSymbol = new QgsFillSymbol( cloneLayers() ); - cloneSymbol->setAlpha( mAlpha ); + cloneSymbol->setOpacity( mOpacity ); cloneSymbol->setLayer( mLayer ); cloneSymbol->setClipFeaturesToExtent( mClipFeaturesToExtent ); return cloneSymbol; diff --git a/src/core/symbology-ng/qgssymbol.h b/src/core/symbology-ng/qgssymbol.h index 76e373ba337..0e70454a8e0 100644 --- a/src/core/symbology-ng/qgssymbol.h +++ b/src/core/symbology-ng/qgssymbol.h @@ -225,10 +225,19 @@ class CORE_EXPORT QgsSymbol QgsMapUnitScale mapUnitScale() const; void setMapUnitScale( const QgsMapUnitScale &scale ); - //! Get alpha transparency 1 for opaque, 0 for invisible - qreal alpha() const { return mAlpha; } - //! Set alpha transparency 1 for opaque, 0 for invisible - void setAlpha( qreal alpha ) { mAlpha = alpha; } + /** + * Returns the opacity for the symbol. + * \returns opacity value between 0 (fully transparent) and 1 (fully opaque) + * \see setOpacity() + */ + qreal opacity() const { return mOpacity; } + + /** + * Sets the \a opacity for the symbol. + * \param opacity opacity value between 0 (fully transparent) and 1 (fully opaque) + * \see opacity() + */ + void setOpacity( qreal opacity ) { mOpacity = opacity; } /** Sets rendering hint flags for the symbol. * \see renderHints() @@ -354,7 +363,7 @@ class CORE_EXPORT QgsSymbol QgsSymbolLayerList mLayers; //! Symbol opacity (in the range 0 - 1) - qreal mAlpha; + qreal mOpacity = 1.0; RenderHints mRenderHints; bool mClipFeaturesToExtent; @@ -383,14 +392,14 @@ class CORE_EXPORT QgsSymbolRenderContext /** Constructor for QgsSymbolRenderContext * \param c * \param u - * \param alpha + * \param opacity value between 0 (fully transparent) and 1 (fully opaque) * \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 = nullptr, const QgsFields &fields = QgsFields(), const QgsMapUnitScale &mapUnitScale = QgsMapUnitScale() ); + QgsSymbolRenderContext( QgsRenderContext &c, QgsUnitTypes::RenderUnit u, qreal opacity = 1.0, bool selected = false, QgsSymbol::RenderHints renderHints = 0, const QgsFeature *f = nullptr, const QgsFields &fields = QgsFields(), const QgsMapUnitScale &mapUnitScale = QgsMapUnitScale() ); QgsRenderContext &renderContext() { return mRenderContext; } const QgsRenderContext &renderContext() const { return mRenderContext; } @@ -411,10 +420,19 @@ class CORE_EXPORT QgsSymbolRenderContext QgsMapUnitScale mapUnitScale() const { return mMapUnitScale; } void setMapUnitScale( const QgsMapUnitScale &scale ) { mMapUnitScale = scale; } - //! Get alpha transparency 1 for opaque, 0 for invisible - qreal alpha() const { return mAlpha; } - //! Set alpha transparency 1 for opaque, 0 for invisible - void setAlpha( qreal alpha ) { mAlpha = alpha; } + /** + * Returns the opacity for the symbol. + * \returns opacity value between 0 (fully transparent) and 1 (fully opaque) + * \see setOpacity() + */ + qreal opacity() const { return mOpacity; } + + /** + * Sets the \a opacity for the symbol. + * \param opacity opacity value between 0 (fully transparent) and 1 (fully opaque) + * \see opacity() + */ + void setOpacity( qreal opacity ) { mOpacity = opacity; } bool selected() const { return mSelected; } void setSelected( bool selected ) { mSelected = selected; } @@ -503,7 +521,7 @@ class CORE_EXPORT QgsSymbolRenderContext std::unique_ptr< QgsExpressionContextScope > mExpressionContextScope; QgsUnitTypes::RenderUnit mOutputUnit; QgsMapUnitScale mMapUnitScale; - qreal mAlpha; + qreal mOpacity = 1.0; bool mSelected; QgsSymbol::RenderHints mRenderHints; const QgsFeature *mFeature; //current feature diff --git a/src/core/symbology-ng/qgssymbollayer.cpp b/src/core/symbology-ng/qgssymbollayer.cpp index ff0f43023ee..0389236782f 100644 --- a/src/core/symbology-ng/qgssymbollayer.cpp +++ b/src/core/symbology-ng/qgssymbollayer.cpp @@ -74,7 +74,7 @@ void QgsSymbolLayer::initPropertyDefinitions() { QgsSymbolLayer::PropertyDistanceY, QgsPropertyDefinition( "distanceY", QObject::tr( "Vertical distance between markers" ), QgsPropertyDefinition::DoublePositive )}, { QgsSymbolLayer::PropertyDisplacementX, QgsPropertyDefinition( "displacementX", QObject::tr( "Horizontal displacement between rows" ), QgsPropertyDefinition::DoublePositive )}, { QgsSymbolLayer::PropertyDisplacementY, QgsPropertyDefinition( "displacementY", QObject::tr( "Vertical displacement between columns" ), QgsPropertyDefinition::DoublePositive )}, - { QgsSymbolLayer::PropertyAlpha, QgsPropertyDefinition( "alpha", QObject::tr( "Opacity" ), QgsPropertyDefinition::Double0To1 )}, + { QgsSymbolLayer::PropertyOpacity, QgsPropertyDefinition( "alpha", QObject::tr( "Opacity" ), QgsPropertyDefinition::Opacity )}, { QgsSymbolLayer::PropertyCustomDash, QgsPropertyDefinition( "customDash", QgsPropertyDefinition::DataTypeString, QObject::tr( "Custom dash pattern" ), QObject::tr( "[;] e.g. '8;2;1;2'" ) )}, { QgsSymbolLayer::PropertyCapStyle, QgsPropertyDefinition( "capStyle", QObject::tr( "Line cap style" ), QgsPropertyDefinition::CapStyle )}, { QgsSymbolLayer::PropertyPlacement, QgsPropertyDefinition( "placement", QgsPropertyDefinition::DataTypeString, QObject::tr( "Marker placement" ), QObject::tr( "string " ) + "[interval|vertex|lastvertex|firstvertex|centerpoint|curvepoint]" )}, @@ -296,7 +296,7 @@ static const QMap< QString, QgsSymbolLayer::Property > OLD_PROPS { "displacement_x", QgsSymbolLayer::PropertyDisplacementX }, { "displacement_y", QgsSymbolLayer::PropertyDisplacementY }, { "file", QgsSymbolLayer::PropertyFile }, - { "alpha", QgsSymbolLayer::PropertyAlpha }, + { "alpha", QgsSymbolLayer::PropertyOpacity }, { "customdash", QgsSymbolLayer::PropertyCustomDash }, { "line_style", QgsSymbolLayer::PropertyStrokeStyle }, { "joinstyle", QgsSymbolLayer::PropertyJoinStyle }, diff --git a/src/core/symbology-ng/qgssymbollayer.h b/src/core/symbology-ng/qgssymbollayer.h index cf505f3edd0..d4885046c07 100644 --- a/src/core/symbology-ng/qgssymbollayer.h +++ b/src/core/symbology-ng/qgssymbollayer.h @@ -93,7 +93,7 @@ class CORE_EXPORT QgsSymbolLayer PropertyDistanceY, //!< Vertical distance between points PropertyDisplacementX, //!< Horizontal displacement PropertyDisplacementY, //!< Vertical displacement - PropertyAlpha, //!< Alpha (opacity) + PropertyOpacity, //!< Opacity PropertyCustomDash, //!< Custom dash pattern PropertyCapStyle, //!< Line cap style PropertyPlacement, //!< Line marker placement diff --git a/src/core/symbology-ng/qgssymbollayerutils.cpp b/src/core/symbology-ng/qgssymbollayerutils.cpp index 5a2a886a7d5..daa2f5f31ac 100644 --- a/src/core/symbology-ng/qgssymbollayerutils.cpp +++ b/src/core/symbology-ng/qgssymbollayerutils.cpp @@ -874,7 +874,7 @@ QgsSymbol *QgsSymbolLayerUtils::loadSymbol( const QDomElement &element, const Qg mapUnitScale.maxScale = element.attribute( QStringLiteral( "mapUnitMaxScale" ), QStringLiteral( "0.0" ) ).toDouble(); symbol->setMapUnitScale( mapUnitScale ); } - symbol->setAlpha( element.attribute( QStringLiteral( "alpha" ), QStringLiteral( "1.0" ) ).toDouble() ); + symbol->setOpacity( element.attribute( QStringLiteral( "alpha" ), QStringLiteral( "1.0" ) ).toDouble() ); symbol->setClipFeaturesToExtent( element.attribute( QStringLiteral( "clip_to_extent" ), QStringLiteral( "1" ) ).toInt() ); return symbol; @@ -945,7 +945,7 @@ QDomElement QgsSymbolLayerUtils::saveSymbol( const QString &name, QgsSymbol *sym QDomElement symEl = doc.createElement( QStringLiteral( "symbol" ) ); symEl.setAttribute( QStringLiteral( "type" ), _nameForSymbolType( symbol->type() ) ); symEl.setAttribute( QStringLiteral( "name" ), name ); - symEl.setAttribute( QStringLiteral( "alpha" ), QString::number( symbol->alpha() ) ); + symEl.setAttribute( QStringLiteral( "alpha" ), QString::number( symbol->opacity() ) ); symEl.setAttribute( QStringLiteral( "clip_to_extent" ), symbol->clipFeaturesToExtent() ? "1" : "0" ); //QgsDebugMsg( "num layers " + QString::number( symbol->symbolLayerCount() ) ); @@ -3373,7 +3373,7 @@ QColor QgsSymbolLayerUtils::parseColorWithAlpha( const QString &colorStr, bool & return QColor(); } -void QgsSymbolLayerUtils::multiplyImageOpacity( QImage *image, qreal alpha ) +void QgsSymbolLayerUtils::multiplyImageOpacity( QImage *image, qreal opacity ) { if ( !image ) { @@ -3396,9 +3396,9 @@ void QgsSymbolLayerUtils::multiplyImageOpacity( QImage *image, qreal alpha ) { myRgb = scanLine[widthIndex]; if ( format == QImage::Format_ARGB32_Premultiplied ) - scanLine[widthIndex] = qRgba( alpha * qRed( myRgb ), alpha * qGreen( myRgb ), alpha * qBlue( myRgb ), alpha * qAlpha( myRgb ) ); + scanLine[widthIndex] = qRgba( opacity * qRed( myRgb ), opacity * qGreen( myRgb ), opacity * qBlue( myRgb ), opacity * qAlpha( myRgb ) ); else - scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), alpha * qAlpha( myRgb ) ); + scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), opacity * qAlpha( myRgb ) ); } } } diff --git a/src/core/symbology-ng/qgssymbollayerutils.h b/src/core/symbology-ng/qgssymbollayerutils.h index 82dafb8cae4..f31f19e32f7 100644 --- a/src/core/symbology-ng/qgssymbollayerutils.h +++ b/src/core/symbology-ng/qgssymbollayerutils.h @@ -492,8 +492,10 @@ class CORE_EXPORT QgsSymbolLayerUtils */ static QColor parseColorWithAlpha( const QString &colorStr, bool &containsAlpha, bool strictEval = false ); - //! Multiplies opacity of image pixel values with a (global) transparency value - static void multiplyImageOpacity( QImage *image, qreal alpha ); + /** + * Multiplies opacity of image pixel values with a (global) transparency value. + */ + static void multiplyImageOpacity( QImage *image, qreal opacity ); //! Blurs an image in place, e.g. creating Qt-independent drop shadows static void blurImageInPlace( QImage &image, QRect rect, int radius, bool alphaOnly ); diff --git a/src/gui/symbology-ng/qgsrendererwidget.cpp b/src/gui/symbology-ng/qgsrendererwidget.cpp index c4da07d26d8..0aae38f2964 100644 --- a/src/gui/symbology-ng/qgsrendererwidget.cpp +++ b/src/gui/symbology-ng/qgsrendererwidget.cpp @@ -113,14 +113,14 @@ void QgsRendererWidget::changeSymbolTransparency() return; bool ok; - double oldTransparency = ( 1 - firstSymbol->alpha() ) * 100; // convert to percents + double oldTransparency = ( 1 - firstSymbol->opacity() ) * 100; // convert to percents double transparency = QInputDialog::getDouble( this, tr( "Transparency" ), tr( "Change symbol transparency [%]" ), oldTransparency, 0.0, 100.0, 0, &ok ); if ( ok ) { Q_FOREACH ( QgsSymbol *symbol, symbolList ) { if ( symbol ) - symbol->setAlpha( 1 - transparency / 100 ); + symbol->setOpacity( 1 - transparency / 100 ); } refreshSymbolView(); } diff --git a/src/gui/symbology-ng/qgssymbollayerwidget.cpp b/src/gui/symbology-ng/qgssymbollayerwidget.cpp index cf01ebb5f50..fdd3b2cd8f6 100644 --- a/src/gui/symbology-ng/qgssymbollayerwidget.cpp +++ b/src/gui/symbology-ng/qgssymbollayerwidget.cpp @@ -2918,12 +2918,16 @@ QgsRasterFillSymbolLayerWidget::QgsRasterFillSymbolLayerWidget( const QgsVectorL mSpinOffsetX->setClearValue( 0.0 ); mSpinOffsetY->setClearValue( 0.0 ); + mSpinOpacity->setClearValue( 100.0 ); + connect( mSliderOpacity, &QSlider::valueChanged, this, [ = ]( int value ) { mSpinOpacity->setValue( value / 10.0 ); } ); + connect( mSpinOpacity, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double value ) { whileBlocking( mSliderOpacity )->setValue( value * 10 ); } ); connect( cboCoordinateMode, static_cast( &QComboBox::currentIndexChanged ), this, &QgsRasterFillSymbolLayerWidget::setCoordinateMode ); connect( mSpinOffsetX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterFillSymbolLayerWidget::offsetChanged ); connect( mSpinOffsetY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterFillSymbolLayerWidget::offsetChanged ); } + void QgsRasterFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer ) { if ( !layer ) @@ -2958,12 +2962,12 @@ void QgsRasterFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer ) break; } cboCoordinateMode->blockSignals( false ); - mSpinTransparency->blockSignals( true ); - mSpinTransparency->setValue( mLayer->alpha() * 100.0 ); - mSpinTransparency->blockSignals( false ); - mSliderTransparency->blockSignals( true ); - mSliderTransparency->setValue( mLayer->alpha() * 100.0 ); - mSliderTransparency->blockSignals( false ); + mSpinOpacity->blockSignals( true ); + mSpinOpacity->setValue( mLayer->opacity() * 100.0 ); + mSpinOpacity->blockSignals( false ); + mSliderOpacity->blockSignals( true ); + mSliderOpacity->setValue( mLayer->opacity() * 1000.0 ); + mSliderOpacity->blockSignals( false ); mRotationSpinBox->blockSignals( true ); mRotationSpinBox->setValue( mLayer->angle() ); mRotationSpinBox->blockSignals( false ); @@ -2989,7 +2993,7 @@ void QgsRasterFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayer *layer ) updatePreviewImage(); registerDataDefinedButton( mFilenameDDBtn, QgsSymbolLayer::PropertyFile ); - registerDataDefinedButton( mOpacityDDBtn, QgsSymbolLayer::PropertyAlpha ); + registerDataDefinedButton( mOpacityDDBtn, QgsSymbolLayer::PropertyOpacity ); registerDataDefinedButton( mRotationDDBtn, QgsSymbolLayer::PropertyAngle ); registerDataDefinedButton( mWidthDDBtn, QgsSymbolLayer::PropertyWidth ); } @@ -3075,14 +3079,14 @@ void QgsRasterFillSymbolLayerWidget::setCoordinateMode( int index ) emit changed(); } -void QgsRasterFillSymbolLayerWidget::on_mSpinTransparency_valueChanged( int value ) +void QgsRasterFillSymbolLayerWidget::on_mSpinOpacity_valueChanged( double value ) { if ( !mLayer ) { return; } - mLayer->setAlpha( value / 100.0 ); + mLayer->setOpacity( value / 100.0 ); emit changed(); updatePreviewImage(); } @@ -3171,9 +3175,9 @@ void QgsRasterFillSymbolLayerWidget::updatePreviewImage() checkerBrush.setTexture( pix ); p.fillRect( imageRect, checkerBrush ); - if ( mLayer->alpha() < 1.0 ) + if ( mLayer->opacity() < 1.0 ) { - p.setOpacity( mLayer->alpha() ); + p.setOpacity( mLayer->opacity() ); } p.drawImage( imageRect.left(), imageRect.top(), image ); diff --git a/src/gui/symbology-ng/qgssymbollayerwidget.h b/src/gui/symbology-ng/qgssymbollayerwidget.h index 890e30044e7..24556b72612 100644 --- a/src/gui/symbology-ng/qgssymbollayerwidget.h +++ b/src/gui/symbology-ng/qgssymbollayerwidget.h @@ -499,7 +499,7 @@ class GUI_EXPORT QgsRasterFillSymbolLayerWidget : public QgsSymbolLayerWidget, p void on_mBrowseToolButton_clicked(); void on_mImageLineEdit_editingFinished(); void setCoordinateMode( int index ); - void on_mSpinTransparency_valueChanged( int value ); + void on_mSpinOpacity_valueChanged( double value ); void offsetChanged(); void on_mOffsetUnitWidget_changed(); void on_mRotationSpinBox_valueChanged( double d ); diff --git a/src/gui/symbology-ng/qgssymbolslistwidget.cpp b/src/gui/symbology-ng/qgssymbolslistwidget.cpp index 15038ca3368..49549b00834 100644 --- a/src/gui/symbology-ng/qgssymbolslistwidget.cpp +++ b/src/gui/symbology-ng/qgssymbolslistwidget.cpp @@ -54,6 +54,7 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style, mSymbolUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderMapUnits << QgsUnitTypes::RenderPixels << QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches ); + mOpacitySpinBox->setClearValue( 100.0 ); btnAdvanced->hide(); // advanced button is hidden by default if ( menu ) // show it if there is a menu pointer @@ -112,6 +113,9 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style, btnColor->setColorDialogTitle( tr( "Select color" ) ); btnColor->setContext( QStringLiteral( "symbology" ) ); + connect( mOpacitySlider, &QSlider::valueChanged, this, [ = ]( int value ) { whileBlocking( mOpacitySpinBox )->setValue( value / 10.0 ); } ); + connect( mOpacitySpinBox, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double value ) { mOpacitySlider->setValue( value * 10 ); } ); + connect( btnSaveSymbol, &QPushButton::clicked, this, &QgsSymbolsListWidget::saveSymbol ); } @@ -453,23 +457,16 @@ void QgsSymbolsListWidget::on_mSymbolUnitWidget_changed() } } -void QgsSymbolsListWidget::on_mTransparencySlider_valueChanged( int value ) +void QgsSymbolsListWidget::on_mOpacitySlider_valueChanged( int value ) { if ( mSymbol ) { - double alpha = 1 - ( value / 255.0 ); - mSymbol->setAlpha( alpha ); - displayTransparency( alpha ); + double opacity = value / 1000.0; + mSymbol->setOpacity( opacity ); emit changed(); } } -void QgsSymbolsListWidget::displayTransparency( double alpha ) -{ - double transparencyPercent = ( 1 - alpha ) * 100; - mTransparencyLabel->setText( tr( "Transparency %1%" ).arg( ( int ) transparencyPercent ) ); -} - void QgsSymbolsListWidget::updateSymbolColor() { btnColor->blockSignals( true ); @@ -551,11 +548,8 @@ void QgsSymbolsListWidget::updateSymbolInfo() mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() ); mSymbolUnitWidget->blockSignals( false ); - mTransparencySlider->blockSignals( true ); - double transparency = 1 - mSymbol->alpha(); - mTransparencySlider->setValue( transparency * 255 ); - displayTransparency( mSymbol->alpha() ); - mTransparencySlider->blockSignals( false ); + whileBlocking( mOpacitySlider )->setValue( mSymbol->opacity() * 1000 ); + whileBlocking( mOpacitySpinBox )->setValue( mSymbol->opacity() * 100 ); if ( mSymbol->type() == QgsSymbol::Line || mSymbol->type() == QgsSymbol::Fill ) { @@ -588,7 +582,7 @@ void QgsSymbolsListWidget::setSymbolFromStyle( const QModelIndex &index ) QgsSymbolLayer *sl = s->takeSymbolLayer( 0 ); mSymbol->appendSymbolLayer( sl ); } - mSymbol->setAlpha( s->alpha() ); + mSymbol->setOpacity( s->opacity() ); // delete the temporary symbol delete s; diff --git a/src/gui/symbology-ng/qgssymbolslistwidget.h b/src/gui/symbology-ng/qgssymbolslistwidget.h index 65da9e425e0..c6fd43409e2 100644 --- a/src/gui/symbology-ng/qgssymbolslistwidget.h +++ b/src/gui/symbology-ng/qgssymbolslistwidget.h @@ -73,7 +73,6 @@ class GUI_EXPORT QgsSymbolsListWidget : public QWidget, private Ui::SymbolsListW void symbolAddedToStyle( const QString &name, QgsSymbol *symbol ); void on_mSymbolUnitWidget_changed(); - void on_mTransparencySlider_valueChanged( int value ); //! Pupulates the groups combo box with available tags and smartgroups void populateGroups(); @@ -92,6 +91,7 @@ class GUI_EXPORT QgsSymbolsListWidget : public QWidget, private Ui::SymbolsListW private slots: void updateAssistantSymbol(); + void on_mOpacitySlider_valueChanged( int value ); private: QgsSymbol *mSymbol = nullptr; @@ -106,10 +106,6 @@ class GUI_EXPORT QgsSymbolsListWidget : public QWidget, private Ui::SymbolsListW void populateSymbols( const QStringList &symbols ); void updateSymbolColor(); void updateSymbolInfo(); - - //! Displays alpha value as transparency in mTransparencyLabel - void displayTransparency( double alpha ); - QgsSymbolWidgetContext mContext; QgsExpressionContext createExpressionContext() const override; diff --git a/src/server/services/wms/qgswmsrenderer.cpp b/src/server/services/wms/qgswmsrenderer.cpp index e76f620e6f2..ee8bdc6ef5f 100644 --- a/src/server/services/wms/qgswmsrenderer.cpp +++ b/src/server/services/wms/qgswmsrenderer.cpp @@ -2180,7 +2180,7 @@ namespace QgsWms QgsSymbolList symbolList = renderer->symbols( context ); for ( auto symbolIt = symbolList.begin(); symbolIt != symbolList.end(); ++symbolIt ) { - ( *symbolIt )->setAlpha( ( *symbolIt )->alpha() * opacityRatio ); + ( *symbolIt )->setOpacity( ( *symbolIt )->opacity() * opacityRatio ); } //labeling diff --git a/src/ui/symbollayer/widget_rasterfill.ui b/src/ui/symbollayer/widget_rasterfill.ui index f3dad8462e1..8284ef6fd91 100644 --- a/src/ui/symbollayer/widget_rasterfill.ui +++ b/src/ui/symbollayer/widget_rasterfill.ui @@ -6,8 +6,8 @@ 0 0 - 290 - 417 + 310 + 429 @@ -242,7 +242,7 @@ Opacity - mSliderTransparency + mSliderOpacity @@ -291,7 +291,7 @@ - + 0 @@ -299,10 +299,16 @@ + 1000 + + + 10 + + 100 - 100 + 1000 Qt::Horizontal @@ -310,18 +316,21 @@ - + + + + 100 + 0 + + - % + % - - 0 - - - 100 + + 1 - 100 + 100.000000000000000 @@ -366,44 +375,11 @@ mWidthSpinBox mRotationSpinBox cboCoordinateMode - mSliderTransparency - mSpinTransparency + mSliderOpacity + mSpinOpacity mSpinOffsetX mSpinOffsetY - - - mSliderTransparency - valueChanged(int) - mSpinTransparency - setValue(int) - - - 311 - 160 - - - 392 - 160 - - - - - mSpinTransparency - valueChanged(int) - mSliderTransparency - setValue(int) - - - 392 - 160 - - - 311 - 160 - - - - + diff --git a/src/ui/symbollayer/widget_symbolslist.ui b/src/ui/symbollayer/widget_symbolslist.ui index 5656777be11..03842f98ab6 100644 --- a/src/ui/symbollayer/widget_symbolslist.ui +++ b/src/ui/symbollayer/widget_symbolslist.ui @@ -14,12 +14,21 @@ Form + + 0 + + + 0 + + + 0 + + + 0 + 4 - - 0 - @@ -152,13 +161,10 @@ - - + + - Color - - - btnColor + Unit @@ -172,38 +178,76 @@ + + + + Color + + + btnColor + + + Opacity - mTransparencySlider + mOpacitySlider - - - - 0 - 0 - - - - 255 - - - Qt::Horizontal - - - - - - - Unit - - + + + + + + 0 + 0 + + + + 1000 + + + 10 + + + 100 + + + 1000 + + + Qt::Horizontal + + + + + + + + 100 + 0 + + + + % + + + 1 + + + 100.000000000000000 + + + 100.000000000000000 + + + + @@ -245,7 +289,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -341,7 +394,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -391,7 +453,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -427,13 +498,20 @@ - mTransparencySlider + mOpacitySlider + mOpacitySpinBox btnColor groupsCombo openStyleManagerButton viewSymbols btnSaveSymbol btnAdvanced + spinSize + mSizeDDBtn + spinAngle + mRotationDDBtn + spinWidth + mWidthDDBtn diff --git a/tests/src/core/testqgscomposerutils.cpp b/tests/src/core/testqgscomposerutils.cpp index 5d53a3106e3..24fce8899d7 100644 --- a/tests/src/core/testqgscomposerutils.cpp +++ b/tests/src/core/testqgscomposerutils.cpp @@ -505,9 +505,9 @@ void TestQgsComposerUtils::readOldDataDefinedPropertyMap() QVERIFY( ( dataDefinedProperties.property( QgsComposerObject::BlendMode ) ).isActive() ); QCOMPARE( ( dataDefinedProperties.property( QgsComposerObject::BlendMode ) ).propertyType(), QgsProperty::ExpressionBasedProperty ); QCOMPARE( dataDefinedProperties.property( QgsComposerObject::BlendMode ).expressionString(), QString( "test expression" ) ); - QVERIFY( !( dataDefinedProperties.property( QgsComposerObject::Transparency ) ).isActive() ); - QCOMPARE( ( dataDefinedProperties.property( QgsComposerObject::Transparency ) ).propertyType(), QgsProperty::FieldBasedProperty ); - QCOMPARE( dataDefinedProperties.property( QgsComposerObject::Transparency ).field(), QString( "test field 2" ) ); + QVERIFY( !( dataDefinedProperties.property( QgsComposerObject::Opacity ) ).isActive() ); + QCOMPARE( ( dataDefinedProperties.property( QgsComposerObject::Opacity ) ).propertyType(), QgsProperty::FieldBasedProperty ); + QCOMPARE( dataDefinedProperties.property( QgsComposerObject::Opacity ).field(), QString( "test field 2" ) ); QVERIFY( ( dataDefinedProperties.property( QgsComposerObject::TestProperty ) ).isActive() ); QCOMPARE( ( dataDefinedProperties.property( QgsComposerObject::TestProperty ) ).propertyType(), QgsProperty::FieldBasedProperty ); QCOMPARE( dataDefinedProperties.property( QgsComposerObject::TestProperty ).field(), QString( "test field 3" ) ); diff --git a/tests/src/core/testqgsrasterfill.cpp b/tests/src/core/testqgsrasterfill.cpp index 190422a23ae..8287b512bc4 100644 --- a/tests/src/core/testqgsrasterfill.cpp +++ b/tests/src/core/testqgsrasterfill.cpp @@ -139,7 +139,7 @@ void TestQgsRasterFill::init() mRasterFill->setWidth( 30.0 ); mRasterFill->setWidthUnit( QgsUnitTypes::RenderPixels ); mRasterFill->setCoordinateMode( QgsRasterFillSymbolLayer::Feature ); - mRasterFill->setAlpha( 1.0 ); + mRasterFill->setOpacity( 1.0 ); mRasterFill->setOffset( QPointF( 0, 0 ) ); } @@ -166,7 +166,7 @@ void TestQgsRasterFill::coordinateMode() void TestQgsRasterFill::alpha() { mReport += QLatin1String( "

Raster fill alpha

\n" ); - mRasterFill->setAlpha( 0.5 ); + mRasterFill->setOpacity( 0.5 ); bool result = imageCheck( QStringLiteral( "rasterfill_alpha" ) ); QVERIFY( result ); }