QGIS API Documentation  3.21.0-Master (56b4176581)
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"
23 #include <optional>
24 
26 
34 {
35  public:
38 
41 
48  QString text( int partId ) const;
49 
58  QgsTextCharacterFormat characterFormat( int partId ) const;
59 
65  bool hasCharacterFormat( int partId ) const;
66 
68  const QMap< QgsPalLayerSettings::Property, QVariant > &dataDefinedValues() const { return mDataDefinedValues; }
70  void setDataDefinedValues( const QMap< QgsPalLayerSettings::Property, QVariant > &values ) { mDataDefinedValues = values; }
71 
73  void setDefinedFont( const QFont &f ) { mDefinedFont = f; }
75  QFont definedFont() { return mDefinedFont; }
76 
82  QFontMetricsF *labelFontMetrics() { return mFontMetrics.has_value() ? &mFontMetrics.value() : nullptr; }
83 
87  void setFontMetrics( const QFontMetricsF &metrics );
88 
97  const QgsPrecalculatedTextMetrics *textMetrics() const { return mTextMetrics.has_value() ? &mTextMetrics.value() : nullptr; }
98 
105  void setTextMetrics( const QgsPrecalculatedTextMetrics &metrics ) { mTextMetrics = metrics; }
106 
112  static QgsPrecalculatedTextMetrics calculateTextMetrics( const QgsMapToPixel *xform, const QFontMetricsF &fontMetrics, double letterSpacing,
113  double wordSpacing, const QString &text = QString(), QgsTextDocument *document = nullptr );
114 
120  QgsTextDocument document() const;
121 
127  void setDocument( const QgsTextDocument &document );
128 
136 
144 
152 
160 
161  protected:
162 
165 
167  std::optional< QFontMetricsF > mFontMetrics;
168 
170  QMap< QgsPalLayerSettings::Property, QVariant > mDataDefinedValues;
171 
173 
176 
177  std::optional< QgsPrecalculatedTextMetrics > mTextMetrics;
178 
179 };
180 
181 #endif //QGSTEXTLABELFEATURE_H
The QgsLabelFeature class describes a feature that should be used within the labeling engine.
QSizeF size(double angle=0.0) const
Size of the label (in map units)
GEOSGeometry * geometry() const
Gets access to the associated geometry.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:39
Contains precalculated properties regarding text metrics for text to be renderered at a later stage.
Stores information relating to individual character formatting.
Represents a document consisting of one or more QgsTextBlock objects.
Class that adds extra information to QgsLabelFeature for text labels.
const QMap< QgsPalLayerSettings::Property, QVariant > & dataDefinedValues() const
Gets data-defined values.
void setDocument(const QgsTextDocument &document)
Sets the document for the label.
void setMaximumCharacterAngleInside(double angle)
Sets the maximum angle (in radians) between inside curved label characters.
void setFontMetrics(const QFontMetricsF &metrics)
Sets the font metrics.
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.
QgsTextLabelFeature(QgsFeatureId id, geos::unique_ptr geometry, QSizeF size)
Construct text label feature.
QgsTextDocument document() const
Returns the document for the label.
static QgsPrecalculatedTextMetrics calculateTextMetrics(const QgsMapToPixel *xform, const QFontMetricsF &fontMetrics, double letterSpacing, double wordSpacing, const QString &text=QString(), QgsTextDocument *document=nullptr)
Calculate text metrics for later retrieval via textMetrics().
void setTextMetrics(const QgsPrecalculatedTextMetrics &metrics)
Sets additional text metrics required for curved label placement.
QgsTextDocument mDocument
QFont definedFont()
Font to be used for rendering.
~QgsTextLabelFeature() override
Clean up.
void setMaximumCharacterAngleOutside(double angle)
Sets the maximum angle (in radians) between outside curved label characters.
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.
QMap< QgsPalLayerSettings::Property, QVariant > mDataDefinedValues
Stores attribute values for data defined properties.
const QgsPrecalculatedTextMetrics * textMetrics() const
Returns additional info required for curved label placement.
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.
std::optional< QFontMetricsF > mFontMetrics
Metrics of the font for rendering.
bool hasCharacterFormat(int partId) const
Returns true if the feature contains specific character formatting for the part with matching ID.
QFontMetricsF * labelFontMetrics()
Metrics of the font for rendering.
std::optional< QgsPrecalculatedTextMetrics > mTextMetrics
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28