Skip to content
Permalink
Browse files

Flip QgsVectorLayer from transparency to opacity

  • Loading branch information
nyalldawson committed May 29, 2017
1 parent b7352bb commit bcf4026f9de53171b440ad82a8794af28c3d79a2
@@ -2303,6 +2303,7 @@ displayExpression instead. For the map tip use mapTipTemplate() instead.
- addFeature() no longer accepts an alsoUpdateExtent boolean - this extra argument has been ignored for some time
- addFeatures() no longer accepts a makeSelected boolean, and will not automatically select newly added features. If desired, features must be manually selected by calling selectByIds() after addFeatures()
- annotationForm() and setAnnotationForm() have been removed. Form path is stored in individual QgsFormAnnotation objects.
- setLayerTransparency, layerTransparency, and layerTransparencyChanged were removed. Use opacity, setOpacity and opacityChanged instead.


QgsVectorLayerEditBuffer {#qgis_api_break_3_0_QgsVectorLayerEditBuffer}
@@ -1615,14 +1615,23 @@ Returns the current blending mode for features
:rtype: QPainter.CompositionMode
%End

void setLayerTransparency( int layerTransparency );
void setOpacity( double opacity );
%Docstring
Set the transparency for the vector layer
Sets the ``opacity`` for the vector layer, where ``opacity`` is a value between 0 (totally transparent)
and 1.0 (fully opaque).
.. seealso:: opacity()
.. seealso:: opacityChanged()
.. versionadded:: 3.0
%End
int layerTransparency() const;

double opacity() const;
%Docstring
Returns the current transparency for the vector layer
:rtype: int
Returns the opacity for the vector layer, where opacity is a value between 0 (totally transparent)
and 1.0 (fully opaque).
.. seealso:: setOpacity()
.. seealso:: opacityChanged()
.. versionadded:: 3.0
:rtype: float
%End

virtual QString htmlMetadata() const;
@@ -1952,9 +1961,13 @@ Emitted when the font family defined for labeling layer is not found on system
Signal emitted when setFeatureBlendMode() is called
%End

void layerTransparencyChanged( int layerTransparency );
void opacityChanged( double opacity );
%Docstring
Signal emitted when setLayerTransparency() is called
Emitted when the layer's opacity is changed, where ``opacity`` is a value between 0 (transparent)
and 1 (opaque).
.. versionadded:: 3.0
.. seealso:: setOpacity()
.. seealso:: opacity()
%End

void editCommandStarted( const QString &text );
@@ -387,7 +387,7 @@ QSizeF QgsSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemC

int opacity = 255;
if ( QgsVectorLayer *vectorLayer = dynamic_cast<QgsVectorLayer *>( layerNode()->layer() ) )
opacity = 255 - ( 255 * vectorLayer->layerTransparency() / 100 );
opacity = ( 255 * vectorLayer->opacity() );

p->save();
p->setRenderHint( QPainter::Antialiasing );
@@ -354,7 +354,7 @@ bool QgsMapRendererJob::needTemporaryImage( QgsMapLayer *ml )
if ( mSettings.testFlag( QgsMapSettings::UseAdvancedEffects ) &&
( ( vl->blendMode() != QPainter::CompositionMode_SourceOver )
|| ( vl->featureBlendMode() != QPainter::CompositionMode_SourceOver )
|| ( vl->layerTransparency() != 0 ) ) )
|| ( !qgsDoubleNear( vl->opacity(), 1.0 ) ) ) )
{
//layer properties require rasterization
return true;
@@ -280,7 +280,7 @@ LayerRenderJobs QgsMapRendererJob::prepareJobs( QPainter *painter, QgsLabelingEn
job.opacity = 1.0;
if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml ) )
{
job.opacity = 1.0 - vl->layerTransparency() / 100.0;
job.opacity = vl->opacity();
}
job.layer = ml;
job.renderingTime = -1;
@@ -40,7 +40,7 @@ const QStringList QgsMapSettingsUtils::containsAdvancedEffects( const QgsMapSett
QgsVectorLayer *currentVectorLayer = qobject_cast<QgsVectorLayer *>( layer );
if ( currentVectorLayer )
{
if ( currentVectorLayer->layerTransparency() != 0 )
if ( !qgsDoubleNear( currentVectorLayer->opacity(), 1.0 ) )
{
layers << layer->name();
}
@@ -114,8 +114,8 @@ void QgsPalLayerSettings::initPropertyDefinitions()
"e.g. Bold Condensed or Light Italic" ) )
},
{ QgsPalLayerSettings::FontSizeUnit, QgsPropertyDefinition( "FontSizeUnit", QObject::tr( "Font size units" ), QgsPropertyDefinition::RenderUnits ) },
{ QgsPalLayerSettings::FontTransp, QgsPropertyDefinition( "FontTransp", QObject::tr( "Text transparency" ), QgsPropertyDefinition::Transparency ) },
{ QgsPalLayerSettings::FontOpacity, QgsPropertyDefinition( "FontOpacity", QObject::tr( "Text opacity" ), QgsPropertyDefinition::Transparency ) },
{ QgsPalLayerSettings::FontTransp, QgsPropertyDefinition( "FontTransp", QObject::tr( "Text transparency" ), QgsPropertyDefinition::Opacity ) },
{ QgsPalLayerSettings::FontOpacity, QgsPropertyDefinition( "FontOpacity", QObject::tr( "Text opacity" ), QgsPropertyDefinition::Opacity ) },
{ QgsPalLayerSettings::FontCase, QgsPropertyDefinition( "FontCase", QgsPropertyDefinition::DataTypeString, QObject::tr( "Font case" ), QObject::tr( "string " ) + QStringLiteral( "[<b>NoChange</b>|<b>Upper</b>|<br><b>Lower</b>|<b>Capitalize</b>]" ) ) },
{ QgsPalLayerSettings::FontLetterSpacing, QgsPropertyDefinition( "FontLetterSpacing", QObject::tr( "Letter spacing" ), QgsPropertyDefinition::Double ) },
{ QgsPalLayerSettings::FontWordSpacing, QgsPropertyDefinition( "FontWordSpacing", QObject::tr( "Word spacing" ), QgsPropertyDefinition::Double ) },
@@ -135,8 +135,8 @@ void QgsPalLayerSettings::initPropertyDefinitions()
{ QgsPalLayerSettings::BufferSize, QgsPropertyDefinition( "BufferSize", QObject::tr( "Symbol size" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsPalLayerSettings::BufferUnit, QgsPropertyDefinition( "BufferUnit", QObject::tr( "Buffer units" ), QgsPropertyDefinition::RenderUnits ) },
{ QgsPalLayerSettings::BufferColor, QgsPropertyDefinition( "BufferColor", QObject::tr( "Buffer color" ), QgsPropertyDefinition::ColorNoAlpha ) },
{ QgsPalLayerSettings::BufferTransp, QgsPropertyDefinition( "BufferTransp", QObject::tr( "Buffer transparency" ), QgsPropertyDefinition::Transparency ) },
{ QgsPalLayerSettings::BufferOpacity, QgsPropertyDefinition( "BufferOpacity", QObject::tr( "Buffer opacity" ), QgsPropertyDefinition::Transparency ) },
{ QgsPalLayerSettings::BufferTransp, QgsPropertyDefinition( "BufferTransp", QObject::tr( "Buffer transparency" ), QgsPropertyDefinition::Opacity ) },
{ QgsPalLayerSettings::BufferOpacity, QgsPropertyDefinition( "BufferOpacity", QObject::tr( "Buffer opacity" ), QgsPropertyDefinition::Opacity ) },
{ QgsPalLayerSettings::BufferJoinStyle, QgsPropertyDefinition( "BufferJoinStyle", QObject::tr( "Buffer join style" ), QgsPropertyDefinition::PenJoinStyle ) },
{ QgsPalLayerSettings::BufferBlendMode, QgsPropertyDefinition( "BufferBlendMode", QObject::tr( "Buffer blend mode" ), QgsPropertyDefinition::BlendMode ) },
{ QgsPalLayerSettings::ShapeDraw, QgsPropertyDefinition( "ShapeDraw", QObject::tr( "Draw shape" ), QgsPropertyDefinition::Boolean ) },
@@ -155,8 +155,8 @@ void QgsPalLayerSettings::initPropertyDefinitions()
{ QgsPalLayerSettings::ShapeOffsetUnits, QgsPropertyDefinition( "ShapeOffsetUnits", QObject::tr( "Shape offset units" ), QgsPropertyDefinition::RenderUnits ) },
{ QgsPalLayerSettings::ShapeRadii, QgsPropertyDefinition( "ShapeRadii", QObject::tr( "Shape radii" ), QgsPropertyDefinition::Size2D ) },
{ QgsPalLayerSettings::ShapeRadiiUnits, QgsPropertyDefinition( "ShapeRadiiUnits", QObject::tr( "Symbol radii units" ), QgsPropertyDefinition::RenderUnits ) },
{ QgsPalLayerSettings::ShapeTransparency, QgsPropertyDefinition( "ShapeTransparency", QObject::tr( "Shape transparency" ), QgsPropertyDefinition::Transparency ) },
{ QgsPalLayerSettings::ShapeOpacity, QgsPropertyDefinition( "ShapeOpacity", QObject::tr( "Shape opacity" ), QgsPropertyDefinition::Transparency ) },
{ QgsPalLayerSettings::ShapeTransparency, QgsPropertyDefinition( "ShapeTransparency", QObject::tr( "Shape transparency" ), QgsPropertyDefinition::Opacity ) },
{ QgsPalLayerSettings::ShapeOpacity, QgsPropertyDefinition( "ShapeOpacity", QObject::tr( "Shape opacity" ), QgsPropertyDefinition::Opacity ) },
{ QgsPalLayerSettings::ShapeBlendMode, QgsPropertyDefinition( "ShapeBlendMode", QObject::tr( "Shape blend mode" ), QgsPropertyDefinition::BlendMode ) },
{ QgsPalLayerSettings::ShapeFillColor, QgsPropertyDefinition( "ShapeFillColor", QObject::tr( "Shape fill color" ), QgsPropertyDefinition::ColorWithAlpha ) },
{ QgsPalLayerSettings::ShapeStrokeColor, QgsPropertyDefinition( "ShapeBorderColor", QObject::tr( "Shape stroke color" ), QgsPropertyDefinition::ColorWithAlpha ) },
@@ -173,8 +173,8 @@ void QgsPalLayerSettings::initPropertyDefinitions()
{ QgsPalLayerSettings::ShadowOffsetUnits, QgsPropertyDefinition( "ShadowOffsetUnits", QObject::tr( "Shadow offset units" ), QgsPropertyDefinition::RenderUnits ) },
{ QgsPalLayerSettings::ShadowRadius, QgsPropertyDefinition( "ShadowRadius", QObject::tr( "Shadow blur radius" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsPalLayerSettings::ShadowRadiusUnits, QgsPropertyDefinition( "ShadowRadiusUnits", QObject::tr( "Shadow blur units" ), QgsPropertyDefinition::RenderUnits ) },
{ QgsPalLayerSettings::ShadowTransparency, QgsPropertyDefinition( "ShadowTransparency", QObject::tr( "Shadow transparency" ), QgsPropertyDefinition::Transparency ) },
{ QgsPalLayerSettings::ShadowOpacity, QgsPropertyDefinition( "ShadowOpacity", QObject::tr( "Shadow opacity" ), QgsPropertyDefinition::Transparency ) },
{ QgsPalLayerSettings::ShadowTransparency, QgsPropertyDefinition( "ShadowTransparency", QObject::tr( "Shadow transparency" ), QgsPropertyDefinition::Opacity ) },
{ QgsPalLayerSettings::ShadowOpacity, QgsPropertyDefinition( "ShadowOpacity", QObject::tr( "Shadow opacity" ), QgsPropertyDefinition::Opacity ) },
{ QgsPalLayerSettings::ShadowScale, QgsPropertyDefinition( "ShadowScale", QObject::tr( "Shadow scale" ), QgsPropertyDefinition::IntegerPositive ) },
{ QgsPalLayerSettings::ShadowColor, QgsPropertyDefinition( "ShadowColor", QObject::tr( "Shadow color" ), QgsPropertyDefinition::ColorNoAlpha ) },
{ QgsPalLayerSettings::ShadowBlendMode, QgsPropertyDefinition( "ShadowBlendMode", QObject::tr( "Shadow blend mode" ), QgsPropertyDefinition::BlendMode ) },
@@ -143,7 +143,6 @@ QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath,
, mLabeling( nullptr )
, mLabelFontNotFoundNotified( false )
, mFeatureBlendMode( QPainter::CompositionMode_SourceOver ) // Default to normal feature blending
, mLayerTransparency( 0 )
, mVertexMarkerOnlyForSelection( false )
, mEditBuffer( nullptr )
, mJoinBuffer( nullptr )
@@ -222,7 +221,7 @@ QgsVectorLayer *QgsVectorLayer::clone() const
layer->setExcludeAttributesWfs( excludeAttributesWfs() );
layer->setAttributeTableConfig( attributeTableConfig() );
layer->setFeatureBlendMode( featureBlendMode() );
layer->setLayerTransparency( layerTransparency() );
layer->setOpacity( opacity() );

Q_FOREACH ( const QgsAction &action, actions()->actions() )
{
@@ -1887,7 +1886,13 @@ bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage, con
if ( !layerTransparencyNode.isNull() )
{
QDomElement e = layerTransparencyNode.toElement();
setLayerTransparency( e.text().toInt() );
setOpacity( 1.0 - e.text().toInt() / 100.0 );
}
QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
if ( !layerOpacityNode.isNull() )
{
QDomElement e = layerOpacityNode.toElement();
setOpacity( e.text().toDouble() );
}

QDomElement e = node.toElement();
@@ -2153,11 +2158,11 @@ bool QgsVectorLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &err
featureBlendModeElem.appendChild( featureBlendModeText );
node.appendChild( featureBlendModeElem );

// add the layer transparency
QDomElement layerTransparencyElem = doc.createElement( QStringLiteral( "layerTransparency" ) );
QDomText layerTransparencyText = doc.createTextNode( QString::number( layerTransparency() ) );
layerTransparencyElem.appendChild( layerTransparencyText );
node.appendChild( layerTransparencyElem );
// add the layer opacity
QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
layerOpacityElem.appendChild( layerOpacityText );
node.appendChild( layerOpacityElem );

if ( mDiagramRenderer )
{
@@ -3535,16 +3540,16 @@ QPainter::CompositionMode QgsVectorLayer::featureBlendMode() const
return mFeatureBlendMode;
}

void QgsVectorLayer::setLayerTransparency( int layerTransparency )
void QgsVectorLayer::setOpacity( double opacity )
{
mLayerTransparency = layerTransparency;
emit layerTransparencyChanged( layerTransparency );
mLayerOpacity = opacity;
emit opacityChanged( opacity );
emit styleChanged();
}

int QgsVectorLayer::layerTransparency() const
double QgsVectorLayer::opacity() const
{
return mLayerTransparency;
return mLayerOpacity;
}


@@ -355,6 +355,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
Q_PROPERTY( QgsEditFormConfig editFormConfig READ editFormConfig WRITE setEditFormConfig NOTIFY editFormConfigChanged )
Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )

public:

@@ -1508,10 +1509,23 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! Returns the current blending mode for features
QPainter::CompositionMode featureBlendMode() const;

//! Set the transparency for the vector layer
void setLayerTransparency( int layerTransparency );
//! Returns the current transparency for the vector layer
int layerTransparency() const;
/**
* Sets the \a opacity for the vector layer, where \a opacity is a value between 0 (totally transparent)
* and 1.0 (fully opaque).
* \see opacity()
* \see opacityChanged()
* \since QGIS 3.0
*/
void setOpacity( double opacity );

/**
* Returns the opacity for the vector layer, where opacity is a value between 0 (totally transparent)
* and 1.0 (fully opaque).
* \see setOpacity()
* \see opacityChanged()
* \since QGIS 3.0
*/
double opacity() const;

QString htmlMetadata() const override;

@@ -1795,8 +1809,14 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! Signal emitted when setFeatureBlendMode() is called
void featureBlendModeChanged( QPainter::CompositionMode blendMode );

//! Signal emitted when setLayerTransparency() is called
void layerTransparencyChanged( int layerTransparency );
/**
* Emitted when the layer's opacity is changed, where \a opacity is a value between 0 (transparent)
* and 1 (opaque).
* \since QGIS 3.0
* \see setOpacity()
* \see opacity()
*/
void opacityChanged( double opacity );

/**
* Signal emitted when a new edit command has been started
@@ -1994,8 +2014,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! Blend mode for features
QPainter::CompositionMode mFeatureBlendMode;

//! Layer transparency
int mLayerTransparency;
//! Layer opacity
double mLayerOpacity = 1.0;

//! Flag if the vertex markers should be drawn only for selection (true) or for all features (false)
bool mVertexMarkerOnlyForSelection;
@@ -21,7 +21,7 @@
QgsLayerTreeEmbeddedWidgetRegistry::QgsLayerTreeEmbeddedWidgetRegistry()
{
// populate with default implementations
addProvider( new QgsLayerTreeTransparencyWidget::Provider() );
addProvider( new QgsLayerTreeOpacityWidget::Provider() );
}

QgsLayerTreeEmbeddedWidgetRegistry::~QgsLayerTreeEmbeddedWidgetRegistry()

0 comments on commit bcf4026

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