QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
26 d =
new QgsTextShadowSettingsPrivate();
48 if ( d->enabled != other.
enabled()
59 || d->scale != other.
scale()
60 || d->color != other.
color()
61 || d->opacity != other.
opacity()
70 return !( *
this == other );
85 return d->shadowUnder;
90 d->shadowUnder = placement;
95 return d->offsetAngle;
100 d->offsetAngle =
angle;
105 return d->offsetDist;
110 d->offsetDist = distance;
115 return d->offsetUnits;
120 d->offsetUnits = units;
125 return d->offsetMapUnitScale;
130 d->offsetMapUnitScale =
scale;
135 return d->offsetGlobal;
140 d->offsetGlobal = global;
155 return d->radiusUnits;
160 d->radiusUnits = units;
165 return d->radiusMapUnitScale;
170 d->radiusMapUnitScale =
scale;
175 return d->radiusAlphaOnly;
180 d->radiusAlphaOnly = alphaOnly;
225 d->enabled = layer->
customProperty( QStringLiteral(
"labeling/shadowDraw" ), QVariant(
false ) ).toBool();
227 d->offsetAngle = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetAngle" ), QVariant( 135 ) ).toInt();
228 d->offsetDist = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetDist" ), QVariant( 1.0 ) ).toDouble();
230 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetUnit" ) ).toString().isEmpty() )
238 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetMapUnitScale" ) ).toString().isEmpty() )
241 const double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetMapUnitMinScale" ), 0.0 ).toDouble();
242 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
243 const double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
244 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
250 d->offsetGlobal = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetGlobal" ), QVariant(
true ) ).toBool();
251 d->radius = layer->
customProperty( QStringLiteral(
"labeling/shadowRadius" ), QVariant( 1.5 ) ).toDouble();
253 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusUnit" ) ).toString().isEmpty() )
261 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusMapUnitScale" ) ).toString().isEmpty() )
264 const double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusMapUnitMinScale" ), 0.0 ).toDouble();
265 d->radiusMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
266 const double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusMapUnitMaxScale" ), 0.0 ).toDouble();
267 d->radiusMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
273 d->radiusAlphaOnly = layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusAlphaOnly" ), QVariant(
false ) ).toBool();
275 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowOpacity" ) ).toString().isEmpty() )
277 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/shadowTransparency" ) ).toInt() / 100.0 );
281 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/shadowOpacity" ) ).toDouble() );
283 d->scale = layer->
customProperty( QStringLiteral(
"labeling/shadowScale" ), QVariant( 100 ) ).toInt();
291 const QDomElement shadowElem = elem.firstChildElement( QStringLiteral(
"shadow" ) );
292 d->enabled = shadowElem.attribute( QStringLiteral(
"shadowDraw" ), QStringLiteral(
"0" ) ).toInt();
293 d->shadowUnder =
static_cast< ShadowPlacement >( shadowElem.attribute( QStringLiteral(
"shadowUnder" ), QString::number(
ShadowLowest ) ).toUInt() );
294 d->offsetAngle = shadowElem.attribute( QStringLiteral(
"shadowOffsetAngle" ), QStringLiteral(
"135" ) ).toInt();
295 d->offsetDist = shadowElem.attribute( QStringLiteral(
"shadowOffsetDist" ), QStringLiteral(
"1" ) ).toDouble();
297 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowOffsetUnit" ) ) )
306 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowOffsetMapUnitScale" ) ) )
309 const double oldMin = shadowElem.attribute( QStringLiteral(
"shadowOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
310 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
311 const double oldMax = shadowElem.attribute( QStringLiteral(
"shadowOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
312 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
318 d->offsetGlobal = shadowElem.attribute( QStringLiteral(
"shadowOffsetGlobal" ), QStringLiteral(
"1" ) ).toInt();
319 d->radius = shadowElem.attribute( QStringLiteral(
"shadowRadius" ), QStringLiteral(
"1.5" ) ).toDouble();
321 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowRadiusUnit" ) ) )
329 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowRadiusMapUnitScale" ) ) )
332 const double oldMin = shadowElem.attribute( QStringLiteral(
"shadowRadiusMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
333 d->radiusMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
334 const double oldMax = shadowElem.attribute( QStringLiteral(
"shadowRadiusMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
335 d->radiusMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
341 d->radiusAlphaOnly = shadowElem.attribute( QStringLiteral(
"shadowRadiusAlphaOnly" ), QStringLiteral(
"0" ) ).toInt();
343 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowOpacity" ) ) )
345 d->opacity = ( 1 - shadowElem.attribute( QStringLiteral(
"shadowTransparency" ) ).toInt() / 100.0 );
349 d->opacity = ( shadowElem.attribute( QStringLiteral(
"shadowOpacity" ) ).toDouble() );
351 d->scale = shadowElem.attribute( QStringLiteral(
"shadowScale" ), QStringLiteral(
"100" ) ).toInt();
359 QDomElement shadowElem = doc.createElement( QStringLiteral(
"shadow" ) );
360 shadowElem.setAttribute( QStringLiteral(
"shadowDraw" ), d->enabled );
361 shadowElem.setAttribute( QStringLiteral(
"shadowUnder" ),
static_cast< unsigned int >( d->shadowUnder ) );
362 shadowElem.setAttribute( QStringLiteral(
"shadowOffsetAngle" ), d->offsetAngle );
363 shadowElem.setAttribute( QStringLiteral(
"shadowOffsetDist" ), d->offsetDist );
366 shadowElem.setAttribute( QStringLiteral(
"shadowOffsetGlobal" ), d->offsetGlobal );
367 shadowElem.setAttribute( QStringLiteral(
"shadowRadius" ), d->radius );
370 shadowElem.setAttribute( QStringLiteral(
"shadowRadiusAlphaOnly" ), d->radiusAlphaOnly );
371 shadowElem.setAttribute( QStringLiteral(
"shadowOpacity" ), d->opacity );
372 shadowElem.setAttribute( QStringLiteral(
"shadowScale" ), d->scale );
388 if ( !exprVal.isNull() )
390 const QString
str = exprVal.toString().trimmed();
391 if ( !
str.isEmpty() )
409 if ( !exprVal.isNull() )
411 const QString units = exprVal.toString();
412 if ( !units.isEmpty() )
417 d->offsetUnits = res;
428 if ( !exprVal.isNull() )
430 const QString units = exprVal.toString();
431 if ( !units.isEmpty() )
436 d->radiusUnits = res;
446 d->opacity = val.toDouble() / 100.0;
465 const QString blendstr = exprVal.toString().trimmed();
466 if ( !blendstr.isEmpty() )
473 return QSet< QString >();
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
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 QString encodeColor(const QColor &color)
void setOpacity(double opacity)
Sets the shadow's opacity.
static QPainter::CompositionMode decodeBlendMode(const QString &s)
double offsetDistance() const
Returns the distance for offsetting the position of the shadow from the text.
void setEnabled(bool enabled)
Sets whether the text shadow will be drawn.
RenderUnit
Rendering size units.
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.
QgsExpressionContext & expressionContext()
Gets the expression context.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
QgsMapUnitScale blurRadiusMapUnitScale() const
Returns the map unit scale object for the shadow blur radius.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units used for the shadow's offset.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
void readXml(const QDomElement &elem)
Read settings from a DOM element.
int scale() const
Returns the scaling used for the drop shadow (in percentage of original size).
Contains information about the context of a rendering operation.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shadow offset distance.
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.
double blurRadius() const
Returns the blur radius for the shadow.
static QColor decodeColor(const QString &str)
QgsTextShadowSettings & operator=(const QgsTextShadowSettings &other)
void setOffsetDistance(double distance)
Sets the distance for offsetting the position of the shadow from the text.
void setOffsetAngle(int angle)
Sets the angle for offsetting the position of the shadow from the text.
bool enabled() const
Returns whether the shadow is enabled.
QDomElement writeXml(QDomDocument &doc) const
Write settings into a DOM element.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
bool blurAlphaOnly() const
Returns whether only the alpha channel for the shadow will be blurred.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the drop shadow.
ShadowPlacement
Placement positions for text shadow.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
static QgsTextShadowSettings::ShadowPlacement decodeShadowPlacementType(const QString &string)
Decodes a string representation of a shadow placement type to a type.
void setColor(const QColor &color)
Sets the color for the drop shadow.
@ ShadowLowest
Draw shadow below all text components.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
QgsMapUnitScale offsetMapUnitScale() const
Returns the map unit scale object for the shadow offset distance.
QColor color() const
Returns the color of the drop shadow.
void setBlurRadius(double blurRadius)
Sets the blur radius for the shadow.
void setShadowPlacement(QgsTextShadowSettings::ShadowPlacement placement)
Sets the placement for the drop shadow.
bool offsetGlobal() const
Returns true if the global shadow offset will be used.
Struct for storing maximum and minimum scales for measurements in map units.
void setScale(int scale)
Sets the scaling used for the drop shadow (in percentage of original size).
void setOffsetGlobal(bool global)
Sets whether the global shadow offset should be used.
void setOffsetUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shadow's offset.
int offsetAngle() const
Returns the angle for offsetting the position of the shadow from the text.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
void setBlurRadiusUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shadow's blur radius.
Container for settings relating to a text shadow.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
void setBlurAlphaOnly(bool alphaOnly)
Sets whether only the alpha channel for the shadow should be blurred.
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 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.
Represents a vector layer which manages a vector based data sets.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
@ ShadowOpacity
Shadow opacity.
double opacity() const
Returns the shadow's opacity.
void setBlurRadiusMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shadow blur radius.
bool operator==(const QgsTextShadowSettings &other) const
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the drop shadow.
QgsTextShadowSettings::ShadowPlacement shadowPlacement() const
Returns the placement for the drop shadow.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
static QgsUnitTypes::RenderUnit convertFromOldLabelUnit(int val)
Converts a unit from an old (pre 3.0) label unit.
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)
bool operator!=(const QgsTextShadowSettings &other) const
QgsUnitTypes::RenderUnit blurRadiusUnit() const
Returns the units used for the shadow's blur radius.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
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.