QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
qgstextlabelfeature.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstextlabelfeature.h
3 ---------------------
4 begin : December 2015
5 copyright : (C) 2015 by Martin Dobias
6 email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSTEXTLABELFEATURE_H
16#define QGSTEXTLABELFEATURE_H
17
18#define SIP_NO_FILE
19
20#include "qgslabelfeature.h"
21#include "qgstextdocument.h"
22#include "qgstextmetrics.h"
24#include "qgspallabeling.h"
25#include <optional>
26
28
35class CORE_EXPORT QgsTextLabelFeature : public QgsLabelFeature
36{
37 public:
39 QgsTextLabelFeature( QgsFeatureId id, geos::unique_ptr geometry, QSizeF size );
40
43
49 QString text( int partId ) const;
50
59 QgsTextCharacterFormat characterFormat( int partId ) const;
60
66 bool hasCharacterFormat( int partId ) const;
67
69 const QMap< QgsPalLayerSettings::Property, QVariant > &dataDefinedValues() const { return mDataDefinedValues; }
71 void setDataDefinedValues( const QMap< QgsPalLayerSettings::Property, QVariant > &values ) { mDataDefinedValues = values; }
72
74 void setDefinedFont( const QFont &f ) { mDefinedFont = f; }
76 QFont definedFont() const { return mDefinedFont; }
77
86 const QgsPrecalculatedTextMetrics *textMetrics() const { return mTextMetrics.has_value() ? &mTextMetrics.value() : nullptr; }
87
94 void setTextMetrics( const QgsPrecalculatedTextMetrics &metrics ) { mTextMetrics = metrics; }
95
101 static QgsPrecalculatedTextMetrics calculateTextMetrics( const QgsMapToPixel *xform, const QgsRenderContext &context, const QFont &baseFont, const QFontMetricsF &fontMetrics, double letterSpacing,
102 double wordSpacing, const QString &text = QString(), QgsTextDocument *document = nullptr, QgsTextDocumentMetrics *metrics = nullptr );
103
109 const QgsTextDocument &document() const { return mDocument; }
110
117 const QgsTextDocumentMetrics &documentMetrics() const { return mDocumentMetrics; }
118
125 void setDocument( const QgsTextDocument &document, const QgsTextDocumentMetrics &metrics );
126
133 void setMaximumCharacterAngleInside( double angle ) { mMaximumCharacterAngleInside = angle; }
134
141 double maximumCharacterAngleInside() const { return mMaximumCharacterAngleInside; }
142
149 void setMaximumCharacterAngleOutside( double angle ) { mMaximumCharacterAngleOutside = angle; }
150
157 double maximumCharacterAngleOutside() const { return mMaximumCharacterAngleOutside; }
158
159 protected:
160
163
165 QMap< QgsPalLayerSettings::Property, QVariant > mDataDefinedValues;
166
169
170 double mMaximumCharacterAngleInside = 0;
171 double mMaximumCharacterAngleOutside = 0;
172
173 std::optional< QgsPrecalculatedTextMetrics > mTextMetrics;
174
175};
176
177#endif //QGSTEXTLABELFEATURE_H
The QgsLabelFeature class describes a feature that should be used within the labeling engine.
Perform transforms between map coordinates and device coordinates.
Contains precalculated properties regarding text metrics for text to be renderered at a later stage.
Contains information about the context of a rendering operation.
Stores information relating to individual character formatting.
Contains pre-calculated metrics of a QgsTextDocument.
Represents a document consisting of one or more QgsTextBlock objects.
Class that adds extra information to QgsLabelFeature for text labels.
const QgsPrecalculatedTextMetrics * textMetrics() const
Returns additional info required for curved label placement.
void setMaximumCharacterAngleInside(double angle)
Sets the maximum angle (in radians) between inside curved label characters.
double maximumCharacterAngleInside() const
Returns the maximum angle (in radians) between inside curved label characters.
void setDefinedFont(const QFont &f)
Sets font to be used for rendering.
QFont definedFont() const
Font to be used for rendering.
void setTextMetrics(const QgsPrecalculatedTextMetrics &metrics)
Sets additional text metrics required for curved label placement.
~QgsTextLabelFeature() override
Clean up.
void setMaximumCharacterAngleOutside(double angle)
Sets the maximum angle (in radians) between outside curved label characters.
const QgsTextDocumentMetrics & documentMetrics() const
Returns the document metrics for the label.
const QgsTextDocument & document() const
Returns the document for the label.
void setDataDefinedValues(const QMap< QgsPalLayerSettings::Property, QVariant > &values)
Sets data-defined values.
QFont mDefinedFont
Font for rendering.
QgsTextDocumentMetrics mDocumentMetrics
QMap< QgsPalLayerSettings::Property, QVariant > mDataDefinedValues
Stores attribute values for data defined properties.
const QMap< QgsPalLayerSettings::Property, QVariant > & dataDefinedValues() const
Gets data-defined values.
double maximumCharacterAngleOutside() const
Returns the maximum angle (in radians) between outside curved label characters.
std::optional< QgsPrecalculatedTextMetrics > mTextMetrics
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features