27 d =
new QgsTextShadowSettingsPrivate();
49 if ( d->enabled != other.
enabled()
60 || d->scale != other.
scale()
61 || d->color != other.
color()
62 || d->opacity != other.
opacity()
71 return !( *
this == other );
86 return d->shadowUnder;
91 d->shadowUnder = placement;
96 return d->offsetAngle;
101 d->offsetAngle =
angle;
106 return d->offsetDist;
111 d->offsetDist = distance;
116 return d->offsetUnits;
121 d->offsetUnits = units;
126 return d->offsetMapUnitScale;
131 d->offsetMapUnitScale =
scale;
136 return d->offsetGlobal;
141 d->offsetGlobal = global;
156 return d->radiusUnits;
161 d->radiusUnits = units;
166 return d->radiusMapUnitScale;
171 d->radiusMapUnitScale =
scale;
176 return d->radiusAlphaOnly;
181 d->radiusAlphaOnly = alphaOnly;
226 d->enabled = layer->
customProperty( QStringLiteral(
"labeling/shadowDraw" ), QVariant(
false ) ).toBool();
228 d->offsetAngle = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetAngle" ), QVariant( 135 ) ).toInt();
229 d->offsetDist = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetDist" ), QVariant( 1.0 ) ).toDouble();
231 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetUnit" ) ).toString().isEmpty() )
239 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetMapUnitScale" ) ).toString().isEmpty() )
242 const double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetMapUnitMinScale" ), 0.0 ).toDouble();
243 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
244 const double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
245 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
251 d->offsetGlobal = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetGlobal" ), QVariant(
true ) ).toBool();
252 d->radius = layer->
customProperty( QStringLiteral(
"labeling/shadowRadius" ), QVariant( 1.5 ) ).toDouble();
254 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusUnit" ) ).toString().isEmpty() )
262 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusMapUnitScale" ) ).toString().isEmpty() )
265 const double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusMapUnitMinScale" ), 0.0 ).toDouble();
266 d->radiusMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
267 const double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusMapUnitMaxScale" ), 0.0 ).toDouble();
268 d->radiusMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
274 d->radiusAlphaOnly = layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusAlphaOnly" ), QVariant(
false ) ).toBool();
276 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowOpacity" ) ).toString().isEmpty() )
278 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/shadowTransparency" ) ).toInt() / 100.0 );
282 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/shadowOpacity" ) ).toDouble() );
284 d->scale = layer->
customProperty( QStringLiteral(
"labeling/shadowScale" ), QVariant( 100 ) ).toInt();
287 static_cast< Qgis::BlendMode >( layer->
customProperty( QStringLiteral(
"labeling/shadowBlendMode" ), QVariant(
static_cast< int >( Qgis::BlendMode::Multiply ) ) ).toUInt() ) );
292 const QDomElement shadowElem = elem.firstChildElement( QStringLiteral(
"shadow" ) );
293 d->enabled = shadowElem.attribute( QStringLiteral(
"shadowDraw" ), QStringLiteral(
"0" ) ).toInt();
294 d->shadowUnder =
static_cast< ShadowPlacement >( shadowElem.attribute( QStringLiteral(
"shadowUnder" ), QString::number(
ShadowLowest ) ).toUInt() );
295 d->offsetAngle = shadowElem.attribute( QStringLiteral(
"shadowOffsetAngle" ), QStringLiteral(
"135" ) ).toInt();
296 d->offsetDist = shadowElem.attribute( QStringLiteral(
"shadowOffsetDist" ), QStringLiteral(
"1" ) ).toDouble();
298 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowOffsetUnit" ) ) )
307 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowOffsetMapUnitScale" ) ) )
310 const double oldMin = shadowElem.attribute( QStringLiteral(
"shadowOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
311 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
312 const double oldMax = shadowElem.attribute( QStringLiteral(
"shadowOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
313 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
319 d->offsetGlobal = shadowElem.attribute( QStringLiteral(
"shadowOffsetGlobal" ), QStringLiteral(
"1" ) ).toInt();
320 d->radius = shadowElem.attribute( QStringLiteral(
"shadowRadius" ), QStringLiteral(
"1.5" ) ).toDouble();
322 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowRadiusUnit" ) ) )
330 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowRadiusMapUnitScale" ) ) )
333 const double oldMin = shadowElem.attribute( QStringLiteral(
"shadowRadiusMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
334 d->radiusMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
335 const double oldMax = shadowElem.attribute( QStringLiteral(
"shadowRadiusMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
336 d->radiusMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
342 d->radiusAlphaOnly = shadowElem.attribute( QStringLiteral(
"shadowRadiusAlphaOnly" ), QStringLiteral(
"0" ) ).toInt();
344 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowOpacity" ) ) )
346 d->opacity = ( 1 - shadowElem.attribute( QStringLiteral(
"shadowTransparency" ) ).toInt() / 100.0 );
350 d->opacity = ( shadowElem.attribute( QStringLiteral(
"shadowOpacity" ) ).toDouble() );
352 d->scale = shadowElem.attribute( QStringLiteral(
"shadowScale" ), QStringLiteral(
"100" ) ).toInt();
355 static_cast< Qgis::BlendMode >( shadowElem.attribute( QStringLiteral(
"shadowBlendMode" ), QString::number(
static_cast<int>( Qgis::BlendMode::Multiply ) ) ).toUInt() ) );
360 QDomElement shadowElem = doc.createElement( QStringLiteral(
"shadow" ) );
361 shadowElem.setAttribute( QStringLiteral(
"shadowDraw" ), d->enabled );
362 shadowElem.setAttribute( QStringLiteral(
"shadowUnder" ),
static_cast< unsigned int >( d->shadowUnder ) );
363 shadowElem.setAttribute( QStringLiteral(
"shadowOffsetAngle" ), d->offsetAngle );
364 shadowElem.setAttribute( QStringLiteral(
"shadowOffsetDist" ), d->offsetDist );
367 shadowElem.setAttribute( QStringLiteral(
"shadowOffsetGlobal" ), d->offsetGlobal );
368 shadowElem.setAttribute( QStringLiteral(
"shadowRadius" ), d->radius );
371 shadowElem.setAttribute( QStringLiteral(
"shadowRadiusAlphaOnly" ), d->radiusAlphaOnly );
372 shadowElem.setAttribute( QStringLiteral(
"shadowOpacity" ), d->opacity );
373 shadowElem.setAttribute( QStringLiteral(
"shadowScale" ), d->scale );
391 const QString
str = exprVal.toString().trimmed();
392 if ( !
str.isEmpty() )
412 const QString units = exprVal.toString();
413 if ( !units.isEmpty() )
418 d->offsetUnits = res;
431 const QString units = exprVal.toString();
432 if ( !units.isEmpty() )
437 d->radiusUnits = res;
447 d->opacity = val.toDouble() / 100.0;
466 const QString blendstr = exprVal.toString().trimmed();
467 if ( !blendstr.isEmpty() )
474 return QSet< QString >();
BlendMode
Blending modes defining the available composition modes that can be used when painting.
RenderUnit
Rendering size units.
QColor valueAsColor(int key, const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a color.
int valueAsInt(int key, const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an integer.
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
Struct for storing maximum and minimum scales for measurements in map units.
static Qgis::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
@ ShadowOpacity
Shadow opacity.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the property with the specified key from within the collection.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
Contains information about the context of a rendering operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QColor decodeColor(const QString &str)
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static QPainter::CompositionMode decodeBlendMode(const QString &s)
static QString encodeColor(const QColor &color)
static QColor readColor(QgsVectorLayer *layer, const QString &property, const QColor &defaultColor=Qt::black, bool withAlpha=true)
Converts an encoded color value from a layer property.
static QgsTextShadowSettings::ShadowPlacement decodeShadowPlacementType(const QString &string)
Decodes a string representation of a shadow placement type to a type.
static Qgis::RenderUnit convertFromOldLabelUnit(int val)
Converts a unit from an old (pre 3.0) label unit.
Container for settings relating to a text shadow.
int offsetAngle() const
Returns the angle for offsetting the position of the shadow from the text.
void setBlurRadiusMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shadow blur radius.
QgsTextShadowSettings & operator=(const QgsTextShadowSettings &other)
void setBlurRadiusUnit(Qgis::RenderUnit units)
Sets the units used for the shadow's blur radius.
bool enabled() const
Returns whether the shadow is enabled.
void setOffsetUnit(Qgis::RenderUnit units)
Sets the units used for the shadow's offset.
int scale() const
Returns the scaling used for the drop shadow (in percentage of original size).
Qgis::RenderUnit offsetUnit() const
Returns the units used for the shadow's offset.
void setShadowPlacement(QgsTextShadowSettings::ShadowPlacement placement)
Sets the placement for the drop shadow.
double opacity() const
Returns the shadow's opacity.
QgsMapUnitScale blurRadiusMapUnitScale() const
Returns the map unit scale object for the shadow blur radius.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shadow offset distance.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the drop shadow.
void setColor(const QColor &color)
Sets the color for the drop shadow.
QColor color() const
Returns the color of the drop shadow.
void readXml(const QDomElement &elem)
Read settings from a DOM element.
void setOffsetGlobal(bool global)
Sets whether the global shadow offset should be used.
ShadowPlacement
Placement positions for text shadow.
@ ShadowLowest
Draw shadow below all text components.
QDomElement writeXml(QDomDocument &doc) const
Write settings into a DOM element.
void setScale(int scale)
Sets the scaling used for the drop shadow (in percentage of original size).
void setBlurAlphaOnly(bool alphaOnly)
Sets whether only the alpha channel for the shadow should be blurred.
QgsTextShadowSettings::ShadowPlacement shadowPlacement() const
Returns the placement for the drop shadow.
Qgis::RenderUnit blurRadiusUnit() const
Returns the units used for the shadow's blur radius.
double offsetDistance() const
Returns the distance for offsetting the position of the shadow from the text.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the drop shadow.
void setOffsetDistance(double distance)
Sets the distance for offsetting the position of the shadow from the text.
void setOpacity(double opacity)
Sets the shadow's opacity.
QgsMapUnitScale offsetMapUnitScale() const
Returns the map unit scale object for the shadow offset distance.
bool operator==(const QgsTextShadowSettings &other) const
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
bool blurAlphaOnly() const
Returns whether only the alpha channel for the shadow will be blurred.
bool offsetGlobal() const
Returns true if the global shadow offset will be used.
void setOffsetAngle(int angle)
Sets the angle for offsetting the position of the shadow from the text.
bool operator!=(const QgsTextShadowSettings &other) const
double blurRadius() const
Returns the blur radius for the shadow.
void setBlurRadius(double blurRadius)
Sets the blur radius for the shadow.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
void setEnabled(bool enabled)
Sets whether the text shadow will be drawn.
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
static bool isNull(const QVariant &variant)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based data sets.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)