QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
28 d =
new QgsTextBufferSettingsPrivate();
79 return d->sizeMapUnitScale;
84 d->sizeMapUnitScale = scale;
99 return d->fillBufferInterior;
104 d->fillBufferInterior = fill;
124 d->joinStyle = style;
139 return d->paintEffect.get();
144 d->paintEffect.reset( effect );
162 if ( exprVal.isValid() )
164 QString units = exprVal.toString();
165 if ( !units.isEmpty() )
189 QString blendstr = exprVal.toString().trimmed();
190 if ( !blendstr.isEmpty() )
197 QString joinstr = exprVal.toString().trimmed();
198 if ( !joinstr.isEmpty() )
207 return QSet< QString >();
213 double bufSize = layer->
customProperty( QStringLiteral(
"labeling/bufferSize" ), QVariant( 0.0 ) ).toDouble();
216 QVariant drawBuffer = layer->
customProperty( QStringLiteral(
"labeling/bufferDraw" ), QVariant() );
217 if ( drawBuffer.isValid() )
219 d->enabled = drawBuffer.toBool();
222 else if ( bufSize != 0.0 )
233 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferSizeUnits" ) ).toString().isEmpty() )
235 bool bufferSizeInMapUnits = layer->
customProperty( QStringLiteral(
"labeling/bufferSizeInMapUnits" ) ).toBool();
243 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferSizeMapUnitScale" ) ).toString().isEmpty() )
246 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/bufferSizeMapUnitMinScale" ), 0.0 ).toDouble();
247 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
248 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/bufferSizeMapUnitMaxScale" ), 0.0 ).toDouble();
249 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
256 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferOpacity" ) ).toString().isEmpty() )
258 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/bufferTransp" ) ).toInt() / 100.0 );
262 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/bufferOpacity" ) ).toDouble() );
266 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( layer->
customProperty( QStringLiteral(
"labeling/bufferJoinStyle" ), QVariant( Qt::RoundJoin ) ).toUInt() );
268 d->fillBufferInterior = !layer->
customProperty( QStringLiteral(
"labeling/bufferNoFill" ), QVariant(
false ) ).toBool();
270 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferEffect" ) ).isValid() )
272 QDomDocument doc( QStringLiteral(
"effect" ) );
273 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/bufferEffect" ) ).toString() );
274 QDomElement effectElem = doc.firstChildElement( QStringLiteral(
"effect" ) ).firstChildElement( QStringLiteral(
"effect" ) );
283 QDomElement textBufferElem = elem.firstChildElement( QStringLiteral(
"text-buffer" ) );
284 double bufSize = textBufferElem.attribute( QStringLiteral(
"bufferSize" ), QStringLiteral(
"0" ) ).toDouble();
287 QVariant drawBuffer = textBufferElem.attribute( QStringLiteral(
"bufferDraw" ) );
288 if ( drawBuffer.isValid() )
290 d->enabled = drawBuffer.toBool();
293 else if ( bufSize != 0.0 )
304 if ( !textBufferElem.hasAttribute( QStringLiteral(
"bufferSizeUnits" ) ) )
306 bool bufferSizeInMapUnits = textBufferElem.attribute( QStringLiteral(
"bufferSizeInMapUnits" ) ).toInt();
314 if ( !textBufferElem.hasAttribute( QStringLiteral(
"bufferSizeMapUnitScale" ) ) )
317 double oldMin = textBufferElem.attribute( QStringLiteral(
"bufferSizeMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
318 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
319 double oldMax = textBufferElem.attribute( QStringLiteral(
"bufferSizeMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
320 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
328 if ( !textBufferElem.hasAttribute( QStringLiteral(
"bufferOpacity" ) ) )
330 d->opacity = ( 1 - textBufferElem.attribute( QStringLiteral(
"bufferTransp" ) ).toInt() / 100.0 );
334 d->opacity = ( textBufferElem.attribute( QStringLiteral(
"bufferOpacity" ) ).toDouble() );
339 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( textBufferElem.attribute( QStringLiteral(
"bufferJoinStyle" ), QString::number( Qt::RoundJoin ) ).toUInt() );
340 d->fillBufferInterior = !textBufferElem.attribute( QStringLiteral(
"bufferNoFill" ), QStringLiteral(
"0" ) ).toInt();
341 QDomElement effectElem = textBufferElem.firstChildElement( QStringLiteral(
"effect" ) );
342 if ( !effectElem.isNull() )
351 QDomElement textBufferElem = doc.createElement( QStringLiteral(
"text-buffer" ) );
352 textBufferElem.setAttribute( QStringLiteral(
"bufferDraw" ), d->enabled );
353 textBufferElem.setAttribute( QStringLiteral(
"bufferSize" ), d->size );
357 textBufferElem.setAttribute( QStringLiteral(
"bufferNoFill" ), !d->fillBufferInterior );
358 textBufferElem.setAttribute( QStringLiteral(
"bufferOpacity" ), d->opacity );
359 textBufferElem.setAttribute( QStringLiteral(
"bufferJoinStyle" ),
static_cast< unsigned int >( d->joinStyle ) );
362 d->paintEffect->saveProperties( doc, textBufferElem );
363 return textBufferElem;
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the buffer size.
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)
static QPainter::CompositionMode decodeBlendMode(const QString &s)
void setOpacity(double opacity)
Sets the buffer opacity.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the buffer size.
RenderUnit
Rendering size units.
QgsExpressionContext & expressionContext()
Gets the expression context.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
QgsPaintEffect * createEffect(const QString &name, const QgsStringMap &properties=QgsStringMap()) const
Creates a new paint effect given the effect name and properties map.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
@ BufferOpacity
Buffer opacity.
double opacity() const
Returns the buffer opacity.
@ RenderMillimeters
Millimeters.
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.
void setFillBufferInterior(bool fill)
Sets whether the interior of the buffer will be filled in.
static QColor decodeColor(const QString &str)
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the buffer size.
QgsTextBufferSettings & operator=(const QgsTextBufferSettings &other)
Copy constructor.
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.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
QDomElement writeXml(QDomDocument &doc) const
Write settings into a DOM element.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the buffer.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Struct for storing maximum and minimum scales for measurements in map units.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the buffer size.
void readXml(const QDomElement &elem)
Read settings from a DOM element.
double size() const
Returns the size of the buffer.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
bool enabled() const
Returns whether the buffer is enabled.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects.
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.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the buffer.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the buffer.
Base class for visual effects which can be applied to QPicture drawings.
void setSize(double size)
Sets the size of the buffer.
void setColor(const QColor &color)
Sets the color for the buffer.
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the buffer.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
QColor color() const
Returns the color of the buffer.
bool fillBufferInterior() const
Returns whether the interior of the buffer will be filled in.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the buffer.
@ RenderMapUnits
Map units.
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.