32using namespace Qt::StringLiterals;
36 d =
new QgsTextBufferSettingsPrivate();
44 : d( std::move( other.d ) )
62 d = std::move( other.d );
73 if ( d->enabled != other.
enabled()
74 || d->size != other.
size()
77 || d->color != other.
color()
78 || d->opacity != other.
opacity()
84 if (
static_cast< bool >( d->paintEffect ) !=
static_cast< bool >( other.
paintEffect() )
93 return !( *
this == other );
128 return d->sizeMapUnitScale;
133 d->sizeMapUnitScale = scale;
148 return d->fillBufferInterior;
153 d->fillBufferInterior = fill;
173 d->joinStyle = style;
188 return d->paintEffect.get();
193 d->paintEffect.reset( effect );
213 const QString units = exprVal.toString();
214 if ( !units.isEmpty() )
229 d->opacity = val.toDouble() / 100.0;
242 const QString blendstr = exprVal.toString().trimmed();
243 if ( !blendstr.isEmpty() )
250 const QString joinstr = exprVal.toString().trimmed();
251 if ( !joinstr.isEmpty() )
260 return QSet< QString >();
266 const double bufSize = layer->
customProperty( u
"labeling/bufferSize"_s, QVariant( 0.0 ) ).toDouble();
269 const QVariant drawBuffer = layer->
customProperty( u
"labeling/bufferDraw"_s, QVariant() );
270 if ( drawBuffer.isValid() )
272 d->enabled = drawBuffer.toBool();
275 else if ( bufSize != 0.0 )
286 if ( layer->
customProperty( u
"labeling/bufferSizeUnits"_s ).toString().isEmpty() )
288 const bool bufferSizeInMapUnits = layer->
customProperty( u
"labeling/bufferSizeInMapUnits"_s ).toBool();
296 if ( layer->
customProperty( u
"labeling/bufferSizeMapUnitScale"_s ).toString().isEmpty() )
299 const double oldMin = layer->
customProperty( u
"labeling/bufferSizeMapUnitMinScale"_s, 0.0 ).toDouble();
300 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
301 const double oldMax = layer->
customProperty( u
"labeling/bufferSizeMapUnitMaxScale"_s, 0.0 ).toDouble();
302 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
309 if ( layer->
customProperty( u
"labeling/bufferOpacity"_s ).toString().isEmpty() )
311 d->opacity = ( 1 - layer->
customProperty( u
"labeling/bufferTransp"_s ).toInt() / 100.0 );
315 d->opacity = ( layer->
customProperty( u
"labeling/bufferOpacity"_s ).toDouble() );
319 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( layer->
customProperty( u
"labeling/bufferJoinStyle"_s, QVariant( Qt::RoundJoin ) ).toUInt() );
321 d->fillBufferInterior = !layer->
customProperty( u
"labeling/bufferNoFill"_s, QVariant(
false ) ).toBool();
323 if ( layer->
customProperty( u
"labeling/bufferEffect"_s ).isValid() )
325 QDomDocument doc( u
"effect"_s );
326 doc.setContent( layer->
customProperty( u
"labeling/bufferEffect"_s ).toString() );
327 const QDomElement effectElem = doc.firstChildElement( u
"effect"_s ).firstChildElement( u
"effect"_s );
336 const QDomElement textBufferElem = elem.firstChildElement( u
"text-buffer"_s );
337 const double bufSize = textBufferElem.attribute( u
"bufferSize"_s, u
"0"_s ).toDouble();
340 const QVariant drawBuffer = textBufferElem.attribute( u
"bufferDraw"_s );
341 if ( drawBuffer.isValid() )
343 d->enabled = drawBuffer.toBool();
346 else if ( bufSize != 0.0 )
357 if ( !textBufferElem.hasAttribute( u
"bufferSizeUnits"_s ) )
359 const bool bufferSizeInMapUnits = textBufferElem.attribute( u
"bufferSizeInMapUnits"_s ).toInt();
367 if ( !textBufferElem.hasAttribute( u
"bufferSizeMapUnitScale"_s ) )
370 const double oldMin = textBufferElem.attribute( u
"bufferSizeMapUnitMinScale"_s, u
"0"_s ).toDouble();
371 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
372 const double oldMax = textBufferElem.attribute( u
"bufferSizeMapUnitMaxScale"_s, u
"0"_s ).toDouble();
373 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
381 if ( !textBufferElem.hasAttribute( u
"bufferOpacity"_s ) )
383 d->opacity = ( 1 - textBufferElem.attribute( u
"bufferTransp"_s ).toInt() / 100.0 );
387 d->opacity = ( textBufferElem.attribute( u
"bufferOpacity"_s ).toDouble() );
392 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( textBufferElem.attribute( u
"bufferJoinStyle"_s, QString::number( Qt::RoundJoin ) ).toUInt() );
393 d->fillBufferInterior = !textBufferElem.attribute( u
"bufferNoFill"_s, u
"0"_s ).toInt();
394 const QDomElement effectElem = textBufferElem.firstChildElement( u
"effect"_s );
395 if ( !effectElem.isNull() )
404 QDomElement textBufferElem = doc.createElement( u
"text-buffer"_s );
405 textBufferElem.setAttribute( u
"bufferDraw"_s, d->enabled );
406 textBufferElem.setAttribute( u
"bufferSize"_s, d->size );
410 textBufferElem.setAttribute( u
"bufferNoFill"_s, !d->fillBufferInterior );
411 textBufferElem.setAttribute( u
"bufferOpacity"_s, d->opacity );
412 textBufferElem.setAttribute( u
"bufferJoinStyle"_s,
static_cast< unsigned int >( d->joinStyle ) );
415 d->paintEffect->saveProperties( doc, textBufferElem );
416 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.