QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgstextrendererutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgstextrendererutils.h
3  -----------------
4  begin : May 2020
5  copyright : (C) Nyall Dawson
6  email : nyall dot dawson 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 
16 #include "qgstextrendererutils.h"
17 #include "qgsvectorlayer.h"
18 
20 {
22  const QString skind = string.trimmed();
23 
24  if ( skind.compare( QLatin1String( "Square" ), Qt::CaseInsensitive ) == 0 )
25  {
27  }
28  else if ( skind.compare( QLatin1String( "Ellipse" ), Qt::CaseInsensitive ) == 0 )
29  {
31  }
32  else if ( skind.compare( QLatin1String( "Circle" ), Qt::CaseInsensitive ) == 0 )
33  {
35  }
36  else if ( skind.compare( QLatin1String( "SVG" ), Qt::CaseInsensitive ) == 0 )
37  {
39  }
40  else if ( skind.compare( QLatin1String( "marker" ), Qt::CaseInsensitive ) == 0 )
41  {
43  }
44  return shpkind;
45 }
46 
48 {
49  const QString stype = string.trimmed();
50  // "Buffer"
52 
53  if ( stype.compare( QLatin1String( "Fixed" ), Qt::CaseInsensitive ) == 0 )
54  {
56  }
57  return sizType;
58 }
59 
61 {
62  const QString rotstr = string.trimmed();
63  // "Sync"
65 
66  if ( rotstr.compare( QLatin1String( "Offset" ), Qt::CaseInsensitive ) == 0 )
67  {
69  }
70  else if ( rotstr.compare( QLatin1String( "Fixed" ), Qt::CaseInsensitive ) == 0 )
71  {
73  }
74  return rottype;
75 }
76 
78 {
79  const QString str = string.trimmed();
80  // "Lowest"
82 
83  if ( str.compare( QLatin1String( "Text" ), Qt::CaseInsensitive ) == 0 )
84  {
86  }
87  else if ( str.compare( QLatin1String( "Buffer" ), Qt::CaseInsensitive ) == 0 )
88  {
90  }
91  else if ( str.compare( QLatin1String( "Background" ), Qt::CaseInsensitive ) == 0 )
92  {
94  }
95  return shdwtype;
96 }
97 
99 {
100  switch ( orientation )
101  {
103  return QStringLiteral( "horizontal" );
105  return QStringLiteral( "vertical" );
107  return QStringLiteral( "rotation-based" );
108  }
109  return QString();
110 }
111 
113 {
114  if ( ok )
115  *ok = true;
116 
117  QString cleaned = name.toLower().trimmed();
118 
119  if ( cleaned == QLatin1String( "horizontal" ) )
121  else if ( cleaned == QLatin1String( "vertical" ) )
123  else if ( cleaned == QLatin1String( "rotation-based" ) )
125 
126  if ( ok )
127  *ok = false;
129 }
130 
132 {
133  if ( val == 0 )
135  else if ( val == 1 )
137  else if ( val == 2 )
139  else if ( val == 3 )
141  else
143 }
144 
145 QColor QgsTextRendererUtils::readColor( QgsVectorLayer *layer, const QString &property, const QColor &defaultColor, bool withAlpha )
146 {
147  int r = layer->customProperty( property + 'R', QVariant( defaultColor.red() ) ).toInt();
148  int g = layer->customProperty( property + 'G', QVariant( defaultColor.green() ) ).toInt();
149  int b = layer->customProperty( property + 'B', QVariant( defaultColor.blue() ) ).toInt();
150  int a = withAlpha ? layer->customProperty( property + 'A', QVariant( defaultColor.alpha() ) ).toInt() : 255;
151  return QColor( r, g, b, a );
152 }
QgsTextRendererUtils::decodeBackgroundSizeType
static QgsTextBackgroundSettings::SizeType decodeBackgroundSizeType(const QString &string)
Decodes a string representation of a background size type to a type.
Definition: qgstextrendererutils.cpp:47
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsTextShadowSettings::ShadowBuffer
@ ShadowBuffer
Draw shadow under buffer.
Definition: qgstextshadowsettings.h:48
QgsTextRendererUtils::decodeBackgroundRotationType
static QgsTextBackgroundSettings::RotationType decodeBackgroundRotationType(const QString &string)
Decodes a string representation of a background rotation type to a type.
Definition: qgstextrendererutils.cpp:60
QgsUnitTypes::RenderPoints
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:172
QgsUnitTypes::RenderPercentage
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:171
QgsTextBackgroundSettings::SizeType
SizeType
Methods for determining the background shape size.
Definition: qgstextbackgroundsettings.h:66
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
QgsTextBackgroundSettings::RotationSync
@ RotationSync
Shape rotation is synced with text rotation.
Definition: qgstextbackgroundsettings.h:77
QgsTextRendererUtils::decodeTextOrientation
static QgsTextFormat::TextOrientation decodeTextOrientation(const QString &name, bool *ok=nullptr)
Attempts to decode a string representation of a text orientation.
Definition: qgstextrendererutils.cpp:112
QgsTextRendererUtils::readColor
static QColor readColor(QgsVectorLayer *layer, const QString &property, const QColor &defaultColor=Qt::black, bool withAlpha=true)
Converts an encoded color value from a layer property.
Definition: qgstextrendererutils.cpp:145
QgsTextRendererUtils::encodeTextOrientation
static QString encodeTextOrientation(QgsTextFormat::TextOrientation orientation)
Encodes a text orientation.
Definition: qgstextrendererutils.cpp:98
QgsTextBackgroundSettings::RotationOffset
@ RotationOffset
Shape rotation is offset from text rotation.
Definition: qgstextbackgroundsettings.h:78
QgsTextBackgroundSettings::ShapeSquare
@ ShapeSquare
Square - buffered sizes only.
Definition: qgstextbackgroundsettings.h:55
QgsTextFormat::VerticalOrientation
@ VerticalOrientation
Horizontally oriented text.
Definition: qgstextformat.h:47
QgsTextBackgroundSettings::RotationType
RotationType
Methods for determining the rotation of the background shape.
Definition: qgstextbackgroundsettings.h:76
qgstextrendererutils.h
QgsTextShadowSettings::ShadowPlacement
ShadowPlacement
Placement positions for text shadow.
Definition: qgstextshadowsettings.h:45
QgsTextBackgroundSettings::ShapeRectangle
@ ShapeRectangle
Rectangle.
Definition: qgstextbackgroundsettings.h:54
QgsTextRendererUtils::decodeShadowPlacementType
static QgsTextShadowSettings::ShadowPlacement decodeShadowPlacementType(const QString &string)
Decodes a string representation of a shadow placement type to a type.
Definition: qgstextrendererutils.cpp:77
QgsTextRendererUtils::decodeShapeType
static QgsTextBackgroundSettings::ShapeType decodeShapeType(const QString &string)
Decodes a string representation of a background shape type to a type.
Definition: qgstextrendererutils.cpp:19
QgsTextBackgroundSettings::ShapeCircle
@ ShapeCircle
Circle.
Definition: qgstextbackgroundsettings.h:57
QgsTextShadowSettings::ShadowLowest
@ ShadowLowest
Draw shadow below all text components.
Definition: qgstextshadowsettings.h:46
QgsTextBackgroundSettings::SizeBuffer
@ SizeBuffer
Shape size is determined by adding a buffer margin around text.
Definition: qgstextbackgroundsettings.h:67
QgsTextShadowSettings::ShadowShape
@ ShadowShape
Draw shadow under background shape.
Definition: qgstextshadowsettings.h:49
QgsTextBackgroundSettings::ShapeEllipse
@ ShapeEllipse
Ellipse.
Definition: qgstextbackgroundsettings.h:56
qgsvectorlayer.h
QgsMapLayer::customProperty
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
Definition: qgsmaplayer.cpp:1723
QgsTextFormat::RotationBasedOrientation
@ RotationBasedOrientation
Horizontally or vertically oriented text based on rotation (only available for map labeling)
Definition: qgstextformat.h:48
QgsTextBackgroundSettings::ShapeSVG
@ ShapeSVG
SVG file.
Definition: qgstextbackgroundsettings.h:58
QgsTextBackgroundSettings::SizeFixed
@ SizeFixed
Fixed size.
Definition: qgstextbackgroundsettings.h:68
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsTextShadowSettings::ShadowText
@ ShadowText
Draw shadow under text.
Definition: qgstextshadowsettings.h:47
QgsTextBackgroundSettings::ShapeType
ShapeType
Background shape types.
Definition: qgstextbackgroundsettings.h:53
QgsTextBackgroundSettings::ShapeMarkerSymbol
@ ShapeMarkerSymbol
Marker symbol.
Definition: qgstextbackgroundsettings.h:59
QgsTextBackgroundSettings::RotationFixed
@ RotationFixed
Shape rotation is a fixed angle.
Definition: qgstextbackgroundsettings.h:79
QgsTextRendererUtils::convertFromOldLabelUnit
static QgsUnitTypes::RenderUnit convertFromOldLabelUnit(int val)
Converts a unit from an old (pre 3.0) label unit.
Definition: qgstextrendererutils.cpp:131
QgsTextFormat::HorizontalOrientation
@ HorizontalOrientation
Vertically oriented text.
Definition: qgstextformat.h:46
QgsUnitTypes::RenderMapUnits
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:169
QgsTextFormat::TextOrientation
TextOrientation
Text orientation.
Definition: qgstextformat.h:45