25 #include <QFontDatabase>
29 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
30 #include <QDesktopWidget>
35 d =
new QgsTextSettingsPrivate();
39 : mBufferSettings( other.mBufferSettings )
40 , mBackgroundSettings( other.mBackgroundSettings )
41 , mShadowSettings( other.mShadowSettings )
42 , mMaskSettings( other.mMaskSettings )
43 , mTextFontFamily( other.mTextFontFamily )
44 , mTextFontFound( other.mTextFontFound )
53 mBufferSettings = other.mBufferSettings;
54 mBackgroundSettings = other.mBackgroundSettings;
55 mShadowSettings = other.mShadowSettings;
56 mMaskSettings = other.mMaskSettings;
57 mTextFontFamily = other.mTextFontFamily;
58 mTextFontFound = other.mTextFontFound;
69 if ( d->isValid != other.
isValid()
70 || d->textFont != other.
font()
72 || d->fontSizeUnits != other.
sizeUnit()
74 || d->fontSize != other.
size()
75 || d->textColor != other.
color()
76 || d->opacity != other.
opacity()
83 || mBufferSettings != other.mBufferSettings
84 || mBackgroundSettings != other.mBackgroundSettings
85 || mShadowSettings != other.mShadowSettings
86 || mMaskSettings != other.mMaskSettings
96 return !( *
this == other );
112 return mBufferSettings;
118 mBufferSettings = bufferSettings;
124 return mBackgroundSettings;
130 mBackgroundSettings = backgroundSettings;
136 return mShadowSettings;
142 mShadowSettings = shadowSettings;
148 return mMaskSettings;
154 mMaskSettings = maskSettings;
167 QFont
font = d->textFont;
168 if ( scaleFactor == 1 )
171 d->fontSizeMapUnitScale );
172 if ( fontPixelSize == 0 )
179 font.setPixelSize( fontPixelSize );
183 double fontPixelSize = context.
convertToPainterUnits( d->fontSize, d->fontSizeUnits, d->fontSizeMapUnitScale );
190 const int roundedPixelSize =
static_cast< int >( std::round( scaleFactor * fontPixelSize + 0.5 ) );
191 font.setPixelSize( roundedPixelSize );
194 font.setLetterSpacing( QFont::AbsoluteSpacing, context.
convertToPainterUnits( d->textFont.letterSpacing(), d->fontSizeUnits, d->fontSizeMapUnitScale ) * scaleFactor );
195 font.setWordSpacing( context.
convertToPainterUnits( d->textFont.wordSpacing(), d->fontSizeUnits, d->fontSizeMapUnitScale ) * scaleFactor * scaleFactor );
208 if ( !d->textNamedStyle.isEmpty() )
209 return d->textNamedStyle;
212 return db.styleString( d->textFont );
219 d->textNamedStyle = style;
235 return d->fontSizeUnits;
241 d->fontSizeUnits = unit;
246 return d->fontSizeMapUnitScale;
252 d->fontSizeMapUnitScale = scale;
274 d->textColor =
color;
301 return d->multilineHeight;
307 d->multilineHeight = height;
312 return d->orientation;
331 d->textFont.setCapitalization( QFont::MixedCase );
336 return d->allowHtmlFormatting;
342 d->allowHtmlFormatting = allow;
347 return d->previewBackgroundColor;
353 d->previewBackgroundColor =
color;
359 QFont appFont = QApplication::font();
360 mTextFontFamily = layer->
customProperty( QStringLiteral(
"labeling/fontFamily" ), QVariant( appFont.family() ) ).toString();
361 QString fontFamily = mTextFontFamily;
365 mTextFontFound =
false;
371 fontFamily = appFont.family();
375 mTextFontFound =
true;
380 d->fontSize = appFont.pointSizeF();
384 d->fontSize = layer->
customProperty( QStringLiteral(
"labeling/fontSize" ) ).toDouble();
387 if ( layer->
customProperty( QStringLiteral(
"labeling/fontSizeUnit" ) ).toString().isEmpty() )
389 d->fontSizeUnits = layer->
customProperty( QStringLiteral(
"labeling/fontSizeInMapUnits" ), QVariant(
false ) ).toBool() ?
399 if ( layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitScale" ) ).toString().isEmpty() )
402 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitMinScale" ), 0.0 ).toDouble();
403 d->fontSizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
404 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitMaxScale" ), 0.0 ).toDouble();
405 d->fontSizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
411 int fontWeight = layer->
customProperty( QStringLiteral(
"labeling/fontWeight" ) ).toInt();
412 bool fontItalic = layer->
customProperty( QStringLiteral(
"labeling/fontItalic" ) ).toBool();
413 d->textFont = QFont( fontFamily, d->fontSize, fontWeight, fontItalic );
417 d->textFont.setUnderline( layer->
customProperty( QStringLiteral(
"labeling/fontUnderline" ) ).toBool() );
418 d->textFont.setStrikeOut( layer->
customProperty( QStringLiteral(
"labeling/fontStrikeout" ) ).toBool() );
419 d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, layer->
customProperty( QStringLiteral(
"labeling/fontLetterSpacing" ), QVariant( 0.0 ) ).toDouble() );
420 d->textFont.setWordSpacing( layer->
customProperty( QStringLiteral(
"labeling/fontWordSpacing" ), QVariant( 0.0 ) ).toDouble() );
422 if ( layer->
customProperty( QStringLiteral(
"labeling/textOpacity" ) ).toString().isEmpty() )
424 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/textTransp" ) ).toInt() / 100.0 );
428 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/textOpacity" ) ).toDouble() );
432 d->multilineHeight = layer->
customProperty( QStringLiteral(
"labeling/multilineHeight" ), QVariant( 1.0 ) ).toDouble();
443 QDomElement textStyleElem;
444 if ( elem.nodeName() == QLatin1String(
"text-style" ) )
445 textStyleElem = elem;
447 textStyleElem = elem.firstChildElement( QStringLiteral(
"text-style" ) );
448 QFont appFont = QApplication::font();
449 mTextFontFamily = textStyleElem.attribute( QStringLiteral(
"fontFamily" ), appFont.family() );
450 QString fontFamily = mTextFontFamily;
452 const QDomElement familiesElem = textStyleElem.firstChildElement( QStringLiteral(
"families" ) );
453 const QDomNodeList familyNodes = familiesElem.childNodes();
455 families.reserve( familyNodes.size() );
456 for (
int i = 0; i < familyNodes.count(); ++i )
458 const QDomElement familyElem = familyNodes.at( i ).toElement();
459 families << familyElem.attribute( QStringLiteral(
"name" ) );
463 mTextFontFound =
false;
466 for (
const QString &family : std::as_const(
families ) )
470 mTextFontFound =
true;
476 if ( !mTextFontFound )
479 fontFamily = appFont.family();
484 mTextFontFound =
true;
487 if ( !mTextFontFound )
489 context.
pushMessage( QObject::tr(
"Font “%1” not available on system" ).arg( mTextFontFamily ) );
492 if ( textStyleElem.hasAttribute( QStringLiteral(
"fontSize" ) ) )
494 d->fontSize = textStyleElem.attribute( QStringLiteral(
"fontSize" ) ).toDouble();
498 d->fontSize = appFont.pointSizeF();
501 if ( !textStyleElem.hasAttribute( QStringLiteral(
"fontSizeUnit" ) ) )
503 d->fontSizeUnits = textStyleElem.attribute( QStringLiteral(
"fontSizeInMapUnits" ) ).toUInt() == 0 ?
QgsUnitTypes::RenderPoints
511 if ( !textStyleElem.hasAttribute( QStringLiteral(
"fontSizeMapUnitScale" ) ) )
514 double oldMin = textStyleElem.attribute( QStringLiteral(
"fontSizeMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
515 d->fontSizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
516 double oldMax = textStyleElem.attribute( QStringLiteral(
"fontSizeMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
517 d->fontSizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
523 int fontWeight = textStyleElem.attribute( QStringLiteral(
"fontWeight" ) ).toInt();
524 bool fontItalic = textStyleElem.attribute( QStringLiteral(
"fontItalic" ) ).toInt();
525 d->textFont = QFont( fontFamily, d->fontSize, fontWeight, fontItalic );
526 d->textFont.setPointSizeF( d->fontSize );
529 d->textFont.setUnderline( textStyleElem.attribute( QStringLiteral(
"fontUnderline" ) ).toInt() );
530 d->textFont.setStrikeOut( textStyleElem.attribute( QStringLiteral(
"fontStrikeout" ) ).toInt() );
531 d->textFont.setKerning( textStyleElem.attribute( QStringLiteral(
"fontKerning" ), QStringLiteral(
"1" ) ).toInt() );
532 d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, textStyleElem.attribute( QStringLiteral(
"fontLetterSpacing" ), QStringLiteral(
"0" ) ).toDouble() );
533 d->textFont.setWordSpacing( textStyleElem.attribute( QStringLiteral(
"fontWordSpacing" ), QStringLiteral(
"0" ) ).toDouble() );
535 if ( !textStyleElem.hasAttribute( QStringLiteral(
"textOpacity" ) ) )
537 d->opacity = ( 1 - textStyleElem.attribute( QStringLiteral(
"textTransp" ) ).toInt() / 100.0 );
541 d->opacity = ( textStyleElem.attribute( QStringLiteral(
"textOpacity" ) ).toDouble() );
549 if ( !textStyleElem.hasAttribute( QStringLiteral(
"multilineHeight" ) ) )
551 QDomElement textFormatElem = elem.firstChildElement( QStringLiteral(
"text-format" ) );
552 d->multilineHeight = textFormatElem.attribute( QStringLiteral(
"multilineHeight" ), QStringLiteral(
"1" ) ).toDouble();
556 d->multilineHeight = textStyleElem.attribute( QStringLiteral(
"multilineHeight" ), QStringLiteral(
"1" ) ).toDouble();
559 if ( textStyleElem.hasAttribute( QStringLiteral(
"capitalization" ) ) )
562 d->capitalization =
static_cast< QgsStringUtils::Capitalization >( textStyleElem.attribute( QStringLiteral(
"fontCapitals" ), QStringLiteral(
"0" ) ).toUInt() );
564 d->allowHtmlFormatting = textStyleElem.attribute( QStringLiteral(
"allowHtml" ), QStringLiteral(
"0" ) ).toInt();
566 if ( textStyleElem.firstChildElement( QStringLiteral(
"text-buffer" ) ).isNull() )
568 mBufferSettings.
readXml( elem );
572 mBufferSettings.
readXml( textStyleElem );
574 if ( textStyleElem.firstChildElement( QStringLiteral(
"text-mask" ) ).isNull() )
580 mMaskSettings.
readXml( textStyleElem );
582 if ( textStyleElem.firstChildElement( QStringLiteral(
"shadow" ) ).isNull() )
584 mShadowSettings.
readXml( elem );
588 mShadowSettings.
readXml( textStyleElem );
590 if ( textStyleElem.firstChildElement( QStringLiteral(
"background" ) ).isNull() )
592 mBackgroundSettings.
readXml( elem, context );
596 mBackgroundSettings.
readXml( textStyleElem, context );
599 QDomElement ddElem = textStyleElem.firstChildElement( QStringLiteral(
"dd_properties" ) );
600 if ( ddElem.isNull() )
602 ddElem = elem.firstChildElement( QStringLiteral(
"dd_properties" ) );
604 if ( !ddElem.isNull() )
611 d->mDataDefinedProperties.clear();
618 QDomElement textStyleElem = doc.createElement( QStringLiteral(
"text-style" ) );
619 textStyleElem.setAttribute( QStringLiteral(
"fontFamily" ), d->textFont.family() );
621 QDomElement familiesElem = doc.createElement( QStringLiteral(
"families" ) );
622 for (
const QString &family : std::as_const( d->families ) )
624 QDomElement familyElem = doc.createElement( QStringLiteral(
"family" ) );
625 familyElem.setAttribute( QStringLiteral(
"name" ), family );
626 familiesElem.appendChild( familyElem );
628 textStyleElem.appendChild( familiesElem );
631 textStyleElem.setAttribute( QStringLiteral(
"fontSize" ), d->fontSize );
634 textStyleElem.setAttribute( QStringLiteral(
"fontWeight" ), d->textFont.weight() );
635 textStyleElem.setAttribute( QStringLiteral(
"fontItalic" ), d->textFont.italic() );
636 textStyleElem.setAttribute( QStringLiteral(
"fontStrikeout" ), d->textFont.strikeOut() );
637 textStyleElem.setAttribute( QStringLiteral(
"fontUnderline" ), d->textFont.underline() );
640 textStyleElem.setAttribute( QStringLiteral(
"fontLetterSpacing" ), d->textFont.letterSpacing() );
641 textStyleElem.setAttribute( QStringLiteral(
"fontWordSpacing" ), d->textFont.wordSpacing() );
642 textStyleElem.setAttribute( QStringLiteral(
"fontKerning" ), d->textFont.kerning() );
643 textStyleElem.setAttribute( QStringLiteral(
"textOpacity" ), d->opacity );
646 textStyleElem.setAttribute( QStringLiteral(
"multilineHeight" ), d->multilineHeight );
647 textStyleElem.setAttribute( QStringLiteral(
"allowHtml" ), d->allowHtmlFormatting ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
648 textStyleElem.setAttribute( QStringLiteral(
"capitalization" ), QString::number(
static_cast< int >( d->capitalization ) ) );
650 QDomElement ddElem = doc.createElement( QStringLiteral(
"dd_properties" ) );
653 textStyleElem.appendChild( mBufferSettings.
writeXml( doc ) );
654 textStyleElem.appendChild( mMaskSettings.
writeXml( doc ) );
655 textStyleElem.appendChild( mBackgroundSettings.
writeXml( doc, context ) );
656 textStyleElem.appendChild( mShadowSettings.
writeXml( doc ) );
657 textStyleElem.appendChild( ddElem );
659 return textStyleElem;
666 QMimeData *mimeData =
new QMimeData;
667 mimeData->setColorData( QVariant(
color() ) );
670 QDomDocument textDoc;
671 QDomElement textElem =
writeXml( textDoc, rwContext );
672 textDoc.appendChild( textElem );
673 mimeData->setText( textDoc.toString() );
682 if (
font.pointSizeF() > 0 )
687 else if (
font.pixelSize() > 0 )
702 f.setPointSizeF(
size() );
706 f.setPointSizeF(
size() * 2.83464567 );
710 f.setPointSizeF(
size() * 72 );
714 f.setPixelSize(
static_cast< int >( std::round(
size() ) ) );
735 QString text = data->text();
736 if ( !text.isEmpty() )
742 if ( doc.setContent( text ) )
744 elem = doc.documentElement();
746 format.
readXml( elem, rwContext );
757 if ( d->blendMode != QPainter::CompositionMode_SourceOver )
760 if ( mBufferSettings.
enabled() && mBufferSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
763 if ( mBackgroundSettings.
enabled() && mBackgroundSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
766 if ( mShadowSettings.
enabled() && mShadowSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
775 return d->mDataDefinedProperties;
780 return d->mDataDefinedProperties;
785 QSet< QString > fields = d->mDataDefinedProperties.referencedFields( context.
expressionContext(),
true );
796 d->mDataDefinedProperties = collection;
802 if ( !d->mDataDefinedProperties.hasActiveProperties() )
805 QString ddFontFamily;
808 if ( !exprVal.isNull() )
810 QString family = exprVal.toString().trimmed();
811 if ( d->textFont.family() != family )
817 ddFontFamily = family;
826 if ( !exprVal.isNull() )
828 QString fontstyle = exprVal.toString().trimmed();
829 ddFontStyle = fontstyle;
839 bool ddItalic =
false;
849 QFontDatabase fontDb;
850 QFont appFont = QApplication::font();
851 bool newFontBuilt =
false;
852 if ( ddBold || ddItalic )
855 newFont = QFont( !ddFontFamily.isEmpty() ? ddFontFamily : d->textFont.family() );
857 newFont.setBold( ddBold );
858 newFont.setItalic( ddItalic );
860 else if ( !ddFontStyle.isEmpty()
861 && ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
863 if ( !ddFontFamily.isEmpty() )
866 QFont styledfont = fontDb.font( ddFontFamily, ddFontStyle, appFont.pointSize() );
867 if ( appFont != styledfont )
869 newFont = styledfont;
877 else if ( !ddFontFamily.isEmpty() )
879 if ( ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
882 QFont styledfont = fontDb.font( ddFontFamily, d->textNamedStyle, appFont.pointSize() );
883 if ( appFont != styledfont )
885 newFont = styledfont;
891 newFont = QFont( ddFontFamily );
899 newFont.setUnderline( d->textFont.underline() );
900 newFont.setStrikeOut( d->textFont.strikeOut() );
901 newFont.setWordSpacing( d->textFont.wordSpacing() );
902 newFont.setLetterSpacing( QFont::AbsoluteSpacing, d->textFont.letterSpacing() );
903 d->textFont = newFont;
931 if ( !exprVal.isNull() )
933 QString units = exprVal.toString();
934 if ( !units.isEmpty() )
939 d->fontSizeUnits = res;
949 d->opacity = val.toDouble() / 100.0;
966 d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, val.toDouble() );
976 d->textFont.setWordSpacing( val.toDouble() );
983 QString blendstr = exprVal.toString().trimmed();
984 if ( !blendstr.isEmpty() )
997 QPixmap pixmap(
size );
998 pixmap.fill( Qt::transparent );
1000 painter.begin( &pixmap );
1002 painter.setRenderHint( QPainter::Antialiasing );
1004 QRect rect( 0, 0,
size.width(),
size.height() );
1007 painter.setPen( Qt::NoPen );
1009 if ( ( background1.lightnessF() < 0.7 ) )
1011 background1 = background1.darker( 125 );
1015 background1 = background1.lighter( 125 );
1018 QLinearGradient linearGrad( QPointF( 0, 0 ), QPointF( 0, rect.height() ) );
1019 linearGrad.setColorAt( 0, background1 );
1020 linearGrad.setColorAt( 1, background2 );
1021 painter.setBrush( QBrush( linearGrad ) );
1022 if (
size.width() > 30 )
1024 painter.drawRoundedRect( rect, 6, 6 );
1029 painter.drawRect( rect );
1031 painter.setBrush( Qt::NoBrush );
1032 painter.setPen( Qt::NoPen );
1040 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
1041 const double logicalDpiX = QgsApplication::desktop()->logicalDpiX();
1043 QWidget *activeWindow = QApplication::activeWindow();
1044 const double logicalDpiX = activeWindow && activeWindow->screen() ? activeWindow->screen()->logicalDotsPerInchX() : 96.0;
1060 double ytrans = 0.0;
1066 const QStringList text = QStringList() << ( previewText.isEmpty() ? QObject::tr(
"Aa" ) : previewText );
1068 QRectF textRect = rect;
1069 textRect.setLeft( xtrans + padding );
1070 textRect.setWidth( rect.width() - xtrans - 2 * padding );
1072 if ( textRect.width() > 2000 )
1073 textRect.setWidth( 2000 - 2 * padding );
1075 const double bottom = textRect.height() / 2 + textHeight / 2;
1076 textRect.setTop( bottom - textHeight );
1077 textRect.setBottom( bottom );
1082 painter.setBrush( Qt::NoBrush );
1084 if (
size.width() > 30 )
1086 painter.drawRoundedRect( rect, 6, 6 );
1091 painter.drawRect( rect );
@ Antialiasing
Use antialiasing while drawing.
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)
Sets 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.
void pushMessage(const QString &message, Qgis::MessageLevel level=Qgis::MessageLevel::Warning) const
Append a message to the context.
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.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
void setFlag(Qgis::RenderContextFlag 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...
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
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.
void upgradeDataDefinedProperties(QgsPropertyCollection &properties)
Upgrade data defined properties when reading a project file saved in QGIS prior to version 3....
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.
QStringList families() const
Returns the list of font families to use when restoring the text format, in order of precedence.
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.
void setFamilies(const QStringList &families)
Sets a list of font families to use for the text format, in order of precedence.
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.
QFont scaledFont(const QgsRenderContext &context, double scaleFactor=1.0, bool *isZeroSize=nullptr) const
Returns a font with the size scaled to match the format's size settings (including units and map unit...
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.
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.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)