39 return QStringLiteral(
"recttext" );
49 const QRectF innerRect(
50 painterBounds.left() + marginLeft,
51 painterBounds.top() + marginTop,
52 painterBounds.width() - marginLeft - marginRight,
53 painterBounds.height() - marginTop - marginBottom );
61 mTextFormat.
allowHtmlFormatting() ? QStringList{displayText }: displayText.split(
'\n' ), context, mTextFormat,
true,
69 element.setAttribute( QStringLiteral(
"text" ), mText );
70 element.setAttribute( QStringLiteral(
"alignment" ), QString::number( mAlignment ) );
72 QDomElement textFormatElem = document.createElement( QStringLiteral(
"rectTextFormat" ) );
73 textFormatElem.appendChild( mTextFormat.
writeXml( document, context ) );
74 element.appendChild( textFormatElem );
76 element.setAttribute( QStringLiteral(
"margins" ), mMargins.
toString() );
90 mText = element.attribute( QStringLiteral(
"text" ) );
92 const QDomElement textFormatElem = element.firstChildElement( QStringLiteral(
"rectTextFormat" ) );
93 if ( !textFormatElem.isNull() )
95 const QDomNodeList textFormatNodeList = textFormatElem.elementsByTagName( QStringLiteral(
"text-style" ) );
96 const QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
97 mTextFormat.
readXml( textFormatElem, context );
103 mAlignment =
static_cast< Qt::Alignment
>( element.attribute( QStringLiteral(
"alignment" ) ).toInt() );
111 std::unique_ptr< QgsAnnotationRectangleTextItem > item = std::make_unique< QgsAnnotationRectangleTextItem >( mText,
bounds() );
113 item->setFormat( mTextFormat );
114 item->setAlignment( mAlignment );
116 item->setMargins( mMargins );
117 item->setMarginsUnit( mMarginUnit );
119 item->copyCommonProperties(
this );
120 return item.release();
@ ScaleDependentBoundingBox
Item's bounding box will vary depending on map scale.
@ SupportsCallouts
Item supports callouts.
@ SupportsReferenceScale
Item supports reference scale based rendering.
QFlags< AnnotationItemFlag > AnnotationItemFlags
Annotation item flags.
@ Millimeters
Millimeters.
@ ApplyScalingWorkaroundForTextRendering
Whether a scaling workaround designed to stablise the rendering of small font sizes (or for painters ...
@ WrapLines
Automatically wrap long lines of text.
@ SpatialBounds
Item is rendered inside fixed spatial bounds, and size will depend on map scale.
@ FixedSize
Item is rendered at a fixed size, regardless of map scale. Item's location is georeferenced to a spat...
@ RelativeToMapFrame
Items size and placement is relative to the map's frame, and the item will always be rendered in the ...
Abstract base class for annotation items which render annotations in a rectangular shape.
QgsRectangle bounds() const
Returns the bounds of the item.
bool readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context) override
Reads common properties from the base class from the given DOM element.
bool writeCommonProperties(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Writes common properties from the base class into an XML element.
void setBackgroundEnabled(bool enabled)
Sets whether the item's background should be rendered.
void setFrameEnabled(bool enabled)
Sets whether the item's frame should be rendered.
Qgis::AnnotationPlacementMode placementMode() const
Returns the placement mode for the item.
An annotation item which renders paragraphs of text within a rectangle.
QgsTextFormat format() const
Returns the text format used to render the text.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Writes the item's state into an XML element.
void setFormat(const QgsTextFormat &format)
Sets the text format used to render the text.
QgsAnnotationRectangleTextItem * clone() const override
Returns a clone of the item.
Qt::Alignment alignment() const
Returns the text's alignment relative to the bounds() rectangle.
static QgsAnnotationRectangleTextItem * create()
Creates a new rectangle text annotation item.
void renderInBounds(QgsRenderContext &context, const QRectF &painterBounds, QgsFeedback *feedback) override
Renders the item to the specified render context.
void setAlignment(Qt::Alignment alignment)
Sets the text's alignment relative to the bounds() rectangle.
QgsAnnotationRectangleTextItem(const QString &text, const QgsRectangle &bounds)
Constructor for QgsAnnotationRectangleTextItem, containing the specified text within the specified bo...
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the item's state from the given DOM element.
~QgsAnnotationRectangleTextItem() override
QString type() const override
Returns a unique (untranslated) string identifying the type of item.
Qgis::AnnotationItemFlags flags() const override
Returns item flags.
static QString replaceExpressionText(const QString &action, const QgsExpressionContext *context, const QgsDistanceArea *distanceArea=nullptr)
This function replaces each expression between [% and %] in the string with the result of its evaluat...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
double top() const
Returns the top margin.
static QgsMargins fromString(const QString &string)
Returns a QgsMargins object decoded from a string, or a null QgsMargins if the string could not be in...
double right() const
Returns the right margin.
double bottom() const
Returns the bottom margin.
QString toString() const
Returns the margins encoded to a string.
double left() const
Returns the left margin.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
const QgsDistanceArea & distanceArea() const
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
QgsExpressionContext & expressionContext()
Gets the expression context.
bool testFlag(Qgis::RenderContextFlag flag) const
Check whether a particular flag is enabled.
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
Container for all settings relating to text rendering.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
bool allowHtmlFormatting() const
Returns true if text should be treated as a HTML document and HTML tags should be used for formatting...
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
static Qgis::TextVerticalAlignment convertQtVAlignment(Qt::Alignment alignment)
Converts a Qt vertical alignment flag to a Qgis::TextVerticalAlignment value.
static void drawText(const QRectF &rect, double rotation, Qgis::TextHorizontalAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, Qgis::TextVerticalAlignment vAlignment=Qgis::TextVerticalAlignment::Top, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Rectangle)
Draws text within a rectangle using the specified settings.
static Qgis::TextHorizontalAlignment convertQtHAlignment(Qt::Alignment alignment)
Converts a Qt horizontal alignment flag to a Qgis::TextHorizontalAlignment value.
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.
#define BUILTIN_UNREACHABLE