55#include <QApplication>
57#include <QFontMetrics>
62#include <QTextBoundaryFinder>
66using namespace Qt::StringLiterals;
83 DEFAULT_PLACEMENT_ORDER,
103void QgsPalLayerSettings::initPropertyDefinitions()
105 if ( !sPropertyDefinitions()->isEmpty() )
108 const QString origin = u
"labeling"_s;
118 QgsPropertyDefinition(
121 QObject::tr(
"Font family" ),
122 QObject::tr(
"string " )
124 "[<b>family</b>|<b>family[foundry]</b>],<br>"
125 "e.g. Helvetica or Helvetica [Cronyx]"
130 QgsPropertyDefinition(
133 QObject::tr(
"Font style" ),
134 QObject::tr(
"string " )
136 "[<b>font style name</b>|<b>Ignore</b>],<br>"
137 "e.g. Bold Condensed or Light Italic"
147 QgsPropertyDefinition(
"FontCase",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Font case" ), QObject::tr(
"string " ) + u
"[<b>NoChange</b>|<b>Upper</b>|<br><b>Lower</b>|<b>Title</b>|<b>Capitalize</b>|<b>SmallCaps</b>|<b>AllSmallCaps</b>]"_s, origin ) },
156 QgsPropertyDefinition(
"MultiLineAlignment",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Line alignment" ), QObject::tr(
"string " ) +
"[<b>Left</b>|<b>Center</b>|<b>Right</b>|<b>Follow</b>]", origin ) },
158 QgsPropertyDefinition(
"TabStopDistance",
QgsPropertyDefinition::DataTypeNumeric, QObject::tr(
"Tab stop distance(s)" ), QObject::tr(
"Numeric distance or array of distances" ), origin ) },
160 QgsPropertyDefinition(
"TextOrientation",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Text orientation" ), QObject::tr(
"string " ) +
"[<b>horizontal</b>|<b>vertical</b>]", origin ) },
165 QgsPropertyDefinition(
"DirSymbPlacement",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Direction symbol placement" ), QObject::tr(
"string " ) +
"[<b>LeftRight</b>|<b>Above</b>|<b>Below</b>]", origin ) },
188 QgsPropertyDefinition(
191 QObject::tr(
"Shape type" ),
192 QObject::tr(
"string " )
194 "[<b>Rectangle</b>|<b>Square</b>|<br>"
195 "<b>Ellipse</b>|<b>Circle</b>|<b>SVG</b>]"
201 QgsPropertyDefinition(
"ShapeSizeType",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Shape size type" ), QObject::tr(
"string " ) +
"[<b>Buffer</b>|<b>Fixed</b>]", origin ) },
206 QgsPropertyDefinition(
"ShapeRotationType",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Shape rotation type" ), QObject::tr(
"string " ) +
"[<b>Sync</b>|<b>Offset</b>|<b>Fixed</b>]", origin ) },
226 QgsPropertyDefinition(
229 QObject::tr(
"Symbol size" ),
230 QObject::tr(
"string " )
232 "[<b>Lowest</b>|<b>Text</b>|<br>"
233 "<b>Buffer</b>|<b>Background</b>]"
254 QgsPropertyDefinition(
"CentroidWhole",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Centroid of whole shape" ), QObject::tr(
"string " ) +
"[<b>Visible</b>|<b>Whole</b>]", origin ) },
256 QgsPropertyDefinition(
259 QObject::tr(
"Offset quadrant" ),
260 QObject::tr(
"int<br>" )
262 "[<b>0</b>=Above Left|<b>1</b>=Above|<b>2</b>=Above Right|<br>"
263 "<b>3</b>=Left|<b>4</b>=Over|<b>5</b>=Right|<br>"
264 "<b>6</b>=Below Left|<b>7</b>=Below|<b>8</b>=Below Right]"
274 QgsPropertyDefinition(
"CurvedCharAngleInOut",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Curved character angles" ), QObject::tr(
"double coord [<b>in,out</b> as 20.0-60.0,20.0-95.0]" ), origin ) },
282 QgsPropertyDefinition(
"LineAnchorClipping",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Line anchor clipping mode" ), QObject::tr(
"string " ) + u
"[<b>visible</b>|<b>entire</b>]"_s, origin ) },
284 QgsPropertyDefinition(
"LineAnchorType",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Line anchor type" ), QObject::tr(
"string " ) + u
"[<b>hint</b>|<b>strict</b>]"_s, origin ) },
286 QgsPropertyDefinition(
"LineAnchorTextPoint",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Line anchor text point" ), QObject::tr(
"string " ) + u
"[<b>follow</b>|<b>start</b>|<b>center</b>|<b>end</b>]"_s, origin ) },
288 QgsPropertyDefinition(
"CurvedLabelMode",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Curved label mode" ), QObject::tr(
"string " ) + u
"[<b>Default</b>|<b>CharactersAtVertices</b>|<b>StretchCharacterSpacingToFit</b>|<b>StretchWordSpacingToFit</b>]"_s, origin ) },
295 QgsPropertyDefinition(
296 "PredefinedPositionOrder",
298 QObject::tr(
"Predefined position order" ),
299 QObject::tr(
"Comma separated list of placements in order of priority<br>" )
301 "[<b>TL</b>=Top left|<b>TSL</b>=Top, slightly left|<b>T</b>=Top middle|<br>"
302 "<b>TSR</b>=Top, slightly right|<b>TR</b>=Top right|<br>"
303 "<b>L</b>=Left|<b>R</b>=Right|<br>"
304 "<b>BL</b>=Bottom left|<b>BSL</b>=Bottom, slightly left|<b>B</b>=Bottom middle|<br>"
305 "<b>BSR</b>=Bottom, slightly right|<b>BR</b>=Bottom right|<b>O</b>=Over point]"
310 QgsPropertyDefinition(
311 "LinePlacementFlags",
313 QObject::tr(
"Line placement options" ),
314 QObject::tr(
"Comma separated list of placement options<br>" )
316 "[<b>OL</b>=On line|<b>AL</b>=Above line|<b>BL</b>=Below line|<br>"
317 "<b>LO</b>=Respect line orientation]"
322 QgsPropertyDefinition(
"PolygonLabelOutside",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Label outside polygons" ), QObject::tr(
"string " ) +
"[<b>yes</b> (allow placing outside)|<b>no</b> (never place outside)|<b>force</b> (always place outside)]", origin ) },
328 QgsPropertyDefinition(
"Hali",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Horizontal alignment" ), QObject::tr(
"string " ) +
"[<b>Left</b>|<b>Center</b>|<b>Right</b>]", origin ) },
330 QgsPropertyDefinition(
333 QObject::tr(
"Vertical alignment" ),
334 QObject::tr(
"string " )
336 "[<b>Bottom</b>|<b>Base</b>|<br>"
337 "<b>Half</b>|<b>Cap</b>|<b>Top</b>]"
357 QgsPropertyDefinition(
"LabelAllParts",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Multipart geometry behavior" ), QObject::tr(
"string " ) +
"[<b>LargestPartOnly</b>|<b>LabelEveryPart</b>|<b>SplitLabelTextLinesOverParts</b>]", origin ) },
361 QgsPropertyDefinition(
"OverlapHandling",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Overlap handling" ), QObject::tr(
"string " ) +
"[<b>Prevent</b>|<b>AllowIfNeeded</b>|<b>AlwaysAllow</b>]", origin ) },
364 QgsPropertyDefinition(
"WhitespaceCollisionHandling",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Whitespace collision handling" ), QObject::tr(
"string " ) + u
"[<b>TreatWhitespaceAsCollision</b>|<b>IgnoreWhitespaceCollisions</b>]"_s, origin ) },
382 mPointSettings.setPredefinedPositionOrder( *DEFAULT_PLACEMENT_ORDER() );
384 initPropertyDefinitions();
392 : mDataDefinedProperties( s.mDataDefinedProperties )
427 mPolygonPlacementFlags = s.mPolygonPlacementFlags;
441 mRotationUnit = s.mRotationUnit;
461 mDataDefinedProperties = s.mDataDefinedProperties;
463 mCallout.reset( s.mCallout ? s.mCallout->clone() :
nullptr );
465 mPlacementSettings = s.mPlacementSettings;
466 mLineSettings = s.mLineSettings;
467 mPointSettings = s.mPointSettings;
468 mObstacleSettings = s.mObstacleSettings;
469 mThinningSettings = s.mThinningSettings;
476 mLegendString = s.mLegendString;
478 mUnplacedVisibility = s.mUnplacedVisibility;
513 if (
drawLabels || mObstacleSettings.isObstacle() )
528 for (
const QString &name : referencedColumns )
530 attributeNames.insert( name );
587 if ( mGeometryGeneratorExpression.hasParserError() )
593 const auto referencedColumns = mGeometryGeneratorExpression.referencedColumns();
594 for (
const QString &name : referencedColumns )
596 attributeNames.insert( name );
599 attributeNames.unite( mFormat.referencedFields( context ) );
603 const auto referencedColumns = mCallout->referencedFields( context );
604 for (
const QString &name : referencedColumns )
606 attributeNames.insert( name );
615 QSet<QString> referenced;
628 referenced.unite( mFormat.referencedFields( context ) );
633 referenced.unite( mDataDefinedProperties.referencedFields( context.
expressionContext(),
true ) );
643 referenced.unite( mCallout->referencedFields( context ) );
651 if ( mRenderStarted )
653 qWarning(
"Start render called for when a previous render was already underway!!" );
680 mCallout->startRender( context );
683 mRenderStarted =
true;
688 if ( !mRenderStarted )
690 qWarning(
"Stop render called for QgsPalLayerSettings without a startRender call!" );
696 mCallout->stopRender( context );
699 mRenderStarted =
false;
704 return mFormat.containsAdvancedEffects() || mCallout->containsAdvancedEffects();
709 if ( mRenderStarted )
711 qWarning(
"stopRender was not called on QgsPalLayerSettings object!" );
718 initPropertyDefinitions();
719 return *sPropertyDefinitions();
726 expression = std::make_unique<QgsExpression>(
fieldName );
728 return expression.get();
733 return mRotationUnit;
738 mRotationUnit = angleUnit;
744 QString newValue = value;
745 if ( !value.isEmpty() && !value.contains(
"~~"_L1 ) )
752 newValue = values.join(
"~~"_L1 );
760 QString newPropertyName =
"labeling/dataDefined/" + sPropertyDefinitions()->value(
static_cast< int >( p ) ).name();
761 QVariant newPropertyField = layer->
customProperty( newPropertyName, QVariant() );
763 if ( !newPropertyField.isValid() )
766 QString ddString = newPropertyField.toString();
768 if ( !ddString.isEmpty() && ddString !=
"0~~0~~~~"_L1 )
772 QStringList ddv = newStyleString.split( u
"~~"_s );
774 bool active = ddv.at( 0 ).toInt();
775 if ( ddv.at( 1 ).toInt() )
791void QgsPalLayerSettings::readOldDataDefinedPropertyMap(
QgsVectorLayer *layer, QDomElement *parentElem )
793 if ( !layer && !parentElem )
798 QgsPropertiesDefinition::const_iterator i = sPropertyDefinitions()->constBegin();
799 for ( ; i != sPropertyDefinitions()->constEnd(); ++i )
804 readOldDataDefinedProperty( layer,
static_cast< Property >( i.key() ) );
806 else if ( parentElem )
809 QDomElement e = parentElem->firstChildElement( i.value().name() );
812 bool active = e.attribute( u
"active"_s ).compare(
"true"_L1, Qt::CaseInsensitive ) == 0;
813 bool isExpression = e.attribute( u
"useExpr"_s ).compare(
"true"_L1, Qt::CaseInsensitive ) == 0;
820 mDataDefinedProperties.setProperty( i.key(),
QgsProperty::fromField( e.attribute( u
"field"_s ), active ) );
827void QgsPalLayerSettings::readFromLayerCustomProperties(
QgsVectorLayer *layer )
829 if ( layer->
customProperty( u
"labeling"_s ).toString() !=
"pal"_L1 )
846 mFormat.readFromLayer( layer );
854 QDomDocument doc( u
"substitutions"_s );
855 doc.setContent( layer->
customProperty( u
"labeling/substitutions"_s ).toString() );
856 QDomElement replacementElem = doc.firstChildElement( u
"substitutions"_s );
868 mLineSettings.setAddDirectionSymbol( layer->
customProperty( u
"labeling/addDirectionSymbol"_s ).toBool() );
869 mLineSettings.setLeftDirectionSymbol( layer->
customProperty( u
"labeling/leftDirectionSymbol"_s, QVariant(
"<" ) ).toString() );
870 mLineSettings.setRightDirectionSymbol( layer->
customProperty( u
"labeling/rightDirectionSymbol"_s, QVariant(
">" ) ).toString() );
871 mLineSettings.setReverseDirectionSymbol( layer->
customProperty( u
"labeling/reverseDirectionSymbol"_s ).toBool() );
872 mLineSettings.setDirectionSymbolPlacement(
888 if ( predefinedPositionOrder.isEmpty() )
889 predefinedPositionOrder = *DEFAULT_PLACEMENT_ORDER();
890 mPointSettings.setPredefinedPositionOrder( predefinedPositionOrder );
895 if ( layer->
customProperty( u
"labeling/distMapUnitScale"_s ).toString().isEmpty() )
898 double oldMin = layer->
customProperty( u
"labeling/distMapUnitMinScale"_s, 0.0 ).toDouble();
900 double oldMax = layer->
customProperty( u
"labeling/distMapUnitMaxScale"_s, 0.0 ).toDouble();
908 mPointSettings.setQuadrant(
913 if ( layer->
customProperty( u
"labeling/labelOffsetInMapUnits"_s, QVariant(
true ) ).toBool() )
918 if ( layer->
customProperty( u
"labeling/labelOffsetMapUnitScale"_s ).toString().isEmpty() )
921 double oldMin = layer->
customProperty( u
"labeling/labelOffsetMapUnitMinScale"_s, 0.0 ).toDouble();
923 double oldMax = layer->
customProperty( u
"labeling/labelOffsetMapUnitMaxScale"_s, 0.0 ).toDouble();
931 QVariant tempAngle = layer->
customProperty( u
"labeling/angleOffset"_s, QVariant() );
932 if ( tempAngle.isValid() )
934 double oldAngle = layer->
customProperty( u
"labeling/angleOffset"_s, QVariant( 0.0 ) ).toDouble();
948 switch ( layer->
customProperty( u
"labeling/repeatDistanceUnit"_s, QVariant( 1 ) ).toUInt() )
963 if ( layer->
customProperty( u
"labeling/repeatDistanceMapUnitScale"_s ).toString().isEmpty() )
966 double oldMin = layer->
customProperty( u
"labeling/repeatDistanceMapUnitMinScale"_s, 0.0 ).toDouble();
968 double oldMax = layer->
customProperty( u
"labeling/repeatDistanceMapUnitMaxScale"_s, 0.0 ).toDouble();
977 double scalemn = layer->
customProperty( u
"labeling/scaleMin"_s, QVariant( 0 ) ).toDouble();
978 double scalemx = layer->
customProperty( u
"labeling/scaleMax"_s, QVariant( 0 ) ).toDouble();
981 QVariant scalevis = layer->
customProperty( u
"labeling/scaleVisibility"_s, QVariant() );
982 if ( scalevis.isValid() )
988 else if ( scalemn > 0 || scalemx > 0 )
1004 if ( layer->
customProperty( u
"labeling/displayAll"_s, QVariant(
false ) ).toBool() )
1007 mPlacementSettings.setAllowDegradedPlacement(
true );
1012 mPlacementSettings.setAllowDegradedPlacement(
false );
1018 mLineSettings.setMergeLines( layer->
customProperty( u
"labeling/mergeLines"_s ).toBool() );
1019 mThinningSettings.setMinimumFeatureSize( layer->
customProperty( u
"labeling/minFeatureSize"_s ).toDouble() );
1020 mThinningSettings.setLimitNumberLabelsEnabled( layer->
customProperty( u
"labeling/limitNumLabels"_s, QVariant(
false ) ).toBool() );
1021 mThinningSettings.setMaximumNumberLabels( layer->
customProperty( u
"labeling/maxNumLabels"_s, QVariant( 2000 ) ).toInt() );
1022 mObstacleSettings.setIsObstacle( layer->
customProperty( u
"labeling/obstacle"_s, QVariant(
true ) ).toBool() );
1023 mObstacleSettings.setFactor( layer->
customProperty( u
"labeling/obstacleFactor"_s, QVariant( 1.0 ) ).toDouble() );
1024 mObstacleSettings.setType(
1031 mDataDefinedProperties.clear();
1032 if ( layer->
customProperty( u
"labeling/ddProperties"_s ).isValid() )
1034 QDomDocument doc( u
"dd"_s );
1035 doc.setContent( layer->
customProperty( u
"labeling/ddProperties"_s ).toString() );
1036 QDomElement elem = doc.firstChildElement( u
"properties"_s );
1037 mDataDefinedProperties.readXml( elem, *sPropertyDefinitions() );
1042 readOldDataDefinedPropertyMap( layer,
nullptr );
1047 mDataDefinedProperties
1053 mDataDefinedProperties
1059 mDataDefinedProperties
1065 mDataDefinedProperties
1071 mDataDefinedProperties
1091 QDomElement textStyleElem = elem.firstChildElement( u
"text-style"_s );
1092 fieldName = textStyleElem.attribute( u
"fieldName"_s );
1093 isExpression = textStyleElem.attribute( u
"isExpression"_s ).toInt();
1095 mFormat.readXml( elem, context );
1097 previewBkgrdColor = QColor( textStyleElem.attribute( u
"previewBkgrdColor"_s, u
"#ffffff"_s ) );
1099 substitutions.readXml( textStyleElem.firstChildElement( u
"substitutions"_s ) );
1100 useSubstitutions = textStyleElem.attribute( u
"useSubstitutions"_s ).toInt();
1101 mLegendString = textStyleElem.attribute( u
"legendString"_s, QObject::tr(
"Aa" ) );
1104 QDomElement textFormatElem = elem.firstChildElement( u
"text-format"_s );
1105 wrapChar = textFormatElem.attribute( u
"wrapChar"_s );
1106 autoWrapLength = textFormatElem.attribute( u
"autoWrapLength"_s, u
"0"_s ).toInt();
1111 mLineSettings.setAddDirectionSymbol( textFormatElem.attribute( u
"addDirectionSymbol"_s ).toInt() );
1112 mLineSettings.setLeftDirectionSymbol( textFormatElem.attribute( u
"leftDirectionSymbol"_s, u
"<"_s ) );
1113 mLineSettings.setRightDirectionSymbol( textFormatElem.attribute( u
"rightDirectionSymbol"_s, u
">"_s ) );
1114 mLineSettings.setReverseDirectionSymbol( textFormatElem.attribute( u
"reverseDirectionSymbol"_s ).toInt() );
1115 mLineSettings.setDirectionSymbolPlacement(
1120 formatNumbers = textFormatElem.attribute( u
"formatNumbers"_s ).toInt();
1121 decimals = textFormatElem.attribute( u
"decimals"_s ).toInt();
1122 plusSign = textFormatElem.attribute( u
"plussign"_s ).toInt();
1125 QDomElement placementElem = elem.firstChildElement( u
"placement"_s );
1132 centroidWhole = placementElem.attribute( u
"centroidWhole"_s, u
"0"_s ).toInt();
1133 centroidInside = placementElem.attribute( u
"centroidInside"_s, u
"0"_s ).toInt();
1136 if ( predefinedPositionOrder.isEmpty() )
1137 predefinedPositionOrder = *DEFAULT_PLACEMENT_ORDER();
1138 mPointSettings.setPredefinedPositionOrder( predefinedPositionOrder );
1140 fitInPolygonOnly = placementElem.attribute( u
"fitInPolygonOnly"_s, u
"0"_s ).toInt();
1141 dist = placementElem.attribute( u
"dist"_s ).toDouble();
1142 if ( !placementElem.hasAttribute( u
"distUnits"_s ) )
1144 if ( placementElem.attribute( u
"distInMapUnits"_s ).toInt() )
1153 if ( !placementElem.hasAttribute( u
"distMapUnitScale"_s ) )
1156 double oldMin = placementElem.attribute( u
"distMapUnitMinScale"_s, u
"0"_s ).toDouble();
1158 double oldMax = placementElem.attribute( u
"distMapUnitMaxScale"_s, u
"0"_s ).toDouble();
1166 mPointSettings.setQuadrant(
1169 xOffset = placementElem.attribute( u
"xOffset"_s, u
"0"_s ).toDouble();
1170 yOffset = placementElem.attribute( u
"yOffset"_s, u
"0"_s ).toDouble();
1171 if ( !placementElem.hasAttribute( u
"offsetUnits"_s ) )
1179 if ( !placementElem.hasAttribute( u
"labelOffsetMapUnitScale"_s ) )
1182 double oldMin = placementElem.attribute( u
"labelOffsetMapUnitMinScale"_s, u
"0"_s ).toDouble();
1184 double oldMax = placementElem.attribute( u
"labelOffsetMapUnitMaxScale"_s, u
"0"_s ).toDouble();
1192 if ( placementElem.hasAttribute( u
"angleOffset"_s ) )
1194 double oldAngle = placementElem.attribute( u
"angleOffset"_s, u
"0"_s ).toDouble();
1199 angleOffset = placementElem.attribute( u
"rotationAngle"_s, u
"0"_s ).toDouble();
1202 preserveRotation = placementElem.attribute( u
"preserveRotation"_s, u
"1"_s ).toInt();
1205 if ( rotationUnitString.startsWith(
"Angle"_L1 ) )
1208 rotationUnitString = rotationUnitString.mid( 5 );
1213 maxCurvedCharAngleIn = placementElem.attribute( u
"maxCurvedCharAngleIn"_s, u
"25"_s ).toDouble();
1215 priority = placementElem.attribute( u
"priority"_s ).toInt();
1216 repeatDistance = placementElem.attribute( u
"repeatDistance"_s, u
"0"_s ).toDouble();
1217 if ( !placementElem.hasAttribute( u
"repeatDistanceUnits"_s ) )
1220 switch ( placementElem.attribute( u
"repeatDistanceUnit"_s, QString::number( 1 ) ).toUInt() )
1240 if ( !placementElem.hasAttribute( u
"repeatDistanceMapUnitScale"_s ) )
1243 double oldMin = placementElem.attribute( u
"repeatDistanceMapUnitMinScale"_s, u
"0"_s ).toDouble();
1245 double oldMax = placementElem.attribute( u
"repeatDistanceMapUnitMaxScale"_s, u
"0"_s ).toDouble();
1253 mLineSettings.setOverrunDistance( placementElem.attribute( u
"overrunDistance"_s, u
"0"_s ).toDouble() );
1256 mLineSettings.setLineAnchorPercent( placementElem.attribute( u
"lineAnchorPercent"_s, u
"0.5"_s ).toDouble() );
1263 mPointSettings.setMaximumDistance( placementElem.attribute( u
"maximumDistance"_s, u
"0"_s ).toDouble() );
1270 QString geometryTypeKey = placementElem.attribute( u
"geometryGeneratorType"_s );
1272 if ( geometryTypeKey.endsWith(
"Geometry"_L1 ) )
1273 geometryTypeKey.chop( 8 );
1278 QString layerTypeKey = placementElem.attribute( u
"layerType"_s );
1280 if ( layerTypeKey.endsWith(
"Geometry"_L1 ) )
1281 layerTypeKey.chop( 8 );
1286 mPlacementSettings.setAllowDegradedPlacement( placementElem.attribute( u
"allowDegraded"_s, u
"0"_s ).toInt() );
1289 QDomElement renderingElem = elem.firstChildElement( u
"rendering"_s );
1291 drawLabels = renderingElem.attribute( u
"drawLabels"_s, u
"1"_s ).toInt();
1293 maximumScale = renderingElem.attribute( u
"scaleMin"_s, u
"0"_s ).toDouble();
1294 minimumScale = renderingElem.attribute( u
"scaleMax"_s, u
"0"_s ).toDouble();
1295 scaleVisibility = renderingElem.attribute( u
"scaleVisibility"_s ).toInt();
1297 fontLimitPixelSize = renderingElem.attribute( u
"fontLimitPixelSize"_s, u
"0"_s ).toInt();
1298 fontMinPixelSize = renderingElem.attribute( u
"fontMinPixelSize"_s, u
"0"_s ).toInt();
1299 fontMaxPixelSize = renderingElem.attribute( u
"fontMaxPixelSize"_s, u
"10000"_s ).toInt();
1301 if ( placementElem.hasAttribute( u
"overlapHandling"_s ) )
1308 if ( renderingElem.attribute( u
"displayAll"_s, u
"0"_s ).toInt() )
1311 mPlacementSettings.setAllowDegradedPlacement(
true );
1316 mPlacementSettings.setAllowDegradedPlacement(
false );
1326 if ( placementElem.hasAttribute( u
"multipartBehavior"_s ) )
1333 if ( renderingElem.attribute( u
"labelPerPart"_s, u
"0"_s ).toInt() )
1345 mLineSettings.setMergeLines( renderingElem.attribute( u
"mergeLines"_s ).toInt() );
1346 mThinningSettings.setMinimumFeatureSize( renderingElem.attribute( u
"minFeatureSize"_s ).toDouble() );
1347 mThinningSettings.setLimitNumberLabelsEnabled( renderingElem.attribute( u
"limitNumLabels"_s, u
"0"_s ).toInt() );
1348 mThinningSettings.setMaximumNumberLabels( renderingElem.attribute( u
"maxNumLabels"_s, u
"2000"_s ).toInt() );
1350 mThinningSettings.setLabelMarginDistance( placementElem.attribute( u
"labelMarginDistance"_s, u
"0"_s ).toDouble() );
1355 mThinningSettings.setMinimumDistanceToDuplicateUnit(
QgsUnitTypes::decodeRenderUnit( placementElem.attribute( u
"minDistanceToDuplicatesUnit"_s ) ) );
1357 mThinningSettings.setAllowDuplicateRemoval( placementElem.attribute( u
"allowDuplicateRemoval"_s, u
"0"_s ).toInt() );
1359 mObstacleSettings.setIsObstacle( renderingElem.attribute( u
"obstacle"_s, u
"1"_s ).toInt() );
1360 mObstacleSettings.setFactor( renderingElem.attribute( u
"obstacleFactor"_s, u
"1"_s ).toDouble() );
1361 mObstacleSettings.setType(
1366 zIndex = renderingElem.attribute( u
"zIndex"_s, u
"0.0"_s ).toDouble();
1371 QDomElement ddElem = elem.firstChildElement( u
"dd_properties"_s );
1372 if ( !ddElem.isNull() )
1374 mDataDefinedProperties.readXml( ddElem, *sPropertyDefinitions() );
1379 mDataDefinedProperties.clear();
1380 QDomElement ddElem = elem.firstChildElement( u
"data-defined"_s );
1381 readOldDataDefinedPropertyMap(
nullptr, &ddElem );
1386 mDataDefinedProperties
1392 mDataDefinedProperties
1398 mDataDefinedProperties
1404 mDataDefinedProperties
1410 mDataDefinedProperties
1427 const QString calloutType = elem.attribute( u
"calloutType"_s );
1428 if ( calloutType.isEmpty() )
1440 QDomElement textStyleElem = mFormat.writeXml( doc, context );
1443 textStyleElem.setAttribute( u
"fieldName"_s,
fieldName );
1444 textStyleElem.setAttribute( u
"isExpression"_s,
isExpression );
1445 QDomElement replacementElem = doc.createElement( u
"substitutions"_s );
1447 textStyleElem.appendChild( replacementElem );
1449 textStyleElem.setAttribute( u
"legendString"_s, mLegendString );
1452 QDomElement textFormatElem = doc.createElement( u
"text-format"_s );
1453 textFormatElem.setAttribute( u
"wrapChar"_s,
wrapChar );
1454 textFormatElem.setAttribute( u
"autoWrapLength"_s,
autoWrapLength );
1456 textFormatElem.setAttribute( u
"multilineAlign"_s,
static_cast< unsigned int >(
multilineAlign ) );
1457 textFormatElem.setAttribute( u
"addDirectionSymbol"_s, mLineSettings.addDirectionSymbol() );
1458 textFormatElem.setAttribute( u
"leftDirectionSymbol"_s, mLineSettings.leftDirectionSymbol() );
1459 textFormatElem.setAttribute( u
"rightDirectionSymbol"_s, mLineSettings.rightDirectionSymbol() );
1460 textFormatElem.setAttribute( u
"reverseDirectionSymbol"_s, mLineSettings.reverseDirectionSymbol() );
1461 textFormatElem.setAttribute( u
"placeDirectionSymbol"_s,
static_cast< unsigned int >( mLineSettings.directionSymbolPlacement() ) );
1462 textFormatElem.setAttribute( u
"formatNumbers"_s,
formatNumbers );
1463 textFormatElem.setAttribute( u
"decimals"_s,
decimals );
1464 textFormatElem.setAttribute( u
"plussign"_s,
plusSign );
1467 QDomElement placementElem = doc.createElement( u
"placement"_s );
1468 placementElem.setAttribute( u
"placement"_s,
static_cast< int >(
placement ) );
1469 placementElem.setAttribute( u
"polygonPlacementFlags"_s,
static_cast< int >( mPolygonPlacementFlags ) );
1470 placementElem.setAttribute( u
"placementFlags"_s,
static_cast< unsigned int >( mLineSettings.placementFlags() ) );
1471 placementElem.setAttribute( u
"centroidWhole"_s,
centroidWhole );
1472 placementElem.setAttribute( u
"centroidInside"_s,
centroidInside );
1475 placementElem.setAttribute( u
"dist"_s,
dist );
1478 placementElem.setAttribute( u
"offsetType"_s,
static_cast< unsigned int >(
offsetType ) );
1479 placementElem.setAttribute( u
"quadOffset"_s,
static_cast< unsigned int >( mPointSettings.quadrant() ) );
1480 placementElem.setAttribute( u
"xOffset"_s,
xOffset );
1481 placementElem.setAttribute( u
"yOffset"_s,
yOffset );
1484 placementElem.setAttribute( u
"rotationAngle"_s,
angleOffset );
1488 const QString rotationUnitString = u
"Angle"_s +
qgsEnumValueToKey( mRotationUnit );
1489 placementElem.setAttribute( u
"rotationUnit"_s, rotationUnitString );
1493 placementElem.setAttribute( u
"priority"_s,
priority );
1494 placementElem.setAttribute( u
"repeatDistance"_s,
repeatDistance );
1497 placementElem.setAttribute( u
"overrunDistance"_s, mLineSettings.overrunDistance() );
1498 placementElem.setAttribute( u
"overrunDistanceUnit"_s,
QgsUnitTypes::encodeUnit( mLineSettings.overrunDistanceUnit() ) );
1500 placementElem.setAttribute( u
"lineAnchorPercent"_s, mLineSettings.lineAnchorPercent() );
1501 placementElem.setAttribute( u
"lineAnchorType"_s,
static_cast< int >( mLineSettings.anchorType() ) );
1502 placementElem.setAttribute( u
"lineAnchorClipping"_s,
static_cast< int >( mLineSettings.anchorClipping() ) );
1503 placementElem.setAttribute( u
"lineAnchorTextPoint"_s,
qgsEnumValueToKey( mLineSettings.anchorTextPoint() ) );
1506 placementElem.setAttribute( u
"curvedLabelMode"_s,
qgsEnumValueToKey( mLineSettings.curvedLabelMode() ) );
1509 placementElem.setAttribute( u
"maximumDistance"_s, mPointSettings.maximumDistance() );
1510 placementElem.setAttribute( u
"maximumDistanceUnit"_s,
QgsUnitTypes::encodeUnit( mPointSettings.maximumDistanceUnit() ) );
1519 placementElem.setAttribute( u
"overlapHandling"_s,
qgsEnumValueToKey( mPlacementSettings.overlapHandling() ) );
1520 placementElem.setAttribute( u
"prioritization"_s,
qgsEnumValueToKey( mPlacementSettings.prioritization() ) );
1521 placementElem.setAttribute( u
"allowDegraded"_s, mPlacementSettings.allowDegradedPlacement() ? u
"1"_s : u
"0"_s );
1524 QDomElement renderingElem = doc.createElement( u
"rendering"_s );
1525 renderingElem.setAttribute( u
"drawLabels"_s,
drawLabels );
1527 renderingElem.setAttribute( u
"scaleMin"_s,
maximumScale );
1528 renderingElem.setAttribute( u
"scaleMax"_s,
minimumScale );
1532 renderingElem.setAttribute( u
"upsidedownLabels"_s,
static_cast< unsigned int >(
upsidedownLabels ) );
1533 placementElem.setAttribute( u
"multipartBehavior"_s,
qgsEnumValueToKey( mPlacementSettings.multiPartBehavior() ) );
1535 placementElem.setAttribute( u
"whitespaceCollisions"_s,
qgsEnumValueToKey( mPlacementSettings.whitespaceCollisionHandling() ) );
1536 renderingElem.setAttribute( u
"mergeLines"_s, mLineSettings.mergeLines() );
1537 renderingElem.setAttribute( u
"minFeatureSize"_s, mThinningSettings.minimumFeatureSize() );
1538 renderingElem.setAttribute( u
"limitNumLabels"_s, mThinningSettings.limitNumberOfLabelsEnabled() );
1539 renderingElem.setAttribute( u
"maxNumLabels"_s, mThinningSettings.maximumNumberLabels() );
1541 if ( mThinningSettings.labelMarginDistance() > 0 )
1543 placementElem.setAttribute( u
"labelMarginDistance"_s, mThinningSettings.labelMarginDistance() );
1547 placementElem.setAttribute( u
"labelMarginDistanceUnit"_s,
QgsUnitTypes::encodeUnit( mThinningSettings.labelMarginDistanceUnit() ) );
1549 if ( !mThinningSettings.labelMarginDistanceMapUnitScale().isNull() )
1556 placementElem.setAttribute( u
"minDistanceToDuplicates"_s, mThinningSettings.minimumDistanceToDuplicate() );
1560 placementElem.setAttribute( u
"minDistanceToDuplicatesUnit"_s,
QgsUnitTypes::encodeUnit( mThinningSettings.minimumDistanceToDuplicateUnit() ) );
1562 if ( !mThinningSettings.minimumDistanceToDuplicateMapUnitScale().isNull() )
1566 if ( mThinningSettings.allowDuplicateRemoval() )
1568 placementElem.setAttribute( u
"allowDuplicateRemoval"_s, u
"1"_s );
1571 renderingElem.setAttribute( u
"obstacle"_s, mObstacleSettings.isObstacle() );
1572 renderingElem.setAttribute( u
"obstacleFactor"_s, mObstacleSettings.factor() );
1573 renderingElem.setAttribute( u
"obstacleType"_s,
static_cast< unsigned int >( mObstacleSettings.type() ) );
1574 renderingElem.setAttribute( u
"zIndex"_s,
zIndex );
1575 renderingElem.setAttribute( u
"unplacedVisibility"_s,
static_cast< int >( mUnplacedVisibility ) );
1577 QDomElement ddElem = doc.createElement( u
"dd_properties"_s );
1578 mDataDefinedProperties.writeXml( ddElem, *sPropertyDefinitions() );
1580 QDomElement elem = doc.createElement( u
"settings"_s );
1581 elem.appendChild( textStyleElem );
1582 elem.appendChild( textFormatElem );
1583 elem.appendChild( placementElem );
1584 elem.appendChild( renderingElem );
1585 elem.appendChild( ddElem );
1589 elem.setAttribute( u
"calloutType"_s, mCallout->type() );
1590 mCallout->saveProperties( doc, elem, context );
1607 QPixmap pixmap( size * devicePixelRatio );
1608 pixmap.fill( Qt::transparent );
1609 pixmap.setDevicePixelRatio( devicePixelRatio );
1611 painter.begin( &pixmap );
1613 painter.setRenderHint( QPainter::Antialiasing );
1615 const QRectF rect( 0, 0, size.width(), size.height() );
1618 painter.setPen( Qt::NoPen );
1620 if ( ( background1.lightnessF() < 0.7 ) )
1622 background1 = background1.darker( 125 );
1626 background1 = background1.lighter( 125 );
1629 QLinearGradient linearGrad( QPointF( 0, 0 ), QPointF( 0, rect.height() ) );
1630 linearGrad.setColorAt( 0, background1 );
1631 linearGrad.setColorAt( 1, background2 );
1632 painter.setBrush( QBrush( linearGrad ) );
1633 if ( size.width() > 30 )
1635 painter.drawRoundedRect( rect, 6, 6 );
1640 painter.drawRect( rect );
1642 painter.setBrush( Qt::NoBrush );
1643 painter.setPen( Qt::NoPen );
1658 QWidget *activeWindow = QApplication::activeWindow();
1659 if ( QScreen *screen = activeWindow ? activeWindow->screen() :
nullptr )
1679 ? fontSize * tempFormat.
buffer().
size() / 100
1684 double ytrans = 0.0;
1694 const QStringList text = QStringList() << ( previewText.isEmpty() ? settings.
legendString() : previewText );
1696 QRectF textRect = rect;
1697 textRect.setLeft( xtrans + padding );
1698 textRect.setWidth( rect.width() - xtrans - 2 * padding );
1700 if ( textRect.width() > 2000 )
1701 textRect.setWidth( 2000 - 2 * padding );
1703 const double bottom = textRect.height() / 2 + textHeight / 2;
1704 textRect.setTop( bottom - textHeight );
1705 textRect.setBottom( bottom );
1714 callout->startRender( context );
1716 QRectF labelRect( textRect.left() + ( textRect.width() - textWidth ) / 2.0, textRect.top(), textWidth, textRect.height() );
1718 callout->stopRender( context );
1723 if ( size.width() > 30 )
1727 QgsApplication::getThemeIcon( u
"labelingSingle.svg"_s ).paint( &painter, QRect( rect.width() - iconWidth * 3, rect.height() - iconWidth * 3, iconWidth * 2, iconWidth * 2 ), Qt::AlignRight | Qt::AlignBottom );
1731 painter.setBrush( Qt::NoBrush );
1733 if ( size.width() > 30 )
1735 painter.drawRoundedRect( rect, 6, 6 );
1740 painter.drawRect( rect );
1749 return mUnplacedVisibility;
1754 mUnplacedVisibility = visibility;
1759 return QgsPalLabeling::checkMinimumSizeMM(
ct, geom, minSize );
1763 const QFontMetricsF *fm,
const QString &text,
double &labelX,
double &labelY,
const QgsFeature *f,
QgsRenderContext *context,
double *rotatedLabelX,
double *rotatedLabelY
1773 QString textCopy( text );
1776 std::unique_ptr< QgsRenderContext > scopedRc;
1779 scopedRc = std::make_unique<QgsRenderContext>();
1781 scopedRc->expressionContext().setFeature( *f );
1787 double multilineH = mFormat.lineHeight();
1790 bool addDirSymb = mLineSettings.addDirectionSymbol();
1791 QString leftDirSymb = mLineSettings.leftDirectionSymbol();
1792 QString rightDirSymb = mLineSettings.rightDirectionSymbol();
1896 if ( wrapchr.isEmpty() )
1904 QString dirSym = leftDirSymb;
1906 if ( fm->horizontalAdvance( rightDirSymb ) > fm->horizontalAdvance( dirSym ) )
1907 dirSym = rightDirSymb;
1909 switch ( placeDirSymb )
1912 textCopy.append( dirSym );
1917 textCopy.prepend( dirSym + u
"\n"_s );
1922 double w = 0.0, h = 0.0, rw = 0.0, rh = 0.0;
1923 double labelHeight = fm->ascent() + fm->descent();
1926 const int lines = multiLineSplit.size();
1928 const double lineHeightPainterUnits = rc->
convertToPainterUnits( mFormat.lineHeight(), mFormat.lineHeightUnit() );
1930 switch ( orientation )
1934 h += fm->height() +
static_cast< double >( ( lines - 1 ) * ( mFormat.lineHeightUnit() ==
Qgis::RenderUnit::Percentage ? ( labelHeight * multilineH ) : lineHeightPainterUnits ) );
1936 for (
const QString &line : std::as_const( multiLineSplit ) )
1938 w = std::max( w, fm->horizontalAdvance( line ) );
1945 double letterSpacing = mFormat.scaledFont( *rc ).letterSpacing();
1946 double labelWidth = fm->maxWidth();
1947 w = labelWidth + ( lines - 1 ) * ( mFormat.lineHeightUnit() ==
Qgis::RenderUnit::Percentage ? ( labelWidth * multilineH ) : lineHeightPainterUnits );
1949 int maxLineLength = 0;
1950 for (
const QString &line : std::as_const( multiLineSplit ) )
1952 maxLineLength = std::max( maxLineLength,
static_cast<int>( line.length() ) );
1954 h = fm->ascent() * maxLineLength + ( maxLineLength - 1 ) * letterSpacing;
1960 double widthHorizontal = 0.0;
1961 for (
const QString &line : std::as_const( multiLineSplit ) )
1963 widthHorizontal = std::max( widthHorizontal, fm->horizontalAdvance( line ) );
1966 double widthVertical = 0.0;
1967 double letterSpacing = mFormat.scaledFont( *rc ).letterSpacing();
1968 double labelWidth = fm->maxWidth();
1969 widthVertical = labelWidth + ( lines - 1 ) * ( mFormat.lineHeightUnit() ==
Qgis::RenderUnit::Percentage ? ( labelWidth * multilineH ) : lineHeightPainterUnits );
1971 double heightHorizontal = 0.0;
1972 heightHorizontal += fm->height() +
static_cast< double >( ( lines - 1 ) * ( mFormat.lineHeightUnit() ==
Qgis::RenderUnit::Percentage ? ( labelHeight * multilineH ) : lineHeightPainterUnits ) );
1974 double heightVertical = 0.0;
1975 int maxLineLength = 0;
1976 for (
const QString &line : std::as_const( multiLineSplit ) )
1978 maxLineLength = std::max( maxLineLength,
static_cast<int>( line.length() ) );
1980 heightVertical = fm->ascent() * maxLineLength + ( maxLineLength - 1 ) * letterSpacing;
1982 w = widthHorizontal;
1983 rw = heightVertical;
1984 h = heightHorizontal;
1990 double uPP =
xform->mapUnitsPerPixel();
1993 if ( rotatedLabelX && rotatedLabelY )
1995 *rotatedLabelX = rw * uPP;
1996 *rotatedLabelY = rh * uPP;
2000void QgsPalLayerSettings::calculateLabelMetrics(
2011 bool addDirSymb = mLineSettings.addDirectionSymbol();
2012 QString leftDirSymb = mLineSettings.leftDirectionSymbol();
2013 QString rightDirSymb = mLineSettings.rightDirectionSymbol();
2015 double multilineH = mFormat.lineHeight();
2049 const double lineHeightPainterUnits = context.
convertToPainterUnits( mFormat.lineHeight(), mFormat.lineHeightUnit() );
2052 QSizeF maximumExtraSpaceAllowance( 0, 0 );
2053 QSizeF minimumSize( 0, 0 );
2058 const QString dirSym = fm.horizontalAdvance( rightDirSymb ) > fm.horizontalAdvance( leftDirSymb ) ? rightDirSymb : leftDirSymb;
2060 switch ( placeDirSymb )
2063 maximumExtraSpaceAllowance = QSizeF( fm.horizontalAdvance( dirSym ), 0 );
2068 maximumExtraSpaceAllowance = QSizeF( 0, ( mFormat.lineHeightUnit() ==
Qgis::RenderUnit::Percentage ? ( ( fm.ascent() + fm.descent() ) * multilineH ) : lineHeightPainterUnits ) );
2069 minimumSize = QSizeF( fm.horizontalAdvance( dirSym ), 0 );
2081 w = std::max( minimumSize.width(), documentSize.width() + maximumExtraSpaceAllowance.width() );
2082 h = std::max( minimumSize.height(), documentSize.height() + maximumExtraSpaceAllowance.height() );
2087 rh = std::max( minimumSize.width(), rotatedSize.width() + maximumExtraSpaceAllowance.width() );
2088 rw = std::max( minimumSize.height(), rotatedSize.height() + maximumExtraSpaceAllowance.height() );
2091 const double uPP =
xform->mapUnitsPerPixel();
2092 size = QSizeF( w * uPP, h * uPP );
2093 rotatedSize = QSizeF( rw * uPP, rh * uPP );
2099 outerBounds = QRectF( outerBoundsPixels.left() * uPP, outerBoundsPixels.top() * uPP, outerBoundsPixels.width() * uPP, outerBoundsPixels.height() * uPP );
2124 if ( useScaleVisibility )
2137 maxScale = 1 / std::fabs( maxScale );
2157 minScale = 1 / std::fabs( minScale );
2172 labelIsHidden =
false;
2173 QgsTextFormat evaluatedFormat = mFormat;
2175 QFont labelFont = evaluatedFormat.
font();
2183 QString units = exprVal.toString();
2184 if ( !units.isEmpty() )
2194 double fontSize = evaluatedFormat.
size();
2200 if ( fontSize <= 0.0 )
2202 labelIsHidden =
true;
2203 return evaluatedFormat;
2208 if ( fontPixelSize < 1 )
2210 labelIsHidden =
true;
2211 return evaluatedFormat;
2213 labelFont.setPixelSize( fontPixelSize );
2225 if ( fontMinPixel > labelFont.pixelSize() || labelFont.pixelSize() > fontMaxPixel )
2227 labelIsHidden =
true;
2228 return evaluatedFormat;
2244 labelFont.setCapitalization( QFont::MixedCase );
2254 QString fcase = exprVal.toString().trimmed();
2257 if ( !fcase.isEmpty() )
2259 if ( fcase.compare(
"NoChange"_L1, Qt::CaseInsensitive ) == 0 )
2263 else if ( fcase.compare(
"Upper"_L1, Qt::CaseInsensitive ) == 0 )
2267 else if ( fcase.compare(
"Lower"_L1, Qt::CaseInsensitive ) == 0 )
2271 else if ( fcase.compare(
"Capitalize"_L1, Qt::CaseInsensitive ) == 0 )
2275 else if ( fcase.compare(
"Title"_L1, Qt::CaseInsensitive ) == 0 )
2279 else if ( fcase.compare(
"SmallCaps"_L1, Qt::CaseInsensitive ) == 0 )
2283 else if ( fcase.compare(
"AllSmallCaps"_L1, Qt::CaseInsensitive ) == 0 )
2291 parseTextStyle( labelFont, fontunits, context );
2292 if ( mDataDefinedProperties.hasActiveProperties() )
2294 parseTextFormatting( context );
2295 parseTextBuffer( context );
2296 parseTextMask( context );
2297 parseShapeBackground( context );
2298 parseDropShadow( context );
2303 QList<QgsTextFormat::Tab> tabPositions;
2307 for (
const QVariant &part : parts )
2309 tabPositions.append( QgsTextFormat::Tab( part.toDouble() ) );
2316 for (
const QString &part : parts )
2318 tabPositions.append( QgsTextFormat::Tab( part.toDouble() ) );
2329 evaluatedFormat.
setFont( labelFont );
2333 evaluatedFormat.
setSize( labelFont.pixelSize() / symbologyReferenceScaleFactor );
2336 return evaluatedFormat;
2386 if ( evalFormatNumbers )
2390 if ( decimalPlaces <= 0 )
2396 QVariant textV( labelText );
2398 double d = textV.toDouble( &ok );
2401 QString numberFormat;
2402 if ( d > 0 && signPlus )
2404 numberFormat.append(
'+' );
2406 numberFormat.append(
"%1" );
2407 labelText = numberFormat.arg( QLocale().toString( d,
'f', decimalPlaces ) );
2424 if ( wrapchr.isEmpty() )
2429 if ( allowMultipleLines )
2439 QgsGeometry geom = feature.
geometry();
2446 bool allowSimplify =
true;
2456 allowSimplify =
false;
2477 std::unique_ptr<QgsGeometry> scopedClonedGeom;
2482 QgsMapToPixelSimplifier simplifier( simplifyHints, simplifyMethod.
tolerance(), simplifyAlgorithm );
2483 geom = simplifier.
simplify( geom );
2495 bool isObstacle = mObstacleSettings.isObstacle();
2499 std::vector<std::unique_ptr<QgsLabelFeature> > res;
2508 std::unique_ptr< QgsLabelFeature > obstacle = registerObstacleFeature( f, context, obstacleGeometry );
2510 res.emplace_back( std::move( obstacle ) );
2519 if ( !isLabelVisible( context ) )
2526 if ( mGeometryGeneratorExpression.hasEvalError() )
2529 if ( obstacleGeometry.
isNull() )
2542 dataDefinedValues.clear();
2545 bool labelIsHidden =
false;
2546 QgsTextFormat evaluatedFormat = evaluateTextFormat( context, labelIsHidden );
2547 if ( labelIsHidden )
2563 bool allowMultipleLines =
true;
2574 allowMultipleLines =
false;
2579 allowMultipleLines =
true;
2596 if ( !evaluateLabelContent( feature, context, allowMultipleLines, labelText, doc, evaluatedFormat ) )
2618 QString str = exprVal.toString().trimmed();
2621 if ( !str.isEmpty() )
2623 if ( str.compare(
"Visible"_L1, Qt::CaseInsensitive ) == 0 )
2625 wholeCentroid =
false;
2627 else if ( str.compare(
"Whole"_L1, Qt::CaseInsensitive ) == 0 )
2629 wholeCentroid =
true;
2640 bool doClip =
false;
2641 if ( !centroidPoly || !wholeCentroid )
2659 std::unique_ptr< QgsTextLabelFeature > label
2660 = generateLabelFeature( context, feature, 0, geom, obstacleGeometry, doc, labelText, evaluatedFormat, details.
symbol(),
lineSettings,
pointSettings,
placementSettings, isObstacle, doClip );
2662 res.emplace_back( std::move( label ) );
2670 const std::size_t partCount = std::min( geometryParts.size(), documentParts.size() );
2671 res.reserve( partCount );
2672 for ( std::size_t i = 0; i < partCount; ++i )
2674 std::unique_ptr< QgsTextLabelFeature > label
2675 = generateLabelFeature( context, feature,
static_cast< int >( i ), geometryParts[i], obstacleGeometry, documentParts[i], labelText, evaluatedFormat, details.
symbol(),
lineSettings,
pointSettings,
placementSettings, isObstacle, doClip );
2677 res.emplace_back( std::move( label ) );
2687std::unique_ptr< QgsTextLabelFeature> QgsPalLayerSettings::generateLabelFeature(
2694 const QString &labelText,
2710 QFontMetricsF labelFontMetrics( evaluatedFormat.
font() );
2711 calculateLabelMetrics( labelFontMetrics, context, evaluatedFormat, doc, documentMetrics, labelSize, rotatedSize, outerBounds );
2715 double maxcharanglein = 20.0;
2716 double maxcharangleout = -20.0;
2734 maxcharanglein = std::clamp(
static_cast< double >( maxcharanglePt.x() ), 20.0, 60.0 );
2735 maxcharangleout = std::clamp(
static_cast< double >( maxcharanglePt.y() ), 20.0, 95.0 );
2739 maxcharangleout = -( std::fabs( maxcharangleout ) );
2766 if ( dataDefinedOutside.userType() == QMetaType::Type::QString )
2768 const QString value = dataDefinedOutside.toString().trimmed();
2769 if ( value.compare(
"force"_L1, Qt::CaseInsensitive ) == 0 )
2775 else if ( value.compare(
"yes"_L1, Qt::CaseInsensitive ) == 0 )
2780 else if ( value.compare(
"no"_L1, Qt::CaseInsensitive ) == 0 )
2788 if ( dataDefinedOutside.toBool() )
2834 QgsGeometry permissibleZone;
2837 permissibleZone = geom;
2861 QgsLabelThinningSettings featureThinningSettings = mThinningSettings;
2864 double minimumSize = 0.0;
2874 if ( !checkMinimumSizeMM( context, geom, featureThinningSettings.
minimumFeatureSize() ) )
2879 if ( !geos_geom_clone )
2908 bool layerDefinedRotation =
false;
2909 bool dataDefinedRotation =
false;
2910 double xPos = 0.0, yPos = 0.0;
2911 double angleInRadians = 0.0;
2912 double quadOffsetX = 0.0, quadOffsetY = 0.0;
2913 double offsetX = 0.0, offsetY = 0.0;
2914 QgsPointXY anchorPosition;
2925 bool ddFixedQuad =
false;
2934 int quadInt = exprVal.toInt( &ok );
2935 if ( ok && 0 <= quadInt && quadInt <= 8 )
3005 QString units = exprVal.toString().trimmed();
3006 if ( !units.isEmpty() )
3012 offUnit = decodedUnits;
3027 layerDefinedRotation =
true;
3028 angleInRadians = ( 360 -
angleOffset ) * M_PI / 180;
3031 const QgsMapToPixel &m2p = context.
mapToPixel();
3040 const double rotation = exprVal.toDouble( &ok );
3043 dataDefinedRotation =
true;
3050 angleInRadians = ( 360 - rotationDegrees ) * M_PI / 180.0;
3055 bool hasDataDefinedPosition =
false;
3057 bool ddPosition =
false;
3067 bool ddXPos =
false, ddYPos =
false;
3068 xPos = xPosProperty.toDouble( &ddXPos );
3069 yPos = yPosProperty.toDouble( &ddYPos );
3070 if ( ddXPos && ddYPos )
3071 hasDataDefinedPosition =
true;
3082 if ( pointPosProperty.userType() == qMetaTypeId<QgsReferencedGeometry>() )
3084 QgsReferencedGeometry referencedGeometryPoint = pointPosProperty.value<QgsReferencedGeometry>();
3085 point = QgsPoint( referencedGeometryPoint.
asPoint() );
3087 if ( !referencedGeometryPoint.
isNull() &&
ct.sourceCrs() != referencedGeometryPoint.
crs() )
3089 QObject::tr(
"Label position geometry is not in layer coordinates reference system. Layer CRS: '%1', Geometry CRS: '%2'" )
3091 QObject::tr(
"Labeling" ),
3095 else if ( pointPosProperty.userType() == qMetaTypeId< QgsGeometry>() )
3097 point = QgsPoint( pointPosProperty.value<QgsGeometry>().asPoint() );
3102 hasDataDefinedPosition =
true;
3113 if ( hasDataDefinedPosition )
3116 if ( layerDefinedRotation && !dataDefinedRotation )
3118 angleInRadians = 0.0;
3127 QString haliString = exprVal.toString();
3128 if ( haliString.compare(
"Center"_L1, Qt::CaseInsensitive ) == 0 )
3130 xdiff -= labelSize.width() / 2.0;
3132 else if ( haliString.compare(
"Right"_L1, Qt::CaseInsensitive ) == 0 )
3134 xdiff -= labelSize.width();
3145 QString valiString = exprVal.toString();
3146 if ( valiString.compare(
"Bottom"_L1, Qt::CaseInsensitive ) != 0 )
3148 if ( valiString.compare(
"Top"_L1, Qt::CaseInsensitive ) == 0 )
3150 ydiff -= labelSize.height();
3154 double descentRatio = labelFontMetrics.descent() / labelFontMetrics.height();
3155 if ( valiString.compare(
"Base"_L1, Qt::CaseInsensitive ) == 0 )
3157 ydiff -= labelSize.height() * descentRatio;
3161 double capHeightRatio = ( labelFontMetrics.boundingRect(
'H' ).height() + 1 + labelFontMetrics.descent() ) / labelFontMetrics.height();
3162 ydiff -= labelSize.height() * capHeightRatio;
3163 if ( valiString.compare(
"Half"_L1, Qt::CaseInsensitive ) == 0 )
3165 ydiff += labelSize.height() * ( capHeightRatio - descentRatio ) / 2.0;
3173 if ( dataDefinedRotation )
3176 double xd = xdiff * std::cos( angleInRadians ) - ydiff * std::sin( angleInRadians );
3177 double yd = xdiff * std::sin( angleInRadians ) + ydiff * std::cos( angleInRadians );
3183 QgsGeometry ddPoint(
new QgsPoint( xPos, yPos ) );
3191 anchorPosition = QgsPointXY( xPos, yPos );
3195 QgsMessageLog::logMessage( QObject::tr(
"Invalid data defined label position (%1, %2)" ).arg( xPos ).arg( yPos ), QObject::tr(
"Labeling" ) );
3196 hasDataDefinedPosition =
false;
3201 anchorPosition = QgsPointXY( xPos, yPos );
3209 anchorPosition = QgsPointXY( xPos, yPos );
3215 bool alwaysShow =
false;
3237 QString units = exprVal.toString().trimmed();
3238 if ( !units.isEmpty() )
3244 repeatUnits = decodedUnits;
3259 double overrunDistanceEval =
lineSettings.overrunDistance();
3271 double maximumDistanceEval =
pointSettings.maximumDistance();
3278 auto labelFeature = std::make_unique< QgsTextLabelFeature>( feature.
id(), std::move( geos_geom_clone ), labelSize, subPartId );
3279 labelFeature->setAnchorPosition( anchorPosition );
3280 labelFeature->setFeature( feature );
3281 labelFeature->setSymbol( symbol );
3282 labelFeature->setDocument( doc, documentMetrics );
3284 labelFeature->setRotatedSize( rotatedSize );
3287 labelFeature->setHasFixedPosition( hasDataDefinedPosition );
3288 labelFeature->setFixedPosition( QgsPointXY( xPos, yPos ) );
3290 labelFeature->setHasFixedAngle( dataDefinedRotation || ( !hasDataDefinedPosition && !
qgsDoubleNear( angleInRadians, 0.0 ) ) );
3291 labelFeature->setFixedAngle( angleInRadians );
3292 labelFeature->setQuadOffset( QPointF( quadOffsetX, quadOffsetY ) );
3293 labelFeature->setPositionOffset( QgsPointXY( offsetX, offsetY ) );
3295 labelFeature->setAlwaysShow( alwaysShow );
3296 labelFeature->setRepeatDistance( repeatDist );
3297 labelFeature->setLabelText( labelText );
3298 labelFeature->setPermissibleZone( permissibleZone );
3299 labelFeature->setOverrunDistance( overrunDistanceEval );
3300 labelFeature->setOverrunSmoothDistance( overrunSmoothDist );
3301 labelFeature->setMaximumDistance( maximumDistanceEval );
3302 labelFeature->setLineAnchorPercent(
lineSettings.lineAnchorPercent() );
3303 labelFeature->setLineAnchorType(
lineSettings.anchorType() );
3304 labelFeature->setLineAnchorTextPoint(
lineSettings.anchorTextPoint() );
3305 labelFeature->setCurvedLabelMode(
lineSettings.curvedLabelMode() );
3308 labelFeature->setMinimumSize( minimumSize );
3309 labelFeature->setWhitespaceCollisionHandling(
placementSettings.whitespaceCollisionHandling() );
3316 if ( outerBounds.left() != 0 || outerBounds.top() != 0 || !
qgsDoubleNear( outerBounds.width(), labelSize.width() ) || !
qgsDoubleNear( outerBounds.height(), labelSize.height() ) )
3318 labelFeature->setOuterBounds( outerBounds );
3321 QgsLabelFeatureThinningSettings thinning;
3334 ( *labelFeature ).setThinningSettings( thinning );
3338 double topMargin = std::max( 0.25 * labelFontMetrics.ascent(), 0.0 );
3339 double bottomMargin = 1.0 + labelFontMetrics.descent();
3340 QgsMargins vm( 0.0, topMargin, 0.0, bottomMargin );
3341 vm *=
xform->mapUnitsPerPixel();
3342 labelFeature->setVisualMargin( vm );
3345 QgsDebugMsgLevel( u
"PAL font stored definedFont: %1, Style: %2"_s.arg( evaluatedFormat.
font().toString(), evaluatedFormat.
font().styleName() ), 4 );
3346 labelFeature->setDefinedFont( evaluatedFormat.
font() );
3348 labelFeature->setMaximumCharacterAngleInside( std::clamp( maxcharanglein, 20.0, 60.0 ) * M_PI / 180 );
3349 labelFeature->setMaximumCharacterAngleOutside( std::clamp( maxcharangleout, -95.0, -20.0 ) * M_PI / 180 );
3364 labelFeature->setTextMetrics(
3365 QgsTextLabelFeature::
3366 calculateTextMetrics(
xform, context, evaluatedFormat, evaluatedFormat.
font(), labelFontMetrics, evaluatedFormat.
font().letterSpacing(), evaluatedFormat.
font().wordSpacing(), doc, documentMetrics )
3376 double distance =
dist;
3390 QString units = exprVal.toString().trimmed();
3392 if ( !units.isEmpty() )
3398 distUnit = decodedUnits;
3412 distance = ( distance < 0 ? -1 : 1 ) * std::max( std::fabs( distance ), 1.0 );
3424 distance = std::max( distance, 2.0 );
3429 distance = std::max( distance, 2.0 );
3436 labelFeature->setDistLabel( d );
3441 labelFeature->setHasFixedQuadrant(
true );
3444 labelFeature->setArrangementFlags(
lineSettings.placementFlags() );
3446 labelFeature->setPolygonPlacementFlags( polygonPlacement );
3455 labelFeature->setZIndex( z );
3465 double priorityD = exprVal.toDouble( &ok );
3468 priorityD = std::clamp( priorityD, 0.0, 10.0 );
3469 priorityD = 1 - priorityD / 10.0;
3470 labelFeature->setPriority( priorityD );
3475 labelFeature->setAllowDegradedPlacement(
placementSettings.allowDegradedPlacement() );
3479 QgsLabelObstacleSettings os = mObstacleSettings;
3483 labelFeature->setObstacleSettings( os );
3485 QVector< Qgis::LabelPredefinedPointPosition > positionOrder =
pointSettings.predefinedPositionOrder();
3486 if ( positionOrder.isEmpty() )
3487 positionOrder = *DEFAULT_PLACEMENT_ORDER();
3493 if ( !dataDefinedOrder.isEmpty() )
3498 labelFeature->setPredefinedPositionOrder( positionOrder );
3501 labelFeature->setDataDefinedValues( dataDefinedValues );
3503 return labelFeature;
3511 if ( !obstacleGeometry.
isNull() )
3513 geom = obstacleGeometry;
3528 if ( ls->numPoints() < 2 )
3534 std::unique_ptr<QgsGeometry> scopedClonedGeom;
3539 QgsMapToPixelSimplifier simplifier( simplifyHints, simplifyMethod.
tolerance(), simplifyAlgorithm );
3540 geom = simplifier.
simplify( geom );
3544 std::unique_ptr<QgsGeometry> scopedPreparedGeom;
3552 if ( !geos_geom_clone )
3556 auto obstacleFeature = std::make_unique< QgsLabelFeature >( f.
id(), std::move( geos_geom_clone ), QSizeF( 0, 0 ) );
3557 obstacleFeature->setFeature( f );
3559 QgsLabelObstacleSettings os = mObstacleSettings;
3562 obstacleFeature->setObstacleSettings( os );
3565 return obstacleFeature;
3570 if ( !mDataDefinedProperties.isActive( p ) )
3574 exprVal = mDataDefinedProperties.value( p, context );
3581 bool bol = exprVal.toBool();
3582 dataDefinedValues.insert( p, QVariant( bol ) );
3588 int size = exprVal.toInt( &ok );
3592 dataDefinedValues.insert( p, QVariant( size ) );
3600 int size = exprVal.toInt( &ok );
3602 if ( ok && size > 0 )
3604 dataDefinedValues.insert( p, QVariant( size ) );
3612 double size = exprVal.toDouble( &ok );
3616 dataDefinedValues.insert( p, QVariant( size ) );
3624 double size = exprVal.toDouble( &ok );
3626 if ( ok && size > 0.0 )
3628 dataDefinedValues.insert( p, QVariant( size ) );
3636 double rot = exprVal.toDouble( &ok );
3639 if ( rot < -180.0 && rot >= -360 )
3643 if ( rot > 180.0 && rot <= 360 )
3647 if ( rot >= -180 && rot <= 180 )
3649 dataDefinedValues.insert( p, QVariant( rot ) );
3658 int size = exprVal.toInt( &ok );
3659 if ( ok && size >= 0 && size <= 100 )
3661 dataDefinedValues.insert( p, QVariant( size ) );
3668 QString str = exprVal.toString();
3670 dataDefinedValues.insert( p, QVariant( str ) );
3675 QString unitstr = exprVal.toString().trimmed();
3677 if ( !unitstr.isEmpty() )
3686 QString colorstr = exprVal.toString().trimmed();
3689 if ( color.isValid() )
3691 dataDefinedValues.insert( p, QVariant( color ) );
3698 QString joinstr = exprVal.toString().trimmed();
3700 if ( !joinstr.isEmpty() )
3709 QString blendstr = exprVal.toString().trimmed();
3711 if ( !blendstr.isEmpty() )
3724 dataDefinedValues.insert( p, res );
3735 dataDefinedValues.insert( p, res );
3756 QString ddFontFamily;
3763 QString family = exprVal.toString().trimmed();
3767 if ( labelFont.family() != family )
3773 ddFontFamily = family;
3780 QString ddFontStyle;
3786 QString fontstyle = exprVal.toString().trimmed();
3788 ddFontStyle = fontstyle;
3793 bool ddBold =
false;
3801 bool ddItalic =
false;
3811 QFont appFont = QApplication::font();
3812 bool newFontBuilt =
false;
3813 if ( ddBold || ddItalic )
3817 newFontBuilt =
true;
3818 newFont.setBold( ddBold );
3819 newFont.setItalic( ddItalic );
3821 else if ( !ddFontStyle.isEmpty() && ddFontStyle.compare(
"Ignore"_L1, Qt::CaseInsensitive ) != 0 )
3823 if ( !ddFontFamily.isEmpty() )
3827 mFontDB = std::make_unique< QFontDatabase >();
3829 QFont styledfont = mFontDB->font( ddFontFamily, ddFontStyle, appFont.pointSize() );
3830 if ( appFont != styledfont )
3832 newFont = styledfont;
3833 newFontBuilt =
true;
3840 else if ( !ddFontFamily.isEmpty() )
3842 if ( ddFontStyle.compare(
"Ignore"_L1, Qt::CaseInsensitive ) != 0 )
3846 mFontDB = std::make_unique< QFontDatabase >();
3847 QFont styledfont = mFontDB->font( ddFontFamily, mFormat.namedStyle(), appFont.pointSize() );
3848 if ( appFont != styledfont )
3850 newFont = styledfont;
3851 newFontBuilt =
true;
3857 newFontBuilt =
true;
3865 newFont.setPixelSize( labelFont.pixelSize() );
3866 newFont.setUnderline( labelFont.underline() );
3867 newFont.setStrikeOut( labelFont.strikeOut() );
3868 newFont.setWordSpacing( labelFont.wordSpacing() );
3869 newFont.setLetterSpacing( QFont::AbsoluteSpacing, labelFont.letterSpacing() );
3871 labelFont = newFont;
3875 double wordspace = labelFont.wordSpacing();
3881 labelFont.setWordSpacing( context.
convertToPainterUnits( wordspace, fontunits, mFormat.sizeMapUnitScale() ) );
3884 double letterspace = labelFont.letterSpacing();
3890 labelFont.setLetterSpacing( QFont::AbsoluteSpacing, context.
convertToPainterUnits( letterspace, fontunits, mFormat.sizeMapUnitScale() ) );
3897 labelFont.setStrikeOut( strikeout );
3912 labelFont.setUnderline( underline );
3931 QgsTextBufferSettings buffer = mFormat.buffer();
3934 bool drawBuffer = mFormat.buffer().enabled();
3937 drawBuffer = exprVal.toBool();
3950 double bufrSize = buffer.
size();
3953 bufrSize = exprVal.toDouble();
3957 double bufferOpacity = buffer.
opacity() * 100;
3960 bufferOpacity = exprVal.toDouble();
3963 drawBuffer = ( drawBuffer && bufrSize > 0.0 && bufferOpacity > 0 );
3990 QgsTextMaskSettings mask = mFormat.mask();
3993 bool maskEnabled = mask.
enabled();
3996 maskEnabled = exprVal.toBool();
4005 double bufrSize = mask.
size();
4008 bufrSize = exprVal.toDouble();
4012 double opacity = mask.
opacity() * 100;
4015 opacity = exprVal.toDouble();
4018 maskEnabled = ( maskEnabled && bufrSize > 0.0 && opacity > 0 );
4043 wrapchr = exprVal.toString();
4049 evalAutoWrapLength = exprVal.toInt();
4070 QString str = exprVal.toString().trimmed();
4073 if ( !str.isEmpty() )
4078 if ( str.compare(
"Center"_L1, Qt::CaseInsensitive ) == 0 )
4082 else if ( str.compare(
"Right"_L1, Qt::CaseInsensitive ) == 0 )
4086 else if ( str.compare(
"Follow"_L1, Qt::CaseInsensitive ) == 0 )
4090 else if ( str.compare(
"Justify"_L1, Qt::CaseInsensitive ) == 0 )
4107 QString str = exprVal.toString().trimmed();
4108 if ( !str.isEmpty() )
4114 bool drawDirSymb = mLineSettings.addDirectionSymbol();
4117 drawDirSymb = exprVal.toBool();
4132 QString str = exprVal.toString().trimmed();
4135 if ( !str.isEmpty() )
4140 if ( str.compare(
"Above"_L1, Qt::CaseInsensitive ) == 0 )
4144 else if ( str.compare(
"Below"_L1, Qt::CaseInsensitive ) == 0 )
4163 QgsTextBackgroundSettings background = mFormat.background();
4166 bool drawShape = background.
enabled();
4169 drawShape = exprVal.toBool();
4178 double shapeOpacity = background.
opacity() * 100;
4181 shapeOpacity = 100.0 * exprVal.toDouble();
4184 drawShape = ( drawShape && shapeOpacity > 0 );
4200 QString skind = exprVal.toString().trimmed();
4203 if ( !skind.isEmpty() )
4212 QString svgPath = background.
svgFile();
4219 QString svgfile = exprVal.toString().trimmed();
4235 QString stype = exprVal.toString().trimmed();
4238 if ( !stype.isEmpty() )
4247 double ddShpSizeX = background.
size().width();
4250 ddShpSizeX = exprVal.toDouble();
4254 double ddShpSizeY = background.
size().height();
4257 ddShpSizeY = exprVal.toDouble();
4274 && ( ddShpSizeX == 0.0 || ddShpSizeY == 0.0 ) )
4299 QString rotstr = exprVal.toString().trimmed();
4302 if ( !rotstr.isEmpty() )
4349 QgsTextShadowSettings shadow = mFormat.shadow();
4352 bool drawShadow = shadow.
enabled();
4355 drawShadow = exprVal.toBool();
4364 double shadowOpacity = shadow.
opacity() * 100;
4367 shadowOpacity = exprVal.toDouble();
4374 shadowOffDist = exprVal.toDouble();
4381 shadowRad = exprVal.toDouble();
4384 drawShadow = ( drawShadow && shadowOpacity > 0 && !( shadowOffDist == 0.0 && shadowRad == 0.0 ) );
4401 QString str = exprVal.toString().trimmed();
4404 if ( !str.isEmpty() )
4439 switch ( layer->
type() )
4443 const QgsVectorLayer *vl = qobject_cast< const QgsVectorLayer * >( layer );
4456 return !labeling->styles().empty();
4463 const QgsMeshLayer *ml = qobject_cast< const QgsMeshLayer * >( layer );
4469 const QgsRasterLayer *rl = qobject_cast< const QgsRasterLayer * >( layer );
4516QStringList
QgsPalLabeling::splitToLines(
const QString &text,
const QString &wrapCharacter,
const int autoWrapLength,
const bool useMaxLineLengthWhenAutoWrapping )
4518 QStringList multiLineSplit;
4519 if ( !wrapCharacter.isEmpty() && wrapCharacter !=
"\n"_L1 )
4522 const QStringList lines = text.split( wrapCharacter );
4523 for (
const QString &line : lines )
4525 multiLineSplit.append( line.split(
'\n' ) );
4530 multiLineSplit = text.split(
'\n' );
4534 if ( autoWrapLength != 0 )
4536 QStringList autoWrappedLines;
4537 autoWrappedLines.reserve( multiLineSplit.count() );
4538 for (
const QString &line : std::as_const( multiLineSplit ) )
4540 autoWrappedLines.append(
QgsStringUtils::wordWrap( line, autoWrapLength, useMaxLineLengthWhenAutoWrapping ).split(
'\n' ) );
4542 multiLineSplit = autoWrappedLines;
4544 return multiLineSplit;
4549 QStringList graphemes;
4550 QTextBoundaryFinder boundaryFinder( QTextBoundaryFinder::Grapheme, text );
4551 int currentBoundary = -1;
4552 int previousBoundary = 0;
4553 while ( ( currentBoundary = boundaryFinder.toNextBoundary() ) > 0 )
4555 graphemes << text.mid( previousBoundary, currentBoundary - previousBoundary );
4556 previousBoundary = currentBoundary;
4586 QgsDebugMsgLevel( u
"Ignoring feature due to transformation exception"_s, 4 );
4590 geom.
filterVertices( [](
const QgsPoint &point ) ->
bool {
return std::isfinite( point.
x() ) && std::isfinite( point.
y() ); } );
4593 cp->removeInvalidRings();
4597 for (
int i = 0; i < ms->numGeometries(); ++i )
4600 cp->removeInvalidRings();
4620 bool mustClipExact =
false;
4644 QVector< QgsGeometry> parts;
4653 parts.append( partGeom );
4660 if ( bufferGeom.
isNull() )
4669 if ( mustClipExact )
4704 double length = geom.
length();
4705 if ( length >= 0.0 )
4707 return ( length >= ( minSize * mapUnitsPerMM ) );
4712 double area = geom.
area();
4715 return ( std::sqrt( area ) >= ( minSize * mapUnitsPerMM ) );
4722void QgsPalLabeling::dataDefinedTextStyle(
QgsPalLayerSettings &tmpLyr,
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4724 QgsTextFormat format = tmpLyr.
format();
4725 bool changed =
false;
4731 format.
setColor( ddColor.value<QColor>() );
4755void QgsPalLabeling::dataDefinedTextFormatting(
QgsPalLayerSettings &tmpLyr,
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4769 QgsTextFormat format = tmpLyr.
format();
4776 QgsTextFormat format = tmpLyr.
format();
4777 QList<QgsTextFormat::Tab> tabPositions;
4781 for (
const QVariant &part : parts )
4783 tabPositions.append( QgsTextFormat::Tab( part.toDouble() ) );
4790 for (
const QString &part : parts )
4792 tabPositions.append( QgsTextFormat::Tab( part.toDouble() ) );
4811 QgsTextFormat format = tmpLyr.
format();
4844void QgsPalLabeling::dataDefinedTextBuffer(
QgsPalLayerSettings &tmpLyr,
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4846 QgsTextBufferSettings buffer = tmpLyr.
format().
buffer();
4847 bool changed =
false;
4860 QgsTextFormat format = tmpLyr.
format();
4895 buffer.
setColor( ddColor.value<QColor>() );
4915 QgsTextFormat format = tmpLyr.
format();
4921void QgsPalLabeling::dataDefinedTextMask(
QgsPalLayerSettings &tmpLyr,
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4923 if ( ddValues.isEmpty() )
4926 QgsTextMaskSettings mask = tmpLyr.
format().
mask();
4927 bool changed =
false;
4940 QgsTextFormat format = tmpLyr.
format();
4980 QgsTextFormat format = tmpLyr.
format();
4986void QgsPalLabeling::dataDefinedShapeBackground(
QgsPalLayerSettings &tmpLyr,
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4989 bool changed =
false;
5002 QgsTextFormat format = tmpLyr.
format();
5029 QSizeF size = background.
size();
5036 QSizeF size = background.
size();
5130 QgsTextFormat format = tmpLyr.
format();
5136void QgsPalLabeling::dataDefinedDropShadow(
QgsPalLayerSettings &tmpLyr,
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
5138 QgsTextShadowSettings shadow = tmpLyr.
format().
shadow();
5139 bool changed =
false;
5152 QgsTextFormat format = tmpLyr.
format();
5198 shadow.
setColor( ddColor.value<QColor>() );
5223 QgsTextFormat format = tmpLyr.
format();
5233 QMimeData *mimeData =
new QMimeData;
5234 mimeData->setColorData( QVariant(
format().color() ) );
5237 QDomDocument textDoc;
5238 QDomElement textElem =
writeXml( textDoc, rwContext );
5239 textDoc.appendChild( textElem );
5240 mimeData->setData(
"application/qgis.labelsettings"_L1, textDoc.toString().toUtf8() );
5250 if ( !data || !data->hasFormat(
"application/qgis.labelsettings"_L1 ) )
5253 QString text = QString::fromUtf8( data->data(
"application/qgis.labelsettings"_L1 ) );
5254 if ( !text.isEmpty() )
5260 if ( doc.setContent( text ) )
5262 elem = doc.documentElement();
5264 settings.
readXml( elem, rwContext );
@ PreferVector
Prefer vector-based rendering, when the result will still be visually near-identical to a raster-base...
@ StretchCharacterSpacingToFitLine
Increases (or decreases) the character spacing used for each label in order to fit the entire text ov...
@ Default
Default curved placement, characters are placed in an optimal position along the line....
@ StretchWordSpacingToFitLine
Increases (or decreases) the word spacing used for each label in order to fit the entire text over th...
@ PlaceCharactersAtVertices
Each individual character from the label text is placed such that their left-baseline position is loc...
@ LabelLargestPartOnly
Place a label only on the largest part from the geometry.
@ SplitLabelTextLinesOverParts
Splits the label text over the parts of the geometry, such that each consecutive part is labeled with...
@ LabelEveryPartWithEntireLabel
Place the (same) entire label over every part from the geometry.
QFlags< VectorRenderingSimplificationFlag > VectorRenderingSimplificationFlags
Simplification flags for vector feature rendering.
@ Success
Operation succeeded.
AngleUnit
Units of angles.
@ NoSimplification
No simplification can be applied.
LabelOffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes.
@ FromPoint
Offset distance applies from point geometry.
@ FromSymbolBounds
Offset distance applies from rendered symbol bounds.
@ PreferCloser
Prefer closer labels, falling back to alternate positions before larger distances.
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature or along a line feature....
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only.
@ AllowPlacementInsideOfPolygon
Labels can be placed inside a polygon feature.
@ AllowPlacementOutsideOfPolygon
Labels can be placed outside of a polygon feature.
VectorSimplificationAlgorithm
Simplification algorithms for vector features.
@ CenterOfText
Anchor using center of text.
@ SkipEmptyInteriorRings
Skip any empty polygon interior ring.
@ Warning
Warning message.
QFlags< LabelLinePlacementFlag > LabelLinePlacementFlags
Line placement flags, which control how candidates are generated for a linear feature.
@ Labeling
Labeling-specific layout mode.
@ Rectangle
Text within rectangle layout mode.
Capitalization
String capitalization options.
@ AllSmallCaps
Force all characters to small caps.
@ MixedCase
Mixed case, ie no change.
@ AllLowercase
Convert all characters to lowercase.
@ TitleCase
Simple title case conversion - does not fully grammatically parse the text and uses simple rules only...
@ SmallCaps
Mixed case small caps.
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
@ AllUppercase
Convert all characters to uppercase.
QFlags< LabelPolygonPlacementFlag > LabelPolygonPlacementFlags
Polygon placement flags, which control how candidates are generated for a polygon feature.
LabelQuadrantPosition
Label quadrant positions.
TextOrientation
Text orientations.
@ Vertical
Vertically oriented text.
@ RotationBased
Horizontally or vertically oriented text based on rotation (only available for map labeling).
@ Horizontal
Horizontally oriented text.
UnplacedLabelVisibility
Unplaced label visibility.
@ FollowEngineSetting
Respect the label engine setting.
@ AffectsLabeling
If present, indicates that the renderer will participate in the map labeling problem.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
LabelMultiLineAlignment
Text alignment for multi-line labels.
@ FollowPlacement
Alignment follows placement of label, e.g., labels to the left of a feature will be drawn with right ...
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
@ TreatWhitespaceAsCollision
Treat overlapping whitespace text in labels and whitespace overlapping obstacles as collisions.
RenderUnit
Rendering size units.
@ Percentage
Percentage of another measurement (e.g., canvas size, feature size).
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes).
@ DrawLabelSelection
Whether vector selections should be change the rendering of associated labels.
@ Antialiasing
Use antialiasing while drawing.
@ Linework
Combines all rings into a set of noded lines and then extracts valid polygons from that linework.
@ AllowOverlapIfRequired
Avoids overlapping labels when possible, but permit overlaps if labels for features cannot otherwise ...
@ PreventOverlap
Do not allow labels to overlap other labels.
static const double UI_SCALE_FACTOR
UI scaling factor.
@ MiddleLeft
Label on left of point.
@ TopRight
Label on top-right of point.
@ MiddleRight
Label on right of point.
@ TopSlightlyRight
Label on top of point, slightly right of center.
@ BottomRight
Label on bottom right of point.
@ BottomLeft
Label on bottom-left of point.
@ BottomSlightlyRight
Label below point, slightly right of center.
@ TopLeft
Label on top-left of point.
UpsideDownLabelHandling
Handling techniques for upside down labels.
@ FlipUpsideDownLabels
Upside-down labels (90 <= angle < 270) are shown upright.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsFontManager * fontManager()
Returns the application font manager, which manages available fonts and font installation for the QGI...
static QgsCalloutRegistry * calloutRegistry()
Returns the application's callout registry, used for managing callout types.
Registry of available callout classes.
static QgsCallout * defaultCallout()
Create a new instance of a callout with default settings.
Contains additional contextual information about the context in which a callout is being rendered.
Abstract base class for callout renderers.
bool enabled() const
Returns true if the callout is enabled.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
Represents a coordinate reference system (CRS).
QString userFriendlyIdentifier(Qgis::CrsIdentifierType type=Qgis::CrsIdentifierType::MediumString) const
Returns a user friendly identifier for the CRS.
Custom exception class for Coordinate Reference System related exceptions.
Curve polygon geometry type.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
QString evalErrorString() const
Returns evaluation error.
QString parserErrorString() const
Returns parser error.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
QVariant evaluate()
Evaluate the feature and return the result.
virtual Qgis::FeatureRendererFlags flags() const
Returns flags associated with the renderer.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Container of fields for a vector layer.
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QString processFontFamilyName(const QString &name) const
Processes a font family name, applying any matching fontFamilyReplacements() to the name.
static QFont createFont(const QString &family, int pointSize=-1, int weight=-1, bool italic=false)
Creates a font with the specified family.
static bool fontFamilyOnSystem(const QString &family)
Check whether font family is on system in a quick manner, which does not compare [foundry].
static bool updateFontViaStyle(QFont &f, const QString &fontstyle, bool fallback=false)
Updates font with named style and retain all font properties.
Encapsulates parameters under which a geometry operation is performed.
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QgsGeometry intersection(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters(), QgsFeedback *feedback=nullptr) const
Returns a geometry representing the points shared by this geometry and other.
double length() const
Returns the planar, 2-dimensional length of geometry.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
QgsGeometry mergeLines(const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
QgsGeometry clipped(const QgsRectangle &rectangle, QgsFeedback *feedback=nullptr)
Clips the geometry using the specified rectangle.
bool isAxisParallelRectangle(double maximumDeviation, bool simpleRectanglesOnly=false) const
Returns true if the geometry is a polygon that is almost an axis-parallel rectangle.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QVector< QgsGeometry > asGeometryCollection() const
Returns contents of the geometry as a list of geometries.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool contains(const QgsPointXY *p) const
Returns true if the geometry contains the point p.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
void filterVertices(const std::function< bool(const QgsPoint &) > &filter)
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
bool isGeosValid(Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const
Checks validity of the geometry using GEOS.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
double area() const
Returns the planar, 2-dimensional area of the geometry.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QgsGeometry makeValid(Qgis::MakeValidMethod method=Qgis::MakeValidMethod::Linework, bool keepCollapsed=false, QgsFeedback *feedback=nullptr) const
Attempts to make an invalid geometry valid without losing vertices.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
bool convertGeometryCollectionToSubclass(Qgis::GeometryType geomType)
Converts geometry collection to a the desired geometry type subclass (multi-point,...
QgsGeometry simplify(double tolerance, QgsFeedback *feedback=nullptr) const
Returns a simplified version of this geometry using a specified tolerance value.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Qgis::GeometryOperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
Q_INVOKABLE QString asWkt(int precision=17) const
Exports the geometry to WKT.
static geos::unique_ptr asGeos(const QgsGeometry &geometry, double precision=0, Qgis::GeosCreationFlags flags=Qgis::GeosCreationFlags())
Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destr...
Encapsulates details for an individual feature to label.
QgsGeometry obstacleGeometry() const
Returns the (optional) obstacle geometry for the label.
bool isSelected() const
Returns true if the feature associated with the label is currently selected.
const QgsSymbol * symbol() const
Returns the (optional) symbol associated with the feature to label.
void setNoRepeatDistance(double distance)
Sets the minimum distance (in label units) between labels for this feature and other labels with the ...
void setLabelMarginDistance(double distance)
Sets the minimum distance (in label units) between labels for this feature and other labels.
Contains settings related to how the label engine places and formats labels for line features (or pol...
AnchorType
Line anchor types.
AnchorClipping
Clipping behavior for line anchor calculation.
@ UseEntireLine
Entire original feature line geometry is used when calculating the line anchor for labels.
@ UseVisiblePartsOfLine
Only visible parts of lines are considered when calculating the line anchor for labels.
void setDirectionSymbolPlacement(DirectionSymbolPlacement placement)
Sets the placement for direction symbols.
void setLeftDirectionSymbol(const QString &symbol)
Sets the string to use for left direction arrows.
DirectionSymbolPlacement
Placement options for direction symbols.
@ SymbolLeftRight
Place direction symbols on left/right of label.
@ SymbolAbove
Place direction symbols on above label.
@ SymbolBelow
Place direction symbols on below label.
void setRightDirectionSymbol(const QString &symbol)
Sets the string to use for right direction arrows.
bool addDirectionSymbol() const
Returns true if '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) w...
void setReverseDirectionSymbol(bool reversed)
Sets whether the direction symbols should be reversed.
void setAddDirectionSymbol(bool enabled)
Sets whether '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) will...
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels.
@ PolygonInterior
Avoid placing labels over interior of polygon (prefer placing labels totally outside or just slightly...
void setIsObstacle(bool isObstacle)
Sets whether features are obstacles to labels of other layers.
void updateDataDefinedProperties(const QgsPropertyCollection &properties, QgsExpressionContext &context)
Updates the obstacle settings to respect any data defined properties set within the specified propert...
void setObstacleGeometry(const QgsGeometry &obstacleGeom)
Sets the label's obstacle geometry, if different to the feature geometry.
Contains general settings related to how labels are placed.
Contains settings related to how the label engine places and formats labels for point-like features.
double minimumFeatureSize() const
Returns the minimum feature size (in millimeters) for a feature to be labelled.
const QgsMapUnitScale & minimumDistanceToDuplicateMapUnitScale() const
Returns the map unit scale for the minimum distance to labels with duplicate text.
int maximumNumberLabels() const
Returns the maximum number of labels which should be drawn for this layer.
bool allowDuplicateRemoval() const
Returns whether duplicate label removal is permitted for this layer.
const QgsMapUnitScale & labelMarginDistanceMapUnitScale() const
Returns the map unit scale for the minimum distance to other labels.
double labelMarginDistance() const
Returns the minimum distance to other labels (i.e.
Qgis::RenderUnit labelMarginDistanceUnit() const
Returns the units for the minimum distance to other labels.
void updateDataDefinedProperties(const QgsPropertyCollection &properties, QgsExpressionContext &context)
Updates the thinning settings to respect any data defined properties set within the specified propert...
double minimumDistanceToDuplicate() const
Returns the minimum distance to labels with duplicate text.
Qgis::RenderUnit minimumDistanceToDuplicateUnit() const
Returns the units for the minimum distance to labels with duplicate text.
bool limitNumberOfLabelsEnabled() const
Returns true if the number of labels drawn for the layer should be limited.
static constexpr double DEFAULT_MINIMUM_DISTANCE_TO_DUPLICATE
Default minimum distance to duplicate labels.
static QString encodePredefinedPositionOrder(const QVector< Qgis::LabelPredefinedPointPosition > &positions)
Encodes an ordered list of predefined point label positions to a string.
static QVector< Qgis::LabelPredefinedPointPosition > decodePredefinedPositionOrder(const QString &positionString)
Decodes a string to an ordered list of predefined point label positions.
Base class for all map layer types.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
T customEnumProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on an enum.
Contains configuration for rendering maps.
const QgsMapToPixel & mapToPixel() const
double extentBuffer() const
Returns the buffer in map units to use around the visible extent for rendering symbols whose correspo...
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
@ SimplifyEnvelope
The geometries can be fully simplified by its BoundingBox.
Perform transforms between map coordinates and device coordinates.
double mapUnitsPerPixel() const
Returns the current map units per pixel.
double mapRotation() const
Returns the current map rotation in degrees (clockwise).
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Sets parameters for use in transforming coordinates.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
const QgsAbstractMeshLayerLabeling * labeling() const
Access to const labeling configuration.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
Multi surface geometry collection.
static QStringList splitToLines(const QString &text, const QString &wrapCharacter, int autoWrapLength=0, bool useMaxLineLengthWhenAutoWrapping=true)
Splits a text string to a list of separate lines, using a specified wrap character (wrapCharacter).
static QgsGeometry prepareGeometry(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry(), bool mergeLines=false)
Prepares a geometry for registration with PAL.
static bool geometryRequiresPreparation(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry(), bool mergeLines=false)
Checks whether a geometry requires preparation before registration with PAL.
static bool staticWillUseLayer(const QgsMapLayer *layer)
Called to find out whether a specified layer is used for labeling.
static QStringList splitToGraphemes(const QString &text)
Splits a text string to a list of graphemes, which are the smallest allowable character divisions in ...
Contains settings for how a map layer will be labeled.
bool fitInPolygonOnly
true if only labels which completely fit within a polygon are allowed.
double yOffset
Vertical offset of label.
QgsMapUnitScale labelOffsetMapUnitScale
Map unit scale for label offset.
int fontMaxPixelSize
Maximum pixel size for showing rendered map unit labels (1 - 10000).
const QgsLabelPlacementSettings & placementSettings() const
Returns the label placement settings.
double maxCurvedCharAngleIn
Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
double zIndex
Z-Index of label, where labels with a higher z-index are rendered on top of labels with a lower z-ind...
const QgsMapToPixel * xform
void startRender(QgsRenderContext &context)
Prepares the label settings for rendering.
QString wrapChar
Wrapping character string.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
Qgis::LabelOffsetType offsetType
Offset type for layer (only applies in certain placement modes).
double xOffset
Horizontal offset of label.
Qgis::LabelPlacement placement
Label placement mode.
QgsCoordinateTransform ct
bool drawLabels
Whether to draw labels for this layer.
bool fontLimitPixelSize
true if label sizes should be limited by pixel size.
QString legendString() const
legendString
static QgsPalLayerSettings fromMimeData(const QMimeData *data, bool *ok=nullptr)
Attempts to parse the provided mime data as a QgsPalLayerSettings.
double minimumScale
The minimum map scale (i.e.
Q_DECL_DEPRECATED void calculateLabelSize(const QFontMetricsF *fm, const QString &text, double &labelX, double &labelY, const QgsFeature *f=nullptr, QgsRenderContext *context=nullptr, double *rotatedLabelX=nullptr, double *rotatedLabelY=nullptr)
Calculates the space required to render the provided text in map units.
void registerFeature(const QgsFeature &f, QgsRenderContext &context)
Registers a feature for labeling.
QgsPalLayerSettings & operator=(const QgsPalLayerSettings &s)
copy operator - only copies the permanent members
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
bool scaleVisibility
Set to true to limit label visibility to a range of scales.
double repeatDistance
Distance for repeating labels for a single feature.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the label's property collection, used for data defined overrides.
QgsExpression * getLabelExpression() const
Returns the QgsExpression for this label settings.
bool geometryGeneratorEnabled
Defines if the geometry generator is enabled or not. If disabled, the standard geometry will be taken...
QMimeData * toMimeData() const
Returns new mime data representing the labeling settings.
Qgis::LabelMultiLineAlignment multilineAlign
Horizontal alignment of multi-line labels.
bool centroidInside
true if centroid positioned labels must be placed inside their corresponding feature polygon,...
int priority
Label priority.
Qgis::GeometryType geometryGeneratorType
The type of the result geometry of the geometry generator.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
QgsCallout * callout() const
Returns the label callout renderer, responsible for drawing label callouts.
int fontMinPixelSize
Minimum pixel size for showing rendered map unit labels (1 - 1000).
double angleOffset
Label rotation, in degrees clockwise.
double maxCurvedCharAngleOut
Maximum angle between outside curved label characters (valid range -20.0 to -95.0).
Qgis::AngleUnit rotationUnit() const
Unit for rotation of labels.
Qgis::GeometryType layerType
Geometry type of layers associated with these settings.
Qgis::RenderUnit offsetUnits
Units for offsets of label.
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
bool preserveRotation
True if label rotation should be preserved during label pin/unpin operations.
bool plusSign
Whether '+' signs should be prepended to positive numeric labels.
bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames, const QgsFields &fields, const QgsMapSettings &mapSettings, const QgsCoordinateReferenceSystem &crs)
Prepare for registration of features.
QString geometryGenerator
The geometry generator expression. Null if disabled.
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
QgsMapUnitScale distMapUnitScale
Map unit scale for label feature distance.
QgsStringReplacementCollection substitutions
Substitution collection for automatic text substitution with labels.
Q_DECL_DEPRECATED QColor previewBkgrdColor
const QgsFeature * mCurFeat
int decimals
Number of decimal places to show for numeric labels.
double dist
Distance from feature to the label.
void setRotationUnit(Qgis::AngleUnit angleUnit)
Set unit for rotation of labels.
QgsMapUnitScale repeatDistanceMapUnitScale
Map unit scale for repeating labels for a single feature.
Qgis::RenderUnit distUnits
Units the distance from feature to the label.
bool centroidWhole
true if feature centroid should be calculated from the whole feature, or false if only the visible pa...
Property
Data definable properties.
@ PositionX
X-coordinate data defined label position.
@ LinePlacementOptions
Line placement flags.
@ MinScale
Min scale (deprecated, for old project compatibility only).
@ FontSizeUnit
Font size units.
@ WhitespaceCollisionHandling
Whitespace collision handling.
@ LabelRotation
Label rotation.
@ FontStyle
Font style name.
@ ShapeTransparency
Shape transparency (deprecated).
@ Italic
Use italic style.
@ ShapeOpacity
Shape opacity.
@ AllowDegradedPlacement
Allow degraded label placements.
@ MaskEnabled
Whether the mask is enabled.
@ PredefinedPositionOrder
@ OverlapHandling
Overlap handling technique.
@ PositionY
Y-coordinate data defined label position.
@ MaximumScale
Maximum map scale (ie most "zoomed in").
@ Vali
Vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top).
@ MinimumScale
Minimum map scale (ie most "zoomed out").
@ FontStretchFactor
Font stretch factor, since QGIS 3.24.
@ PolygonLabelOutside
Whether labels outside a polygon feature are permitted, or should be forced.
@ LineAnchorType
Line anchor type.
@ MaxScale
Max scale (deprecated, for old project compatibility only).
@ BufferOpacity
Buffer opacity.
@ BufferTransp
Buffer transparency (deprecated).
@ LineAnchorClipping
Clipping mode for line anchor calculation.
@ MaskJoinStyle
Mask join style.
@ Strikeout
Use strikeout.
@ LabelAllParts
Multipart geometry behavior.
@ LabelMarginDistance
Minimum distance from labels for this feature to other labels.
@ Underline
Use underline.
@ FontBlendMode
Text blend mode.
@ LineAnchorPercent
Portion along line at which labels should be anchored.
@ FontCase
Label text case.
@ Hali
Horizontal alignment for data defined label position (Left, Center, Right).
@ MaskOpacity
Mask opacity.
@ RemoveDuplicateLabelDistance
Minimum distance from labels for this feature to other labels with duplicate text.
@ LineAnchorTextPoint
Line anchor text point.
@ ShadowTransparency
Shadow transparency (deprecated).
@ OverrunDistance
Distance which labels can extend past either end of linear features.
@ MaskBufferUnit
Mask buffer size unit.
@ FontOpacity
Text opacity.
@ FontWordSpacing
Word spacing.
@ FontTransp
Text transparency (deprecated).
@ CalloutDraw
Show callout.
@ CurvedLabelMode
Mode which determine how curved labels are generated and placed.
@ MaskBufferSize
Mask buffer size.
@ FontLetterSpacing
Letter spacing.
@ TabStopDistance
Tab stop distance, since QGIS 3.38.
@ ShadowOpacity
Shadow opacity.
@ RemoveDuplicateLabels
Whether this feature can cause removal of duplicate labels.
@ PositionPoint
Point-coordinate data defined label position.
@ MaximumDistance
Maximum distance of label from feature.
@ Rotation
Label rotation (deprecated, for old project compatibility only).
Qgis::RenderUnit repeatDistanceUnit
Units for repeating labels for a single feature.
Qgis::UpsideDownLabelHandling upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
QString fieldName
Name of field (or an expression) to use for label text.
static QPixmap labelSettingsPreviewPixmap(const QgsPalLayerSettings &settings, QSize size, const QString &previewText=QString(), int padding=0, const QgsScreenProperties &screen=QgsScreenProperties())
Returns a pixmap preview for label settings.
bool formatNumbers
Set to true to format numeric label text as numbers (e.g.
bool containsAdvancedEffects() const
Returns true if any component of the label settings requires advanced effects such as blend modes,...
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc.
void setCallout(QgsCallout *callout)
Sets the label callout renderer, responsible for drawing label callouts.
double maximumScale
The maximum map scale (i.e.
int autoWrapLength
If non-zero, indicates that label text should be automatically wrapped to (ideally) the specified num...
Qgis::UnplacedLabelVisibility unplacedVisibility() const
Returns the layer's unplaced label visibility.
bool useMaxLineLengthForAutoWrap
If true, indicates that when auto wrapping label text the autoWrapLength length indicates the maximum...
void setUnplacedVisibility(Qgis::UnplacedLabelVisibility visibility)
Sets the layer's unplaced label visibility.
const QgsLabelPointSettings & pointSettings() const
Returns the label point settings, which contain settings related to how the label engine places and f...
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the labeling property definitions.
void stopRender(QgsRenderContext &context)
Finalises the label settings after use.
std::vector< std::unique_ptr< QgsLabelFeature > > registerFeatureWithDetails(const QgsFeature &feature, QgsRenderContext &context, const QgsLabelFeatureDetails &details)
Registers a feature for labeling.
bool useSubstitutions
True if substitutions should be applied.
Point geometry type, with support for z-dimension and m-values.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const final
Returns the calculated value of the property with the specified key from within the collection.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
@ Double
Double value (including negative values).
@ Double0To1
Double value between 0-1 (inclusive).
@ StrokeWidth
Line stroke width.
@ String
Any string value.
@ RenderUnits
Render units (eg mm/pixels/map units).
@ PenJoinStyle
Pen join style.
@ SvgPath
Path to an SVG file.
@ IntegerPositiveGreaterZero
Non-zero positive integer values.
@ IntegerPositive
Positive integer values (including 0).
@ Opacity
Opacity (0-100).
@ ColorNoAlpha
Color with no alpha channel.
@ Rotation
Rotation (value between 0-360 degrees).
@ ColorWithAlpha
Color with alpha channel.
@ DoublePositive
Positive double value (including 0).
@ Size2D
2D size (width/height different)
@ DataTypeString
Property requires a string value.
@ DataTypeNumeric
Property requires a numeric value.
A store for object properties.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
Represents a raster layer.
const QgsAbstractRasterLayerLabeling * labeling() const
Access to const labeling configuration.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Q_INVOKABLE QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be rounded to the spec...
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
void grow(double delta)
Grows the rectangle in place by the specified amount.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
Contains information about the context of a rendering operation.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
double convertToMapUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
QgsVectorSimplifyMethod & vectorSimplifyMethod()
Returns the simplification settings to use when rendering vector layers.
double symbologyReferenceScale() const
Returns the symbology reference scale.
void setDevicePixelRatio(float ratio)
Sets the device pixel ratio.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
double rendererScale() const
Returns the renderer map scale.
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsGeometry featureClipGeometry() const
Returns the geometry to use to clip features at render time.
bool testFlag(Qgis::RenderContextFlag flag) const
Check whether a particular flag is enabled.
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
void setRasterizedRenderingPolicy(Qgis::RasterizedRenderingPolicy policy)
Sets the policy controlling when rasterisation of content during renders is permitted.
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected).
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QColor selectionColor() const
Returns the color to use when rendering selected features.
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly during rendering to check if rendering shou...
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
static bool equalToOrGreaterThanMinimumScale(const double scale, const double minScale)
Returns whether the scale is equal to or greater than the minScale, taking non-round numbers into acc...
static bool lessThanMaximumScale(const double scale, const double maxScale)
Returns whether the scale is less than the maxScale, taking non-round numbers into account.
Stores properties relating to a screen.
double devicePixelRatio() const
Returns the ratio between physical pixels and device-independent pixels for the screen.
bool isValid() const
Returns true if the properties are valid.
void updateRenderContextForScreen(QgsRenderContext &context) const
Updates the settings in a render context to match the screen settings.
static QString capitalize(const QString &string, Qgis::Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
static QString wordWrap(const QString &string, int length, bool useMaxLineLength=true, const QString &customDelimiter=QString())
Automatically wraps a string by inserting new line characters at appropriate locations in the string.
QgsTextFormat defaultTextFormat(QgsStyle::TextFormatContext context=QgsStyle::TextFormatContext::Labeling) const
Returns the default text format to use for new text based objects in the specified context.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
@ Labeling
Text format used in labeling.
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QPointF toPoint(const QVariant &value, bool *ok=nullptr)
Converts a value to a point.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static QSizeF toSize(const QVariant &value, bool *ok=nullptr)
Converts a value to a size.
static QPainter::CompositionMode decodeBlendMode(const QString &s)
static QString encodeSize(QSizeF size)
Encodes a QSizeF to a string.
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
static QString encodePoint(QPointF point)
Encodes a QPointF to a string.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
Abstract base class for all rendered symbols.
void setRadiiUnit(Qgis::RenderUnit units)
Sets the units used for the shape's radii.
QString svgFile() const
Returns the absolute path to the background SVG file, if set.
QSizeF size() const
Returns the size of the background shape.
QSizeF radii() const
Returns the radii used for rounding the corners of shapes.
void setOpacity(double opacity)
Sets the background shape's opacity.
void setStrokeColor(const QColor &color)
Sets the color used for outlining the background shape.
Qt::PenJoinStyle joinStyle() const
Returns the join style used for drawing the background shape.
SizeType
Methods for determining the background shape size.
bool enabled() const
Returns whether the background is enabled.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the background shape.
double opacity() const
Returns the background shape's opacity.
double rotation() const
Returns the rotation for the background shape, in degrees clockwise.
QColor fillColor() const
Returns the color used for filing the background shape.
void setRadii(QSizeF radii)
Sets the radii used for rounding the corners of shapes.
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
ShapeType type() const
Returns the type of background shape (e.g., square, ellipse, SVG).
double strokeWidth() const
Returns the width of the shape's stroke (stroke).
void setSizeType(SizeType type)
Sets the method used to determine the size of the background shape (e.g., fixed size or buffer around...
ShapeType
Background shape types.
@ ShapeMarkerSymbol
Marker symbol.
void setFillColor(const QColor &color)
Sets the color used for filing the background shape.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units used for the shape's size.
QColor strokeColor() const
Returns the color used for outlining the background shape.
void setRotationType(RotationType type)
Sets the method used for rotating the background shape.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the background shape.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the shape size.
void setType(ShapeType type)
Sets the type of background shape to draw (e.g., square, ellipse, SVG).
Qgis::RenderUnit sizeUnit() const
Returns the units used for the shape's size.
RotationType
Methods for determining the rotation of the background shape.
void setEnabled(bool enabled)
Sets whether the text background will be drawn.
QgsMarkerSymbol * markerSymbol() const
Returns the marker symbol to be rendered in the background.
void setRotation(double rotation)
Sets the rotation for the background shape, in degrees clockwise.
void setStrokeWidthUnit(Qgis::RenderUnit units)
Sets the units used for the shape's stroke width.
void setOffsetUnit(Qgis::RenderUnit units)
Sets the units used for the shape's offset.
void setOffset(QPointF offset)
Sets the offset used for drawing the background shape.
void setSize(QSizeF size)
Sets the size of the background shape.
void setSvgFile(const QString &file)
Sets the path to the background SVG file.
void setStrokeWidth(double width)
Sets the width of the shape's stroke (stroke).
QPointF offset() const
Returns the offset used for drawing the background shape.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the buffer.
Qgis::RenderUnit sizeUnit() const
Returns the units for the buffer size.
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
double size() const
Returns the size of the buffer.
void setColor(const QColor &color)
Sets the color for the buffer.
void setOpacity(double opacity)
Sets the buffer opacity.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the buffer size.
bool enabled() const
Returns whether the buffer is enabled.
double opacity() const
Returns the buffer opacity.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units used for the buffer size.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
QColor color() const
Returns the color of the buffer.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the buffer.
void setSize(double size)
Sets the size of the buffer.
Contains pre-calculated metrics of a QgsTextDocument.
QSizeF documentSize(Qgis::TextLayoutMode mode, Qgis::TextOrientation orientation) const
Returns the overall size of the document.
static QgsTextDocumentMetrics calculateMetrics(const QgsTextDocument &document, const QgsTextFormat &format, const QgsRenderContext &context, double scaleFactor=1.0, const QgsTextDocumentRenderContext &documentContext=QgsTextDocumentRenderContext())
Returns precalculated text metrics for a text document, when rendered using the given base format and...
QRectF outerBounds(Qgis::TextLayoutMode mode, Qgis::TextOrientation orientation) const
Returns the outer bounds of the document, which is the documentSize() adjusted to account for any tex...
Represents a document consisting of one or more QgsTextBlock objects.
void splitLines(const QString &wrapCharacter, int autoWrapLength=0, bool useMaxLineLengthWhenAutoWrapping=true)
Splits lines of text in the document to separate lines, using a specified wrap character (wrapCharact...
QVector< QgsTextDocument > splitBlocksToDocuments() const
Splits the text document, such that each block in the document becomes a separate document of its own...
static QgsTextDocument fromTextAndFormat(const QStringList &lines, const QgsTextFormat &format)
Constructor for QgsTextDocument consisting of a set of lines, respecting settings from a text format.
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the text.
void setSize(double size)
Sets the size for rendered text.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the size.
void setCapitalization(Qgis::Capitalization capitalization)
Sets the text capitalization style.
void setOrientation(Qgis::TextOrientation orientation)
Sets the orientation for the text.
void setFont(const QFont &font)
Sets the font used for rendering text.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units for the size of rendered text.
void setShadow(const QgsTextShadowSettings &shadowSettings)
Sets the text's drop shadow settings.
void setMask(const QgsTextMaskSettings &maskSettings)
Sets the text's masking settings.
void setOpacity(double opacity)
Sets the text's opacity.
Qgis::Capitalization capitalization() const
Returns the text capitalization style.
QgsTextMaskSettings & mask()
Returns a reference to the masking settings.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
Qgis::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
void setTabStopDistance(double distance)
Sets the distance for tab stops.
double size() const
Returns the size for rendered text.
QgsTextShadowSettings & shadow()
Returns a reference to the text drop shadow settings.
void setTabPositions(const QList< QgsTextFormat::Tab > &positions)
Sets the list of tab positions for tab stops.
void setBackground(const QgsTextBackgroundSettings &backgroundSettings)
Sets the text's background settings.q.
QFont font() const
Returns the font used for rendering text.
QColor previewBackgroundColor() const
Returns the background color for text previews.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
void setLineHeight(double height)
Sets the line height for text.
void setEnabled(bool)
Returns whether the mask is enabled.
void setSize(double size)
Sets the size of the buffer.
double size() const
Returns the size of the buffer.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the buffer.
double opacity() const
Returns the mask's opacity.
bool enabled() const
Returns whether the mask is enabled.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units used for the buffer size.
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
void setOpacity(double opacity)
Sets the mask's opacity.
static QgsTextBackgroundSettings::ShapeType decodeShapeType(const QString &string)
Decodes a string representation of a background shape type to a type.
static Qgis::TextOrientation decodeTextOrientation(const QString &name, bool *ok=nullptr)
Attempts to decode a string representation of a text orientation.
static QgsTextShadowSettings::ShadowPlacement decodeShadowPlacementType(const QString &string)
Decodes a string representation of a shadow placement type to a type.
static QgsTextBackgroundSettings::RotationType decodeBackgroundRotationType(const QString &string)
Decodes a string representation of a background rotation type to a type.
static QString encodeTextOrientation(Qgis::TextOrientation orientation)
Encodes a text orientation.
static QgsTextBackgroundSettings::SizeType decodeBackgroundSizeType(const QString &string)
Decodes a string representation of a background size type to a type.
static double textWidth(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, QFontMetricsF *fontMetrics=nullptr)
Returns the width of a text based on a given format.
static int sizeToPixel(double size, const QgsRenderContext &c, Qgis::RenderUnit unit, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale())
Calculates pixel size (considering output size should be in pixel or map units, scale factors and opt...
static void drawText(const QRectF &rect, double rotation, Qgis::TextHorizontalAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, Qgis::TextVerticalAlignment vAlignment=Qgis::TextVerticalAlignment::Top, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Rectangle)
Draws text within a rectangle using the specified settings.
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Point, QFontMetricsF *fontMetrics=nullptr, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), double maxLineWidth=0)
Returns the height of a text based on a given format.
int offsetAngle() const
Returns the angle for offsetting the position of the shadow from the text.
void setBlurRadiusUnit(Qgis::RenderUnit units)
Sets the units used for the shadow's blur radius.
bool enabled() const
Returns whether the shadow is enabled.
void setOffsetUnit(Qgis::RenderUnit units)
Sets the units used for the shadow's offset.
int scale() const
Returns the scaling used for the drop shadow (in percentage of original size).
void setShadowPlacement(QgsTextShadowSettings::ShadowPlacement placement)
Sets the placement for the drop shadow.
double opacity() const
Returns the shadow's opacity.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the drop shadow.
void setColor(const QColor &color)
Sets the color for the drop shadow.
QColor color() const
Returns the color of the drop shadow.
ShadowPlacement
Placement positions for text shadow.
void setScale(int scale)
Sets the scaling used for the drop shadow (in percentage of original size).
double offsetDistance() const
Returns the distance for offsetting the position of the shadow from the text.
void setOffsetDistance(double distance)
Sets the distance for offsetting the position of the shadow from the text.
void setOpacity(double opacity)
Sets the shadow's opacity.
void setOffsetAngle(int angle)
Sets the angle for offsetting the position of the shadow from the text.
double blurRadius() const
Returns the blur radius for the shadow.
void setBlurRadius(double blurRadius)
Sets the blur radius for the shadow.
void setEnabled(bool enabled)
Sets whether the text shadow will be drawn.
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based dataset.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
const QgsDiagramRenderer * diagramRenderer() const
double tolerance() const
Gets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported,...
Qgis::VectorRenderingSimplificationFlags simplifyHints() const
Gets the simplification hints of the vector layer managed.
Qgis::VectorSimplificationAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
Basic labeling configuration for vector tile layers.
Implements a map layer that is dedicated to rendering of vector tiles.
QgsVectorTileLabeling * labeling() const
Returns currently assigned labeling.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
#define Q_NOWARN_DEPRECATED_POP
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
T qgsgeometry_cast(QgsAbstractGeometry *geom)
Q_GLOBAL_STATIC(QReadWriteLock, sDefinitionCacheLock)
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
QString updateDataDefinedString(const QString &value)
QVector< Qgis::LabelPredefinedPointPosition > PredefinedPointPositionVector
Q_GLOBAL_STATIC_WITH_ARGS(PredefinedPointPositionVector, DEFAULT_PLACEMENT_ORDER,({ Qgis::LabelPredefinedPointPosition::TopRight, Qgis::LabelPredefinedPointPosition::TopLeft, Qgis::LabelPredefinedPointPosition::BottomRight, Qgis::LabelPredefinedPointPosition::BottomLeft, Qgis::LabelPredefinedPointPosition::MiddleRight, Qgis::LabelPredefinedPointPosition::MiddleLeft, Qgis::LabelPredefinedPointPosition::TopSlightlyRight, Qgis::LabelPredefinedPointPosition::BottomSlightlyRight })) void QgsPalLayerSettings
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.