QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgspallabeling.h"
24 #include <optional>
25 
27 
34 class CORE_EXPORT QgsTextLabelFeature : public QgsLabelFeature
35 {
36  public:
38  QgsTextLabelFeature( QgsFeatureId id, geos::unique_ptr geometry, QSizeF size );
39 
41  ~QgsTextLabelFeature() override;
42 
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 
83  QFontMetricsF *labelFontMetrics() { return mFontMetrics.has_value() ? &mFontMetrics.value() : nullptr; }
84 
88  void setFontMetrics( const QFontMetricsF &metrics );
89 
98  const QgsPrecalculatedTextMetrics *textMetrics() const { return mTextMetrics.has_value() ? &mTextMetrics.value() : nullptr; }
99 
106  void setTextMetrics( const QgsPrecalculatedTextMetrics &metrics ) { mTextMetrics = metrics; }
107 
113  static QgsPrecalculatedTextMetrics calculateTextMetrics( const QgsMapToPixel *xform, const QFontMetricsF &fontMetrics, double letterSpacing,
114  double wordSpacing, const QString &text = QString(), QgsTextDocument *document = nullptr );
115 
121  QgsTextDocument document() const;
122 
128  void setDocument( const QgsTextDocument &document );
129 
136  void setMaximumCharacterAngleInside( double angle ) { mMaximumCharacterAngleInside = angle; }
137 
144  double maximumCharacterAngleInside() const { return mMaximumCharacterAngleInside; }
145 
152  void setMaximumCharacterAngleOutside( double angle ) { mMaximumCharacterAngleOutside = angle; }
153 
160  double maximumCharacterAngleOutside() const { return mMaximumCharacterAngleOutside; }
161 
162  protected:
163 
166 
168  std::optional< QFontMetricsF > mFontMetrics;
169 
171  QMap< QgsPalLayerSettings::Property, QVariant > mDataDefinedValues;
172 
174 
175  double mMaximumCharacterAngleInside = 0;
176  double mMaximumCharacterAngleOutside = 0;
177 
178  std::optional< QgsPrecalculatedTextMetrics > mTextMetrics;
179 
180 };
181 
182 #endif //QGSTEXTLABELFEATURE_H
qgstextdocument.h
qgspallabeling.h
QgsTextLabelFeature::dataDefinedValues
const QMap< QgsPalLayerSettings::Property, QVariant > & dataDefinedValues() const
Gets data-defined values.
Definition: qgstextlabelfeature.h:69
QgsTextLabelFeature::maximumCharacterAngleOutside
double maximumCharacterAngleOutside() const
Returns the maximum angle (in radians) between outside curved label characters.
Definition: qgstextlabelfeature.h:160
QgsTextLabelFeature::textMetrics
const QgsPrecalculatedTextMetrics * textMetrics() const
Returns additional info required for curved label placement.
Definition: qgstextlabelfeature.h:98
QgsTextLabelFeature::labelFontMetrics
QFontMetricsF * labelFontMetrics()
Metrics of the font for rendering.
Definition: qgstextlabelfeature.h:83
QgsTextLabelFeature::setTextMetrics
void setTextMetrics(const QgsPrecalculatedTextMetrics &metrics)
Sets additional text metrics required for curved label placement.
Definition: qgstextlabelfeature.h:106
QgsTextLabelFeature::mDefinedFont
QFont mDefinedFont
Font for rendering.
Definition: qgstextlabelfeature.h:165
QgsTextCharacterFormat
Stores information relating to individual character formatting.
Definition: qgstextcharacterformat.h:39
QgsTextLabelFeature::mFontMetrics
std::optional< QFontMetricsF > mFontMetrics
Metrics of the font for rendering.
Definition: qgstextlabelfeature.h:168
qgslabelfeature.h
QgsTextLabelFeature
Class that adds extra information to QgsLabelFeature for text labels.
Definition: qgstextlabelfeature.h:34
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
QgsTextLabelFeature::maximumCharacterAngleInside
double maximumCharacterAngleInside() const
Returns the maximum angle (in radians) between inside curved label characters.
Definition: qgstextlabelfeature.h:144
QgsTextLabelFeature::mDocument
QgsTextDocument mDocument
Definition: qgstextlabelfeature.h:173
QgsTextLabelFeature::setDefinedFont
void setDefinedFont(const QFont &f)
Sets font to be used for rendering.
Definition: qgstextlabelfeature.h:74
QgsTextLabelFeature::definedFont
QFont definedFont() const
Font to be used for rendering.
Definition: qgstextlabelfeature.h:76
QgsTextLabelFeature::setMaximumCharacterAngleOutside
void setMaximumCharacterAngleOutside(double angle)
Sets the maximum angle (in radians) between outside curved label characters.
Definition: qgstextlabelfeature.h:152
QgsMapToPixel
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:38
QgsTextDocument
Represents a document consisting of one or more QgsTextBlock objects.
Definition: qgstextdocument.h:38
QgsTextLabelFeature::mTextMetrics
std::optional< QgsPrecalculatedTextMetrics > mTextMetrics
Definition: qgstextlabelfeature.h:178
QgsPrecalculatedTextMetrics
Contains precalculated properties regarding text metrics for text to be renderered at a later stage.
Definition: qgstextmetrics.h:34
QgsTextLabelFeature::setDataDefinedValues
void setDataDefinedValues(const QMap< QgsPalLayerSettings::Property, QVariant > &values)
Sets data-defined values.
Definition: qgstextlabelfeature.h:71
QgsLabelFeature
The QgsLabelFeature class describes a feature that should be used within the labeling engine....
Definition: qgslabelfeature.h:57
QgsTextLabelFeature::setMaximumCharacterAngleInside
void setMaximumCharacterAngleInside(double angle)
Sets the maximum angle (in radians) between inside curved label characters.
Definition: qgstextlabelfeature.h:136
MathUtils::angle
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
QgsTextLabelFeature::mDataDefinedValues
QMap< QgsPalLayerSettings::Property, QVariant > mDataDefinedValues
Stores attribute values for data defined properties.
Definition: qgstextlabelfeature.h:171
qgstextmetrics.h
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28