31 d =
new QgsTextBufferSettingsPrivate();
52 if ( d->enabled != other.
enabled()
53 || d->size != other.
size()
56 || d->color != other.
color()
57 || d->opacity != other.
opacity()
63 if (
static_cast< bool >( d->paintEffect ) !=
static_cast< bool >( other.
paintEffect() )
72 return !( *
this == other );
107 return d->sizeMapUnitScale;
112 d->sizeMapUnitScale = scale;
127 return d->fillBufferInterior;
132 d->fillBufferInterior = fill;
152 d->joinStyle = style;
167 return d->paintEffect.get();
172 d->paintEffect.reset( effect );
192 const QString units = exprVal.toString();
193 if ( !units.isEmpty() )
208 d->opacity = val.toDouble() / 100.0;
221 const QString blendstr = exprVal.toString().trimmed();
222 if ( !blendstr.isEmpty() )
229 const QString joinstr = exprVal.toString().trimmed();
230 if ( !joinstr.isEmpty() )
239 return QSet< QString >();
245 const double bufSize = layer->
customProperty( QStringLiteral(
"labeling/bufferSize" ), QVariant( 0.0 ) ).toDouble();
248 const QVariant drawBuffer = layer->
customProperty( QStringLiteral(
"labeling/bufferDraw" ), QVariant() );
249 if ( drawBuffer.isValid() )
251 d->enabled = drawBuffer.toBool();
254 else if ( bufSize != 0.0 )
265 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferSizeUnits" ) ).toString().isEmpty() )
267 const bool bufferSizeInMapUnits = layer->
customProperty( QStringLiteral(
"labeling/bufferSizeInMapUnits" ) ).toBool();
275 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferSizeMapUnitScale" ) ).toString().isEmpty() )
278 const double oldMin = layer->
customProperty( QStringLiteral(
"labeling/bufferSizeMapUnitMinScale" ), 0.0 ).toDouble();
279 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
280 const double oldMax = layer->
customProperty( QStringLiteral(
"labeling/bufferSizeMapUnitMaxScale" ), 0.0 ).toDouble();
281 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
288 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferOpacity" ) ).toString().isEmpty() )
290 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/bufferTransp" ) ).toInt() / 100.0 );
294 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/bufferOpacity" ) ).toDouble() );
298 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( layer->
customProperty( QStringLiteral(
"labeling/bufferJoinStyle" ), QVariant( Qt::RoundJoin ) ).toUInt() );
300 d->fillBufferInterior = !layer->
customProperty( QStringLiteral(
"labeling/bufferNoFill" ), QVariant(
false ) ).toBool();
302 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferEffect" ) ).isValid() )
304 QDomDocument doc( QStringLiteral(
"effect" ) );
305 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/bufferEffect" ) ).toString() );
306 const QDomElement effectElem = doc.firstChildElement( QStringLiteral(
"effect" ) ).firstChildElement( QStringLiteral(
"effect" ) );
315 const QDomElement textBufferElem = elem.firstChildElement( QStringLiteral(
"text-buffer" ) );
316 const double bufSize = textBufferElem.attribute( QStringLiteral(
"bufferSize" ), QStringLiteral(
"0" ) ).toDouble();
319 const QVariant drawBuffer = textBufferElem.attribute( QStringLiteral(
"bufferDraw" ) );
320 if ( drawBuffer.isValid() )
322 d->enabled = drawBuffer.toBool();
325 else if ( bufSize != 0.0 )
336 if ( !textBufferElem.hasAttribute( QStringLiteral(
"bufferSizeUnits" ) ) )
338 const bool bufferSizeInMapUnits = textBufferElem.attribute( QStringLiteral(
"bufferSizeInMapUnits" ) ).toInt();
346 if ( !textBufferElem.hasAttribute( QStringLiteral(
"bufferSizeMapUnitScale" ) ) )
349 const double oldMin = textBufferElem.attribute( QStringLiteral(
"bufferSizeMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
350 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
351 const double oldMax = textBufferElem.attribute( QStringLiteral(
"bufferSizeMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
352 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
360 if ( !textBufferElem.hasAttribute( QStringLiteral(
"bufferOpacity" ) ) )
362 d->opacity = ( 1 - textBufferElem.attribute( QStringLiteral(
"bufferTransp" ) ).toInt() / 100.0 );
366 d->opacity = ( textBufferElem.attribute( QStringLiteral(
"bufferOpacity" ) ).toDouble() );
371 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( textBufferElem.attribute( QStringLiteral(
"bufferJoinStyle" ), QString::number( Qt::RoundJoin ) ).toUInt() );
372 d->fillBufferInterior = !textBufferElem.attribute( QStringLiteral(
"bufferNoFill" ), QStringLiteral(
"0" ) ).toInt();
373 const QDomElement effectElem = textBufferElem.firstChildElement( QStringLiteral(
"effect" ) );
374 if ( !effectElem.isNull() )
383 QDomElement textBufferElem = doc.createElement( QStringLiteral(
"text-buffer" ) );
384 textBufferElem.setAttribute( QStringLiteral(
"bufferDraw" ), d->enabled );
385 textBufferElem.setAttribute( QStringLiteral(
"bufferSize" ), d->size );
389 textBufferElem.setAttribute( QStringLiteral(
"bufferNoFill" ), !d->fillBufferInterior );
390 textBufferElem.setAttribute( QStringLiteral(
"bufferOpacity" ), d->opacity );
391 textBufferElem.setAttribute( QStringLiteral(
"bufferJoinStyle" ),
static_cast< unsigned int >( d->joinStyle ) );
394 d->paintEffect->saveProperties( doc, textBufferElem );
395 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.
QgsPaintEffect * createEffect(const QString &name, const QVariantMap &properties=QVariantMap()) const
Creates a new paint effect given the effect name and properties map.
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 a 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)
Container for settings relating to a text buffer.
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 data sets.