25 #include <QFontDatabase>
26 #include <QDesktopWidget>
31 d =
new QgsTextSettingsPrivate();
35 : mBufferSettings( other.mBufferSettings )
36 , mBackgroundSettings( other.mBackgroundSettings )
37 , mShadowSettings( other.mShadowSettings )
38 , mMaskSettings( other.mMaskSettings )
39 , mTextFontFamily( other.mTextFontFamily )
40 , mTextFontFound( other.mTextFontFound )
49 mBufferSettings = other.mBufferSettings;
50 mBackgroundSettings = other.mBackgroundSettings;
51 mShadowSettings = other.mShadowSettings;
52 mMaskSettings = other.mMaskSettings;
53 mTextFontFamily = other.mTextFontFamily;
54 mTextFontFound = other.mTextFontFound;
65 if ( d->isValid != other.
isValid()
66 || d->textFont != other.
font()
68 || d->fontSizeUnits != other.
sizeUnit()
70 || d->fontSize != other.
size()
71 || d->textColor != other.
color()
72 || d->opacity != other.
opacity()
79 || mBufferSettings != other.mBufferSettings
80 || mBackgroundSettings != other.mBackgroundSettings
81 || mShadowSettings != other.mShadowSettings
82 || mMaskSettings != other.mMaskSettings
91 return !( *
this == other );
107 return mBufferSettings;
113 mBufferSettings = bufferSettings;
119 return mBackgroundSettings;
125 mBackgroundSettings = backgroundSettings;
131 return mShadowSettings;
137 mShadowSettings = shadowSettings;
143 return mMaskSettings;
149 mMaskSettings = maskSettings;
159 QFont
font = d->textFont;
160 if ( scaleFactor == 1 )
163 d->fontSizeMapUnitScale );
164 font.setPixelSize( fontPixelSize );
168 double fontPixelSize = context.
convertToPainterUnits( d->fontSize, d->fontSizeUnits, d->fontSizeMapUnitScale );
169 font.setPixelSize( std::round( scaleFactor * fontPixelSize + 0.5 ) );
172 font.setLetterSpacing( QFont::AbsoluteSpacing, context.
convertToPainterUnits( d->textFont.letterSpacing(), d->fontSizeUnits, d->fontSizeMapUnitScale ) * scaleFactor );
173 font.setWordSpacing( context.
convertToPainterUnits( d->textFont.wordSpacing(), d->fontSizeUnits, d->fontSizeMapUnitScale ) * scaleFactor * scaleFactor );
186 if ( !d->textNamedStyle.isEmpty() )
187 return d->textNamedStyle;
190 return db.styleString( d->textFont );
197 d->textNamedStyle = style;
202 return d->fontSizeUnits;
208 d->fontSizeUnits = unit;
213 return d->fontSizeMapUnitScale;
219 d->fontSizeMapUnitScale = scale;
241 d->textColor =
color;
268 return d->multilineHeight;
274 d->multilineHeight = height;
279 return d->orientation;
298 d->textFont.setCapitalization( QFont::MixedCase );
303 return d->allowHtmlFormatting;
309 d->allowHtmlFormatting = allow;
314 return d->previewBackgroundColor;
320 d->previewBackgroundColor =
color;
326 QFont appFont = QApplication::font();
327 mTextFontFamily = layer->
customProperty( QStringLiteral(
"labeling/fontFamily" ), QVariant( appFont.family() ) ).toString();
328 QString fontFamily = mTextFontFamily;
332 mTextFontFound =
false;
338 fontFamily = appFont.family();
342 mTextFontFound =
true;
347 d->fontSize = appFont.pointSizeF();
351 d->fontSize = layer->
customProperty( QStringLiteral(
"labeling/fontSize" ) ).toDouble();
354 if ( layer->
customProperty( QStringLiteral(
"labeling/fontSizeUnit" ) ).toString().isEmpty() )
356 d->fontSizeUnits = layer->
customProperty( QStringLiteral(
"labeling/fontSizeInMapUnits" ), QVariant(
false ) ).toBool() ?
366 if ( layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitScale" ) ).toString().isEmpty() )
369 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitMinScale" ), 0.0 ).toDouble();
370 d->fontSizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
371 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitMaxScale" ), 0.0 ).toDouble();
372 d->fontSizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
378 int fontWeight = layer->
customProperty( QStringLiteral(
"labeling/fontWeight" ) ).toInt();
379 bool fontItalic = layer->
customProperty( QStringLiteral(
"labeling/fontItalic" ) ).toBool();
380 d->textFont = QFont( fontFamily, d->fontSize, fontWeight, fontItalic );
384 d->textFont.setUnderline( layer->
customProperty( QStringLiteral(
"labeling/fontUnderline" ) ).toBool() );
385 d->textFont.setStrikeOut( layer->
customProperty( QStringLiteral(
"labeling/fontStrikeout" ) ).toBool() );
386 d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, layer->
customProperty( QStringLiteral(
"labeling/fontLetterSpacing" ), QVariant( 0.0 ) ).toDouble() );
387 d->textFont.setWordSpacing( layer->
customProperty( QStringLiteral(
"labeling/fontWordSpacing" ), QVariant( 0.0 ) ).toDouble() );
389 if ( layer->
customProperty( QStringLiteral(
"labeling/textOpacity" ) ).toString().isEmpty() )
391 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/textTransp" ) ).toInt() / 100.0 );
395 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/textOpacity" ) ).toDouble() );
399 d->multilineHeight = layer->
customProperty( QStringLiteral(
"labeling/multilineHeight" ), QVariant( 1.0 ) ).toDouble();
410 QDomElement textStyleElem;
411 if ( elem.nodeName() == QLatin1String(
"text-style" ) )
412 textStyleElem = elem;
414 textStyleElem = elem.firstChildElement( QStringLiteral(
"text-style" ) );
415 QFont appFont = QApplication::font();
416 mTextFontFamily = textStyleElem.attribute( QStringLiteral(
"fontFamily" ), appFont.family() );
417 QString fontFamily = mTextFontFamily;
421 mTextFontFound =
false;
427 fontFamily = appFont.family();
431 mTextFontFound =
true;
434 if ( textStyleElem.hasAttribute( QStringLiteral(
"fontSize" ) ) )
436 d->fontSize = textStyleElem.attribute( QStringLiteral(
"fontSize" ) ).toDouble();
440 d->fontSize = appFont.pointSizeF();
443 if ( !textStyleElem.hasAttribute( QStringLiteral(
"fontSizeUnit" ) ) )
445 d->fontSizeUnits = textStyleElem.attribute( QStringLiteral(
"fontSizeInMapUnits" ) ).toUInt() == 0 ?
QgsUnitTypes::RenderPoints
453 if ( !textStyleElem.hasAttribute( QStringLiteral(
"fontSizeMapUnitScale" ) ) )
456 double oldMin = textStyleElem.attribute( QStringLiteral(
"fontSizeMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
457 d->fontSizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
458 double oldMax = textStyleElem.attribute( QStringLiteral(
"fontSizeMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
459 d->fontSizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
465 int fontWeight = textStyleElem.attribute( QStringLiteral(
"fontWeight" ) ).toInt();
466 bool fontItalic = textStyleElem.attribute( QStringLiteral(
"fontItalic" ) ).toInt();
467 d->textFont = QFont( fontFamily, d->fontSize, fontWeight, fontItalic );
468 d->textFont.setPointSizeF( d->fontSize );
471 d->textFont.setUnderline( textStyleElem.attribute( QStringLiteral(
"fontUnderline" ) ).toInt() );
472 d->textFont.setStrikeOut( textStyleElem.attribute( QStringLiteral(
"fontStrikeout" ) ).toInt() );
473 d->textFont.setKerning( textStyleElem.attribute( QStringLiteral(
"fontKerning" ), QStringLiteral(
"1" ) ).toInt() );
474 d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, textStyleElem.attribute( QStringLiteral(
"fontLetterSpacing" ), QStringLiteral(
"0" ) ).toDouble() );
475 d->textFont.setWordSpacing( textStyleElem.attribute( QStringLiteral(
"fontWordSpacing" ), QStringLiteral(
"0" ) ).toDouble() );
477 if ( !textStyleElem.hasAttribute( QStringLiteral(
"textOpacity" ) ) )
479 d->opacity = ( 1 - textStyleElem.attribute( QStringLiteral(
"textTransp" ) ).toInt() / 100.0 );
483 d->opacity = ( textStyleElem.attribute( QStringLiteral(
"textOpacity" ) ).toDouble() );
491 if ( !textStyleElem.hasAttribute( QStringLiteral(
"multilineHeight" ) ) )
493 QDomElement textFormatElem = elem.firstChildElement( QStringLiteral(
"text-format" ) );
494 d->multilineHeight = textFormatElem.attribute( QStringLiteral(
"multilineHeight" ), QStringLiteral(
"1" ) ).toDouble();
498 d->multilineHeight = textStyleElem.attribute( QStringLiteral(
"multilineHeight" ), QStringLiteral(
"1" ) ).toDouble();
501 if ( textStyleElem.hasAttribute( QStringLiteral(
"capitalization" ) ) )
504 d->capitalization =
static_cast< QgsStringUtils::Capitalization >( textStyleElem.attribute( QStringLiteral(
"fontCapitals" ), QStringLiteral(
"0" ) ).toUInt() );
506 d->allowHtmlFormatting = textStyleElem.attribute( QStringLiteral(
"allowHtml" ), QStringLiteral(
"0" ) ).toInt();
508 if ( textStyleElem.firstChildElement( QStringLiteral(
"text-buffer" ) ).isNull() )
510 mBufferSettings.
readXml( elem );
514 mBufferSettings.
readXml( textStyleElem );
516 if ( textStyleElem.firstChildElement( QStringLiteral(
"text-mask" ) ).isNull() )
522 mMaskSettings.
readXml( textStyleElem );
524 if ( textStyleElem.firstChildElement( QStringLiteral(
"shadow" ) ).isNull() )
526 mShadowSettings.
readXml( elem );
530 mShadowSettings.
readXml( textStyleElem );
532 if ( textStyleElem.firstChildElement( QStringLiteral(
"background" ) ).isNull() )
534 mBackgroundSettings.
readXml( elem, context );
538 mBackgroundSettings.
readXml( textStyleElem, context );
541 QDomElement ddElem = textStyleElem.firstChildElement( QStringLiteral(
"dd_properties" ) );
542 if ( ddElem.isNull() )
544 ddElem = elem.firstChildElement( QStringLiteral(
"dd_properties" ) );
546 if ( !ddElem.isNull() )
552 d->mDataDefinedProperties.clear();
559 QDomElement textStyleElem = doc.createElement( QStringLiteral(
"text-style" ) );
560 textStyleElem.setAttribute( QStringLiteral(
"fontFamily" ), d->textFont.family() );
562 textStyleElem.setAttribute( QStringLiteral(
"fontSize" ), d->fontSize );
565 textStyleElem.setAttribute( QStringLiteral(
"fontWeight" ), d->textFont.weight() );
566 textStyleElem.setAttribute( QStringLiteral(
"fontItalic" ), d->textFont.italic() );
567 textStyleElem.setAttribute( QStringLiteral(
"fontStrikeout" ), d->textFont.strikeOut() );
568 textStyleElem.setAttribute( QStringLiteral(
"fontUnderline" ), d->textFont.underline() );
571 textStyleElem.setAttribute( QStringLiteral(
"fontLetterSpacing" ), d->textFont.letterSpacing() );
572 textStyleElem.setAttribute( QStringLiteral(
"fontWordSpacing" ), d->textFont.wordSpacing() );
573 textStyleElem.setAttribute( QStringLiteral(
"fontKerning" ), d->textFont.kerning() );
574 textStyleElem.setAttribute( QStringLiteral(
"textOpacity" ), d->opacity );
577 textStyleElem.setAttribute( QStringLiteral(
"multilineHeight" ), d->multilineHeight );
578 textStyleElem.setAttribute( QStringLiteral(
"allowHtml" ), d->allowHtmlFormatting ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
579 textStyleElem.setAttribute( QStringLiteral(
"capitalization" ), QString::number(
static_cast< int >( d->capitalization ) ) );
581 QDomElement ddElem = doc.createElement( QStringLiteral(
"dd_properties" ) );
584 textStyleElem.appendChild( mBufferSettings.
writeXml( doc ) );
585 textStyleElem.appendChild( mMaskSettings.
writeXml( doc ) );
586 textStyleElem.appendChild( mBackgroundSettings.
writeXml( doc, context ) );
587 textStyleElem.appendChild( mShadowSettings.
writeXml( doc ) );
588 textStyleElem.appendChild( ddElem );
590 return textStyleElem;
597 QMimeData *mimeData =
new QMimeData;
598 mimeData->setColorData( QVariant(
color() ) );
601 QDomDocument textDoc;
602 QDomElement textElem =
writeXml( textDoc, rwContext );
603 textDoc.appendChild( textElem );
604 mimeData->setText( textDoc.toString() );
613 if (
font.pointSizeF() > 0 )
618 else if (
font.pixelSize() > 0 )
633 f.setPointSizeF(
size() );
637 f.setPointSizeF(
size() * 2.83464567 );
641 f.setPointSizeF(
size() * 72 );
645 f.setPixelSize(
static_cast< int >( std::round(
size() ) ) );
666 QString text = data->text();
667 if ( !text.isEmpty() )
673 if ( doc.setContent( text ) )
675 elem = doc.documentElement();
677 format.
readXml( elem, rwContext );
688 if ( d->blendMode != QPainter::CompositionMode_SourceOver )
691 if ( mBufferSettings.
enabled() && mBufferSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
694 if ( mBackgroundSettings.
enabled() && mBackgroundSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
697 if ( mShadowSettings.
enabled() && mShadowSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
706 return d->mDataDefinedProperties;
711 return d->mDataDefinedProperties;
716 QSet< QString > fields = d->mDataDefinedProperties.referencedFields( context.
expressionContext(),
true );
727 d->mDataDefinedProperties = collection;
733 if ( !d->mDataDefinedProperties.hasActiveProperties() )
736 QString ddFontFamily;
739 if ( exprVal.isValid() )
741 QString family = exprVal.toString().trimmed();
742 if ( d->textFont.family() != family )
748 ddFontFamily = family;
757 if ( exprVal.isValid() )
759 QString fontstyle = exprVal.toString().trimmed();
760 ddFontStyle = fontstyle;
770 bool ddItalic =
false;
780 QFontDatabase fontDb;
781 QFont appFont = QApplication::font();
782 bool newFontBuilt =
false;
783 if ( ddBold || ddItalic )
786 newFont = QFont( !ddFontFamily.isEmpty() ? ddFontFamily : d->textFont.family() );
788 newFont.setBold( ddBold );
789 newFont.setItalic( ddItalic );
791 else if ( !ddFontStyle.isEmpty()
792 && ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
794 if ( !ddFontFamily.isEmpty() )
797 QFont styledfont = fontDb.font( ddFontFamily, ddFontStyle, appFont.pointSize() );
798 if ( appFont != styledfont )
800 newFont = styledfont;
808 else if ( !ddFontFamily.isEmpty() )
810 if ( ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
813 QFont styledfont = fontDb.font( ddFontFamily, d->textNamedStyle, appFont.pointSize() );
814 if ( appFont != styledfont )
816 newFont = styledfont;
822 newFont = QFont( ddFontFamily );
830 newFont.setUnderline( d->textFont.underline() );
831 newFont.setStrikeOut( d->textFont.strikeOut() );
832 newFont.setWordSpacing( d->textFont.wordSpacing() );
833 newFont.setLetterSpacing( QFont::AbsoluteSpacing, d->textFont.letterSpacing() );
834 d->textFont = newFont;
862 if ( exprVal.isValid() )
864 QString units = exprVal.toString();
865 if ( !units.isEmpty() )
870 d->fontSizeUnits = res;
902 QString blendstr = exprVal.toString().trimmed();
903 if ( !blendstr.isEmpty() )
916 QPixmap pixmap(
size );
917 pixmap.fill( Qt::transparent );
919 painter.begin( &pixmap );
921 painter.setRenderHint( QPainter::Antialiasing );
923 QRect rect( 0, 0,
size.width(),
size.height() );
926 painter.setPen( Qt::NoPen );
928 if ( ( background1.lightnessF() < 0.7 ) )
930 background1 = background1.darker( 125 );
934 background1 = background1.lighter( 125 );
937 QLinearGradient linearGrad( QPointF( 0, 0 ), QPointF( 0, rect.height() ) );
938 linearGrad.setColorAt( 0, background1 );
939 linearGrad.setColorAt( 1, background2 );
940 painter.setBrush( QBrush( linearGrad ) );
941 if (
size.width() > 30 )
943 painter.drawRoundedRect( rect, 6, 6 );
948 painter.drawRect( rect );
950 painter.setBrush( Qt::NoBrush );
951 painter.setPen( Qt::NoPen );
959 context.
setScaleFactor( QgsApplication::desktop()->logicalDpiX() / 25.4 );
978 const QStringList text = QStringList() << ( previewText.isEmpty() ? QObject::tr(
"Aa" ) : previewText );
980 QRectF textRect = rect;
981 textRect.setLeft( xtrans + padding );
982 textRect.setWidth( rect.width() - xtrans - 2 * padding );
984 if ( textRect.width() > 2000 )
985 textRect.setWidth( 2000 - 2 * padding );
987 const double bottom = textRect.height() / 2 + textHeight / 2;
988 textRect.setTop( bottom - textHeight );
989 textRect.setBottom( bottom );
994 painter.setBrush( Qt::NoBrush );
996 if (
size.width() > 30 )
998 painter.drawRoundedRect( rect, 6, 6 );
1003 painter.drawRect( rect );
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
static QString translateNamedStyle(const QString &namedStyle)
Returns the localized named style of a font, if such a translation is available.
static QString untranslateNamedStyle(const QString &namedStyle)
Returns the english named style of a font, if possible.
static bool fontFamilyMatchOnSystem(const QString &family, QString *chosen=nullptr, bool *match=nullptr)
Check whether font family is on system.
static bool fontFamilyOnSystem(const QString &family)
Check whether font family is on system in a quick manner, which does not compare [foundry].
static bool updateFontViaStyle(QFont &f, const QString &fontstyle, bool fallback=false)
Updates font with named style and retain all font properties.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
Perform transforms between map coordinates and device coordinates.
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
Struct for storing maximum and minimum scales for measurements in map units.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
@ Strikeout
Use strikeout.
@ FontStyle
Font style name.
@ Underline
Use underline.
@ FontLetterSpacing
Letter spacing.
@ FontSizeUnit
Font size units.
@ Italic
Use italic style.
@ FontWordSpacing
Word spacing.
@ FontBlendMode
Text blend mode.
@ FontOpacity
Text opacity.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the labeling property definitions.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
QgsExpressionContext & expressionContext()
Gets the expression context.
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
@ Antialiasing
Use antialiasing while drawing.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
Capitalization
Capitalization options.
@ MixedCase
Mixed case, ie no change.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QColor decodeColor(const QString &str)
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 background object.
QSizeF size() const
Returns the size of the background shape.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the background shape.
bool enabled() const
Returns whether the background is enabled.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the shape size.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units used for the shape's size.
Container for settings relating to a text buffer.
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.
double size() const
Returns the size of the buffer.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the buffer size.
bool enabled() const
Returns whether the buffer is enabled.
QDomElement writeXml(QDomDocument &doc) const
Write settings into a DOM element.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the buffer size.
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 readXml(const QDomElement &elem)
Read settings from a DOM element.
Container for all settings relating to text rendering.
QgsTextFormat()
Default constructor for QgsTextFormat.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the text.
void setSize(double size)
Sets the size for rendered text.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the size.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the format's property collection, used for data defined overrides.
void setFont(const QFont &font)
Sets the font used for rendering text.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
static QgsTextFormat fromMimeData(const QMimeData *data, bool *ok=nullptr)
Attempts to parse the provided mime data as a QgsTextFormat.
double lineHeight() const
Returns the line height for text.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
void setOrientation(TextOrientation orientation)
Sets the orientation for the text.
void updateDataDefinedProperties(QgsRenderContext &context)
Updates the format by evaluating current values of data defined properties.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the format's property collection, used for data defined overrides.
void setShadow(const QgsTextShadowSettings &shadowSettings)
Sets the text's drop shadow settings.
void setMask(const QgsTextMaskSettings &maskSettings)
Sets the text's masking settings.
void setPreviewBackgroundColor(const QColor &color)
Sets the background color that text will be rendered on for previews.
void setOpacity(double opacity)
Sets the text's opacity.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the text.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
bool operator==(const QgsTextFormat &other) const
TextOrientation orientation() const
Returns the orientation of the text.
void setAllowHtmlFormatting(bool allow)
Sets whether text should be treated as a HTML document and HTML tags should be used for formatting th...
QgsTextMaskSettings & mask()
Returns a reference to the masking settings.
static QPixmap textFormatPreviewPixmap(const QgsTextFormat &format, QSize size, const QString &previewText=QString(), int padding=0)
Returns a pixmap preview for a text format.
bool isValid() const
Returns true if the format is valid.
void setCapitalization(QgsStringUtils::Capitalization capitalization)
Sets the text capitalization style.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
TextOrientation
Text orientation.
static QgsTextFormat fromQFont(const QFont &font)
Returns a text format matching the settings from an input font.
void setValid()
Sets the format to a valid state, without changing any of the default format settings.
bool allowHtmlFormatting() const
Returns true if text should be treated as a HTML document and HTML tags should be used for formatting...
QFont toQFont() const
Returns a QFont matching the relevant settings from this text format.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the size of rendered text.
bool operator!=(const QgsTextFormat &other) const
double opacity() const
Returns the text's opacity.
QFont scaledFont(const QgsRenderContext &context, double scaleFactor=1.0) const
Returns a font with the size scaled to match the format's size settings (including units and map unit...
QString namedStyle() const
Returns the named style for the font used for rendering text (e.g., "bold").
double size() const
Returns the size for rendered text.
QgsTextShadowSettings & shadow()
Returns a reference to the text drop shadow settings.
QgsTextFormat & operator=(const QgsTextFormat &other)
void setBackground(const QgsTextBackgroundSettings &backgroundSettings)
Sets the text's background settings.q.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
QMimeData * toMimeData() const
Returns new mime data representing the text format settings.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the size.
void setNamedStyle(const QString &style)
Sets the named style for the font used for rendering text.
QgsStringUtils::Capitalization capitalization() const
Returns the text capitalization style.
QColor color() const
Returns the color that text will be rendered in.
QFont font() const
Returns the font used for rendering text.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
QColor previewBackgroundColor() const
Returns the background color for text previews.
bool containsAdvancedEffects() const
Returns true if any component of the font format requires advanced effects such as blend modes,...
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
void setLineHeight(double height)
Sets the line height for text.
Container for settings relating to a selective masking around a text.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
void readXml(const QDomElement &elem)
Read settings from a DOM element.
QDomElement writeXml(QDomDocument &doc) const
Write settings into a DOM element.
static QString encodeTextOrientation(QgsTextFormat::TextOrientation orientation)
Encodes a text orientation.
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 QgsTextFormat::TextOrientation decodeTextOrientation(const QString &name, bool *ok=nullptr)
Attempts to decode a string representation of a text orientation.
@ AlignCenter
Center align.
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, DrawMode mode=Point, QFontMetricsF *fontMetrics=nullptr)
Returns the height of a text based on a given format.
static int sizeToPixel(double size, const QgsRenderContext &c, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale())
Calculates pixel size (considering output size should be in pixel or map units, scale factors and opt...
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, VAlignment vAlignment=AlignTop)
Draws text within a rectangle using the specified settings.
@ Rect
Text within rectangle draw mode.
Container for settings relating to a text shadow.
bool enabled() const
Returns whether the shadow is enabled.
void readXml(const QDomElement &elem)
Read settings from a DOM element.
QDomElement writeXml(QDomDocument &doc) const
Write settings into a DOM element.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the drop shadow.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
RenderUnit
Rendering size units.
@ RenderUnknownUnit
Mixed or unknown units.
@ RenderMetersInMapUnits
Meters value as Map units.
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
@ RenderPoints
Points (e.g., for font sizes)
@ RenderMillimeters
Millimeters.
@ RenderMapUnits
Map units.
Represents a vector layer which manages a vector based data sets.