32using namespace Qt::StringLiterals;
36 d =
new QgsTextBufferSettingsPrivate();
43 : d( std::move( other.d ) )
60 d = std::move( other.d );
69 if ( d->enabled != other.
enabled()
70 || d->size != other.
size()
73 || d->color != other.
color()
74 || d->opacity != other.
opacity()
80 if (
static_cast< bool >( d->paintEffect ) !=
static_cast< bool >( other.
paintEffect() ) || ( d->paintEffect && d->paintEffect->properties() != other.
paintEffect()->
properties() ) )
88 return !( *
this == other );
123 return d->sizeMapUnitScale;
128 d->sizeMapUnitScale = scale;
143 return d->fillBufferInterior;
148 d->fillBufferInterior = fill;
168 d->joinStyle = style;
183 return d->paintEffect.get();
188 d->paintEffect.reset( effect );
208 const QString units = exprVal.toString();
209 if ( !units.isEmpty() )
224 d->opacity = val.toDouble() / 100.0;
237 const QString blendstr = exprVal.toString().trimmed();
238 if ( !blendstr.isEmpty() )
245 const QString joinstr = exprVal.toString().trimmed();
246 if ( !joinstr.isEmpty() )
255 return QSet< QString >();
261 const double bufSize = layer->
customProperty( u
"labeling/bufferSize"_s, QVariant( 0.0 ) ).toDouble();
264 const QVariant drawBuffer = layer->
customProperty( u
"labeling/bufferDraw"_s, QVariant() );
265 if ( drawBuffer.isValid() )
267 d->enabled = drawBuffer.toBool();
270 else if ( bufSize != 0.0 )
281 if ( layer->
customProperty( u
"labeling/bufferSizeUnits"_s ).toString().isEmpty() )
283 const bool bufferSizeInMapUnits = layer->
customProperty( u
"labeling/bufferSizeInMapUnits"_s ).toBool();
291 if ( layer->
customProperty( u
"labeling/bufferSizeMapUnitScale"_s ).toString().isEmpty() )
294 const double oldMin = layer->
customProperty( u
"labeling/bufferSizeMapUnitMinScale"_s, 0.0 ).toDouble();
295 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
296 const double oldMax = layer->
customProperty( u
"labeling/bufferSizeMapUnitMaxScale"_s, 0.0 ).toDouble();
297 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
304 if ( layer->
customProperty( u
"labeling/bufferOpacity"_s ).toString().isEmpty() )
306 d->opacity = ( 1 - layer->
customProperty( u
"labeling/bufferTransp"_s ).toInt() / 100.0 );
310 d->opacity = ( layer->
customProperty( u
"labeling/bufferOpacity"_s ).toDouble() );
315 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( layer->
customProperty( u
"labeling/bufferJoinStyle"_s, QVariant( Qt::RoundJoin ) ).toUInt() );
317 d->fillBufferInterior = !layer->
customProperty( u
"labeling/bufferNoFill"_s, QVariant(
false ) ).toBool();
319 if ( layer->
customProperty( u
"labeling/bufferEffect"_s ).isValid() )
321 QDomDocument doc( u
"effect"_s );
322 doc.setContent( layer->
customProperty( u
"labeling/bufferEffect"_s ).toString() );
323 const QDomElement effectElem = doc.firstChildElement( u
"effect"_s ).firstChildElement( u
"effect"_s );
332 const QDomElement textBufferElem = elem.firstChildElement( u
"text-buffer"_s );
333 const double bufSize = textBufferElem.attribute( u
"bufferSize"_s, u
"0"_s ).toDouble();
336 const QVariant drawBuffer = textBufferElem.attribute( u
"bufferDraw"_s );
337 if ( drawBuffer.isValid() )
339 d->enabled = drawBuffer.toBool();
342 else if ( bufSize != 0.0 )
353 if ( !textBufferElem.hasAttribute( u
"bufferSizeUnits"_s ) )
355 const bool bufferSizeInMapUnits = textBufferElem.attribute( u
"bufferSizeInMapUnits"_s ).toInt();
363 if ( !textBufferElem.hasAttribute( u
"bufferSizeMapUnitScale"_s ) )
366 const double oldMin = textBufferElem.attribute( u
"bufferSizeMapUnitMinScale"_s, u
"0"_s ).toDouble();
367 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
368 const double oldMax = textBufferElem.attribute( u
"bufferSizeMapUnitMaxScale"_s, u
"0"_s ).toDouble();
369 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
377 if ( !textBufferElem.hasAttribute( u
"bufferOpacity"_s ) )
379 d->opacity = ( 1 - textBufferElem.attribute( u
"bufferTransp"_s ).toInt() / 100.0 );
383 d->opacity = ( textBufferElem.attribute( u
"bufferOpacity"_s ).toDouble() );
389 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( textBufferElem.attribute( u
"bufferJoinStyle"_s, QString::number( Qt::RoundJoin ) ).toUInt() );
390 d->fillBufferInterior = !textBufferElem.attribute( u
"bufferNoFill"_s, u
"0"_s ).toInt();
391 const QDomElement effectElem = textBufferElem.firstChildElement( u
"effect"_s );
392 if ( !effectElem.isNull() )
401 QDomElement textBufferElem = doc.createElement( u
"text-buffer"_s );
402 textBufferElem.setAttribute( u
"bufferDraw"_s, d->enabled );
403 textBufferElem.setAttribute( u
"bufferSize"_s, d->size );
407 textBufferElem.setAttribute( u
"bufferNoFill"_s, !d->fillBufferInterior );
408 textBufferElem.setAttribute( u
"bufferOpacity"_s, d->opacity );
409 textBufferElem.setAttribute( u
"bufferJoinStyle"_s,
static_cast< unsigned int >( d->joinStyle ) );
412 d->paintEffect->saveProperties( doc, textBufferElem );
413 return textBufferElem;
BlendMode
Blending modes defining the available composition modes that can be used when painting.
RenderUnit
Rendering size units.
@ Millimeters
Millimeters.
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.
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 QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects.
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 bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
Base class for visual effects which can be applied to QPicture drawings.
virtual QVariantMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
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.
@ BufferOpacity
Buffer 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 Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
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)
QgsTextBufferSettings & operator=(const QgsTextBufferSettings &other)
void setFillBufferInterior(bool fill)
Sets whether the interior of the buffer will be filled in.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the buffer.
Qgis::RenderUnit sizeUnit() const
Returns the units for the buffer size.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
double size() const
Returns the size of the buffer.
void setColor(const QColor &color)
Sets the color for the buffer.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the buffer size.
void setOpacity(double opacity)
Sets the buffer opacity.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the buffer size.
bool enabled() const
Returns whether the buffer is enabled.
double opacity() const
Returns the buffer opacity.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units used for the buffer size.
bool operator!=(const QgsTextBufferSettings &other) const
QDomElement writeXml(QDomDocument &doc) const
Write settings into a DOM element.
bool fillBufferInterior() const
Returns whether the interior of the buffer will be filled in.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the buffer.
const QgsPaintEffect * paintEffect() const
Returns the current paint effect for the buffer.
QColor color() const
Returns the color of the buffer.
bool operator==(const QgsTextBufferSettings &other) const
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the buffer.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the buffer.
void setSize(double size)
Sets the size of the buffer.
void readXml(const QDomElement &elem)
Read settings from a DOM element.
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 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.