QGIS API Documentation 3.99.0-Master (7d2ca374f2d)
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
19#include <optional>
20
21#include "qgslabelfeature.h"
22#include "qgspallabeling.h"
23#include "qgstextdocument.h"
25#include "qgstextmetrics.h"
26
27#define SIP_NO_FILE
28
30
37class CORE_EXPORT QgsTextLabelFeature : public QgsLabelFeature
38{
39 public:
42
45
51 QString text( int partId ) const;
52
61 QgsTextCharacterFormat characterFormat( int partId ) const;
62
68 bool hasCharacterFormat( int partId ) const;
69
71 const QMap< QgsPalLayerSettings::Property, QVariant > &dataDefinedValues() const { return mDataDefinedValues; }
73 void setDataDefinedValues( const QMap< QgsPalLayerSettings::Property, QVariant > &values ) { mDataDefinedValues = values; }
74
76 void setDefinedFont( const QFont &f ) { mDefinedFont = f; }
78 QFont definedFont() const { return mDefinedFont; }
79
88 const QgsPrecalculatedTextMetrics *textMetrics() const { return mTextMetrics.has_value() ? &( *mTextMetrics ) : nullptr; }
89
96 void setTextMetrics( const QgsPrecalculatedTextMetrics &metrics ) { mTextMetrics = metrics; }
97
103 static QgsPrecalculatedTextMetrics calculateTextMetrics( const QgsMapToPixel *xform, const QgsRenderContext &context, const QgsTextFormat &format, const QFont &baseFont, const QFontMetricsF &fontMetrics, double letterSpacing,
104 double wordSpacing, const QgsTextDocument &document, const QgsTextDocumentMetrics &metrics );
105
111 const QgsTextDocument &document() const { return mDocument; }
112
120
127 void setDocument( const QgsTextDocument &document, const QgsTextDocumentMetrics &metrics );
128
136
144
152
160
161 protected:
162
165
167 QMap< QgsPalLayerSettings::Property, QVariant > mDataDefinedValues;
168
171
174
175 std::optional< QgsPrecalculatedTextMetrics > mTextMetrics;
176
177};
178
179#endif //QGSTEXTLABELFEATURE_H
QSizeF size(double angle=0.0) const
Size of the label (in map units).
GEOSGeometry * geometry() const
Gets access to the associated geometry.
QgsLabelFeature(QgsFeatureId id, geos::unique_ptr geometry, QSizeF size, int subPartId=0)
Constructor for QgsLabelFeature.
int subPartId() const
Sub part identifier (for features which register multiple labels).
Perform transforms between map coordinates and device coordinates.
Contains precalculated properties regarding text metrics for text to be rendered 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.
Container for all settings relating to text rendering.
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.
QgsTextCharacterFormat characterFormat(int partId) const
Returns the character format corresponding to the specified label part.
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.
QgsTextLabelFeature(QgsFeatureId id, geos::unique_ptr geometry, QSizeF size, int subPartId=0)
Construct text label feature.
double maximumCharacterAngleOutside() const
Returns the maximum angle (in radians) between outside curved label characters.
QString text(int partId) const
Returns the text component corresponding to a specified label part.
bool hasCharacterFormat(int partId) const
Returns true if the feature contains specific character formatting for the part with matching ID.
std::optional< QgsPrecalculatedTextMetrics > mTextMetrics
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition qgsgeos.h:114
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features