29using namespace Qt::StringLiterals;
33 d =
new QgsTextShadowSettingsPrivate();
43 : d( std::move( other.d ) )
62 d = std::move( other.d );
74 if ( d->enabled != other.
enabled()
85 || d->scale != other.
scale()
86 || d->color != other.
color()
87 || d->opacity != other.
opacity()
96 return !( *
this == other );
111 return d->shadowUnder;
116 d->shadowUnder = placement;
121 return d->offsetAngle;
126 d->offsetAngle = angle;
131 return d->offsetDist;
136 d->offsetDist = distance;
141 return d->offsetUnits;
146 d->offsetUnits = units;
151 return d->offsetMapUnitScale;
156 d->offsetMapUnitScale =
scale;
161 return d->offsetGlobal;
166 d->offsetGlobal = global;
181 return d->radiusUnits;
186 d->radiusUnits = units;
191 return d->radiusMapUnitScale;
196 d->radiusMapUnitScale =
scale;
201 return d->radiusAlphaOnly;
206 d->radiusAlphaOnly = alphaOnly;
251 d->enabled = layer->
customProperty( u
"labeling/shadowDraw"_s, QVariant(
false ) ).toBool();
253 d->offsetAngle = layer->
customProperty( u
"labeling/shadowOffsetAngle"_s, QVariant( 135 ) ).toInt();
254 d->offsetDist = layer->
customProperty( u
"labeling/shadowOffsetDist"_s, QVariant( 1.0 ) ).toDouble();
256 if ( layer->
customProperty( u
"labeling/shadowOffsetUnit"_s ).toString().isEmpty() )
264 if ( layer->
customProperty( u
"labeling/shadowOffsetMapUnitScale"_s ).toString().isEmpty() )
267 const double oldMin = layer->
customProperty( u
"labeling/shadowOffsetMapUnitMinScale"_s, 0.0 ).toDouble();
268 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
269 const double oldMax = layer->
customProperty( u
"labeling/shadowOffsetMapUnitMaxScale"_s, 0.0 ).toDouble();
270 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
276 d->offsetGlobal = layer->
customProperty( u
"labeling/shadowOffsetGlobal"_s, QVariant(
true ) ).toBool();
277 d->radius = layer->
customProperty( u
"labeling/shadowRadius"_s, QVariant( 1.5 ) ).toDouble();
279 if ( layer->
customProperty( u
"labeling/shadowRadiusUnit"_s ).toString().isEmpty() )
287 if ( layer->
customProperty( u
"labeling/shadowRadiusMapUnitScale"_s ).toString().isEmpty() )
290 const double oldMin = layer->
customProperty( u
"labeling/shadowRadiusMapUnitMinScale"_s, 0.0 ).toDouble();
291 d->radiusMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
292 const double oldMax = layer->
customProperty( u
"labeling/shadowRadiusMapUnitMaxScale"_s, 0.0 ).toDouble();
293 d->radiusMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
299 d->radiusAlphaOnly = layer->
customProperty( u
"labeling/shadowRadiusAlphaOnly"_s, QVariant(
false ) ).toBool();
301 if ( layer->
customProperty( u
"labeling/shadowOpacity"_s ).toString().isEmpty() )
303 d->opacity = ( 1 - layer->
customProperty( u
"labeling/shadowTransparency"_s ).toInt() / 100.0 );
307 d->opacity = ( layer->
customProperty( u
"labeling/shadowOpacity"_s ).toDouble() );
309 d->scale = layer->
customProperty( u
"labeling/shadowScale"_s, QVariant( 100 ) ).toInt();
317 const QDomElement shadowElem = elem.firstChildElement( u
"shadow"_s );
318 d->enabled = shadowElem.attribute( u
"shadowDraw"_s, u
"0"_s ).toInt();
319 d->shadowUnder =
static_cast< ShadowPlacement >( shadowElem.attribute( u
"shadowUnder"_s, QString::number(
ShadowLowest ) ).toUInt() );
320 d->offsetAngle = shadowElem.attribute( u
"shadowOffsetAngle"_s, u
"135"_s ).toInt();
321 d->offsetDist = shadowElem.attribute( u
"shadowOffsetDist"_s, u
"1"_s ).toDouble();
323 if ( !shadowElem.hasAttribute( u
"shadowOffsetUnit"_s ) )
332 if ( !shadowElem.hasAttribute( u
"shadowOffsetMapUnitScale"_s ) )
335 const double oldMin = shadowElem.attribute( u
"shadowOffsetMapUnitMinScale"_s, u
"0"_s ).toDouble();
336 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
337 const double oldMax = shadowElem.attribute( u
"shadowOffsetMapUnitMaxScale"_s, u
"0"_s ).toDouble();
338 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
344 d->offsetGlobal = shadowElem.attribute( u
"shadowOffsetGlobal"_s, u
"1"_s ).toInt();
345 d->radius = shadowElem.attribute( u
"shadowRadius"_s, u
"1.5"_s ).toDouble();
347 if ( !shadowElem.hasAttribute( u
"shadowRadiusUnit"_s ) )
355 if ( !shadowElem.hasAttribute( u
"shadowRadiusMapUnitScale"_s ) )
358 const double oldMin = shadowElem.attribute( u
"shadowRadiusMapUnitMinScale"_s, u
"0"_s ).toDouble();
359 d->radiusMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
360 const double oldMax = shadowElem.attribute( u
"shadowRadiusMapUnitMaxScale"_s, u
"0"_s ).toDouble();
361 d->radiusMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
367 d->radiusAlphaOnly = shadowElem.attribute( u
"shadowRadiusAlphaOnly"_s, u
"0"_s ).toInt();
369 if ( !shadowElem.hasAttribute( u
"shadowOpacity"_s ) )
371 d->opacity = ( 1 - shadowElem.attribute( u
"shadowTransparency"_s ).toInt() / 100.0 );
375 d->opacity = ( shadowElem.attribute( u
"shadowOpacity"_s ).toDouble() );
377 d->scale = shadowElem.attribute( u
"shadowScale"_s, u
"100"_s ).toInt();
385 QDomElement shadowElem = doc.createElement( u
"shadow"_s );
386 shadowElem.setAttribute( u
"shadowDraw"_s, d->enabled );
387 shadowElem.setAttribute( u
"shadowUnder"_s,
static_cast< unsigned int >( d->shadowUnder ) );
388 shadowElem.setAttribute( u
"shadowOffsetAngle"_s, d->offsetAngle );
389 shadowElem.setAttribute( u
"shadowOffsetDist"_s, d->offsetDist );
392 shadowElem.setAttribute( u
"shadowOffsetGlobal"_s, d->offsetGlobal );
393 shadowElem.setAttribute( u
"shadowRadius"_s, d->radius );
396 shadowElem.setAttribute( u
"shadowRadiusAlphaOnly"_s, d->radiusAlphaOnly );
397 shadowElem.setAttribute( u
"shadowOpacity"_s, d->opacity );
398 shadowElem.setAttribute( u
"shadowScale"_s, d->scale );
416 const QString str = exprVal.toString().trimmed();
417 if ( !str.isEmpty() )
437 const QString units = exprVal.toString();
438 if ( !units.isEmpty() )
443 d->offsetUnits = res;
456 const QString units = exprVal.toString();
457 if ( !units.isEmpty() )
462 d->radiusUnits = res;
472 d->opacity = val.toDouble() / 100.0;
491 const QString blendstr = exprVal.toString().trimmed();
492 if ( !blendstr.isEmpty() )
499 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.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
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 Qgis::BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a Qgis::BlendMode.
@ ShadowOpacity
Shadow opacity.
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const final
Returns the calculated value of the property with the specified key from within the collection.
bool isActive(int key) const final
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 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.
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, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based dataset.