34 #include <QApplication> 37 #include <QFontMetrics> 64 #include <QMessageBox> 78 const QVector< QgsPalLayerSettings::PredefinedPointPosition > QgsPalLayerSettings::DEFAULT_PLACEMENT_ORDER
97 void QgsPalLayerSettings::initPropertyDefinitions()
99 if ( !sPropertyDefinitions.isEmpty() )
102 const QString origin = QStringLiteral(
"labeling" );
114 "e.g. Helvetica or Helvetica [Cronyx]" ), origin )
118 "e.g. Bold Condensed or Light Italic" ), origin )
150 "<b>Ellipse</b>|<b>Circle</b>|<b>SVG</b>]" ), origin )
174 "<b>Buffer</b>|<b>Background</b>]" ), origin )
190 "<b>3</b>=Left|<b>4</b>=Over|<b>5</b>=Right|<br>" 191 "<b>6</b>=Below Left|<b>7</b>=Below|<b>8</b>=Below Right]" ), origin )
206 + QStringLiteral(
"[<b>TL</b>=Top left|<b>TSL</b>=Top, slightly left|<b>T</b>=Top middle|<br>" 207 "<b>TSR</b>=Top, slightly right|<b>TR</b>=Top right|<br>" 208 "<b>L</b>=Left|<b>R</b>=Right|<br>" 209 "<b>BL</b>=Bottom left|<b>BSL</b>=Bottom, slightly left|<b>B</b>=Bottom middle|<br>" 210 "<b>BSR</b>=Bottom, slightly right|<b>BR</b>=Bottom right]" ), origin )
214 + QStringLiteral(
"[<b>OL</b>=On line|<b>AL</b>=Above line|<b>BL</b>=Below line|<br>" 215 "<b>LO</b>=Respect line orientation]" ), origin )
222 "<b>Half</b>|<b>Cap</b>|<b>Top</b>]" ), origin )
243 initPropertyDefinitions();
246 isExpression =
false;
249 previewBkgrdColor = Qt::white;
250 useSubstitutions =
false;
253 multilineAlign = MultiFollowPlacement;
254 addDirectionSymbol =
false;
255 leftDirectionSymbol = QStringLiteral(
"<" );
256 rightDirectionSymbol = QStringLiteral(
">" );
257 reverseDirectionSymbol =
false;
258 placeDirectionSymbol = SymbolLeftRight;
259 formatNumbers =
false;
264 placement = AroundPoint;
265 placementFlags = AboveLine | MapOrientation;
266 centroidWhole =
false;
267 centroidInside =
false;
268 predefinedPositionOrder = DEFAULT_PLACEMENT_ORDER;
269 fitInPolygonOnly =
false;
270 quadOffset = QuadrantOver;
276 offsetType = FromPoint;
278 preserveRotation =
true;
279 maxCurvedCharAngleIn = 25.0;
280 maxCurvedCharAngleOut = -25.0;
286 scaleVisibility =
false;
289 fontLimitPixelSize =
false;
290 fontMinPixelSize = 0;
291 fontMaxPixelSize = 10000;
293 upsidedownLabels = Upright;
295 labelPerPart =
false;
297 minFeatureSize = 0.0;
298 limitNumLabels =
false;
301 obstacleFactor = 1.0;
302 obstacleType = PolygonInterior;
308 , mDataDefinedProperties( s.mDataDefinedProperties )
389 mDataDefinedProperties = s.mDataDefinedProperties;
443 for (
const QString &name : referencedColumns )
445 attributeNames.insert( name );
501 for (
const QString &name : referencedColumns )
503 attributeNames.insert( name );
521 initPropertyDefinitions();
522 return sPropertyDefinitions;
534 static Qt::PenJoinStyle _decodePenJoinStyle(
const QString &str )
536 if ( str.compare( QLatin1String(
"Miter" ), Qt::CaseInsensitive ) == 0 )
return Qt::MiterJoin;
537 if ( str.compare( QLatin1String(
"Round" ), Qt::CaseInsensitive ) == 0 )
return Qt::RoundJoin;
538 return Qt::BevelJoin;
544 QString newValue = value;
545 if ( !value.isEmpty() && !value.contains( QLatin1String(
"~~" ) ) )
548 values << QStringLiteral(
"1" );
549 values << QStringLiteral(
"0" );
552 newValue = values.join( QStringLiteral(
"~~" ) );
560 QString newPropertyName =
"labeling/dataDefined/" + sPropertyDefinitions.value( p ).name();
561 QVariant newPropertyField = layer->
customProperty( newPropertyName, QVariant() );
563 if ( !newPropertyField.isValid() )
566 QString ddString = newPropertyField.toString();
568 if ( !ddString.isEmpty() && ddString != QLatin1String(
"0~~0~~~~" ) )
572 QStringList ddv = newStyleString.split( QStringLiteral(
"~~" ) );
574 bool active = ddv.at( 0 ).toInt();
575 if ( ddv.at( 1 ).toInt() )
591 void QgsPalLayerSettings::readOldDataDefinedPropertyMap(
QgsVectorLayer *layer, QDomElement *parentElem )
593 if ( !layer && !parentElem )
598 QgsPropertiesDefinition::const_iterator i = sPropertyDefinitions.constBegin();
599 for ( ; i != sPropertyDefinitions.constEnd(); ++i )
604 readOldDataDefinedProperty( layer, static_cast< Property >( i.key() ) );
606 else if ( parentElem )
609 QDomElement e = parentElem->firstChildElement( i.value().name() );
612 bool active = e.attribute( QStringLiteral(
"active" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
613 bool isExpression = e.attribute( QStringLiteral(
"useExpr" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
627 void QgsPalLayerSettings::readFromLayerCustomProperties(
QgsVectorLayer *layer )
629 if ( layer->
customProperty( QStringLiteral(
"labeling" ) ).toString() != QLatin1String(
"pal" ) )
652 QDomDocument doc( QStringLiteral(
"substitutions" ) );
653 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/substitutions" ) ).toString() );
654 QDomElement replacementElem = doc.firstChildElement( QStringLiteral(
"substitutions" ) );
684 if ( layer->
customProperty( QStringLiteral(
"labeling/distMapUnitScale" ) ).toString().isEmpty() )
687 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMinScale" ), 0.0 ).toDouble();
689 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMaxScale" ), 0.0 ).toDouble();
700 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetInMapUnits" ), QVariant(
true ) ).toBool() )
705 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitScale" ) ).toString().isEmpty() )
708 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMinScale" ), 0.0 ).toDouble();
710 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
718 QVariant tempAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant() );
719 if ( tempAngle.isValid() )
721 double oldAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant( 0.0 ) ).toDouble();
734 switch ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceUnit" ), QVariant( 1 ) ).toUInt() )
749 if ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitScale" ) ).toString().isEmpty() )
752 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMinScale" ), 0.0 ).toDouble();
754 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMaxScale" ), 0.0 ).toDouble();
763 double scalemn = layer->
customProperty( QStringLiteral(
"labeling/scaleMin" ), QVariant( 0 ) ).toDouble();
764 double scalemx = layer->
customProperty( QStringLiteral(
"labeling/scaleMax" ), QVariant( 0 ) ).toDouble();
767 QVariant scalevis = layer->
customProperty( QStringLiteral(
"labeling/scaleVisibility" ), QVariant() );
768 if ( scalevis.isValid() )
774 else if ( scalemn > 0 || scalemx > 0 )
801 zIndex = layer->
customProperty( QStringLiteral(
"labeling/zIndex" ), QVariant( 0.0 ) ).toDouble();
803 mDataDefinedProperties.
clear();
804 if ( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).isValid() )
806 QDomDocument doc( QStringLiteral(
"dd" ) );
807 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).toString() );
808 QDomElement elem = doc.firstChildElement( QStringLiteral(
"properties" ) );
809 mDataDefinedProperties.
readXml( elem, sPropertyDefinitions );
814 readOldDataDefinedPropertyMap( layer,
nullptr );
858 QDomElement textStyleElem = elem.firstChildElement( QStringLiteral(
"text-style" ) );
859 fieldName = textStyleElem.attribute( QStringLiteral(
"fieldName" ) );
860 isExpression = textStyleElem.attribute( QStringLiteral(
"isExpression" ) ).toInt();
862 mFormat.
readXml( elem, context );
863 previewBkgrdColor = QColor( textStyleElem.attribute( QStringLiteral(
"previewBkgrdColor" ), QStringLiteral(
"#ffffff" ) ) );
865 useSubstitutions = textStyleElem.attribute( QStringLiteral(
"useSubstitutions" ) ).toInt();
868 QDomElement textFormatElem = elem.firstChildElement( QStringLiteral(
"text-format" ) );
869 wrapChar = textFormatElem.attribute( QStringLiteral(
"wrapChar" ) );
870 autoWrapLength = textFormatElem.attribute( QStringLiteral(
"autoWrapLength" ), QStringLiteral(
"0" ) ).toInt();
871 useMaxLineLengthForAutoWrap = textFormatElem.attribute( QStringLiteral(
"useMaxLineLengthForAutoWrap" ), QStringLiteral(
"1" ) ).toInt();
873 addDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"addDirectionSymbol" ) ).toInt();
874 leftDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"leftDirectionSymbol" ), QStringLiteral(
"<" ) );
875 rightDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"rightDirectionSymbol" ), QStringLiteral(
">" ) );
878 formatNumbers = textFormatElem.attribute( QStringLiteral(
"formatNumbers" ) ).toInt();
879 decimals = textFormatElem.attribute( QStringLiteral(
"decimals" ) ).toInt();
880 plusSign = textFormatElem.attribute( QStringLiteral(
"plussign" ) ).toInt();
883 QDomElement placementElem = elem.firstChildElement( QStringLiteral(
"placement" ) );
884 placement =
static_cast< Placement >( placementElem.attribute( QStringLiteral(
"placement" ) ).toInt() );
885 placementFlags = placementElem.attribute( QStringLiteral(
"placementFlags" ) ).toUInt();
886 centroidWhole = placementElem.attribute( QStringLiteral(
"centroidWhole" ), QStringLiteral(
"0" ) ).toInt();
887 centroidInside = placementElem.attribute( QStringLiteral(
"centroidInside" ), QStringLiteral(
"0" ) ).toInt();
891 fitInPolygonOnly = placementElem.attribute( QStringLiteral(
"fitInPolygonOnly" ), QStringLiteral(
"0" ) ).toInt();
892 dist = placementElem.attribute( QStringLiteral(
"dist" ) ).toDouble();
893 if ( !placementElem.hasAttribute( QStringLiteral(
"distUnits" ) ) )
895 if ( placementElem.attribute( QStringLiteral(
"distInMapUnits" ) ).toInt() )
904 if ( !placementElem.hasAttribute( QStringLiteral(
"distMapUnitScale" ) ) )
907 double oldMin = placementElem.attribute( QStringLiteral(
"distMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
909 double oldMax = placementElem.attribute( QStringLiteral(
"distMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
918 xOffset = placementElem.attribute( QStringLiteral(
"xOffset" ), QStringLiteral(
"0" ) ).toDouble();
919 yOffset = placementElem.attribute( QStringLiteral(
"yOffset" ), QStringLiteral(
"0" ) ).toDouble();
920 if ( !placementElem.hasAttribute( QStringLiteral(
"offsetUnits" ) ) )
928 if ( !placementElem.hasAttribute( QStringLiteral(
"labelOffsetMapUnitScale" ) ) )
931 double oldMin = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
933 double oldMax = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
941 if ( placementElem.hasAttribute( QStringLiteral(
"angleOffset" ) ) )
943 double oldAngle = placementElem.attribute( QStringLiteral(
"angleOffset" ), QStringLiteral(
"0" ) ).toDouble();
948 angleOffset = placementElem.attribute( QStringLiteral(
"rotationAngle" ), QStringLiteral(
"0" ) ).toDouble();
951 preserveRotation = placementElem.attribute( QStringLiteral(
"preserveRotation" ), QStringLiteral(
"1" ) ).toInt();
952 maxCurvedCharAngleIn = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleIn" ), QStringLiteral(
"25" ) ).toDouble();
953 maxCurvedCharAngleOut = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleOut" ), QStringLiteral(
"-25" ) ).toDouble();
954 priority = placementElem.attribute( QStringLiteral(
"priority" ) ).toInt();
955 repeatDistance = placementElem.attribute( QStringLiteral(
"repeatDistance" ), QStringLiteral(
"0" ) ).toDouble();
956 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceUnits" ) ) )
959 switch ( placementElem.attribute( QStringLiteral(
"repeatDistanceUnit" ), QString::number( 1 ) ).toUInt() )
979 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceMapUnitScale" ) ) )
982 double oldMin = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
984 double oldMax = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
992 geometryGenerator = placementElem.attribute( QStringLiteral(
"geometryGenerator" ) );
997 QDomElement renderingElem = elem.firstChildElement( QStringLiteral(
"rendering" ) );
999 drawLabels = renderingElem.attribute( QStringLiteral(
"drawLabels" ), QStringLiteral(
"1" ) ).toInt();
1001 maximumScale = renderingElem.attribute( QStringLiteral(
"scaleMin" ), QStringLiteral(
"0" ) ).toDouble();
1002 minimumScale = renderingElem.attribute( QStringLiteral(
"scaleMax" ), QStringLiteral(
"0" ) ).toDouble();
1003 scaleVisibility = renderingElem.attribute( QStringLiteral(
"scaleVisibility" ) ).toInt();
1005 fontLimitPixelSize = renderingElem.attribute( QStringLiteral(
"fontLimitPixelSize" ), QStringLiteral(
"0" ) ).toInt();
1006 fontMinPixelSize = renderingElem.attribute( QStringLiteral(
"fontMinPixelSize" ), QStringLiteral(
"0" ) ).toInt();
1007 fontMaxPixelSize = renderingElem.attribute( QStringLiteral(
"fontMaxPixelSize" ), QStringLiteral(
"10000" ) ).toInt();
1008 displayAll = renderingElem.attribute( QStringLiteral(
"displayAll" ), QStringLiteral(
"0" ) ).toInt();
1011 labelPerPart = renderingElem.attribute( QStringLiteral(
"labelPerPart" ) ).toInt();
1012 mergeLines = renderingElem.attribute( QStringLiteral(
"mergeLines" ) ).toInt();
1013 minFeatureSize = renderingElem.attribute( QStringLiteral(
"minFeatureSize" ) ).toDouble();
1014 limitNumLabels = renderingElem.attribute( QStringLiteral(
"limitNumLabels" ), QStringLiteral(
"0" ) ).toInt();
1015 maxNumLabels = renderingElem.attribute( QStringLiteral(
"maxNumLabels" ), QStringLiteral(
"2000" ) ).toInt();
1016 obstacle = renderingElem.attribute( QStringLiteral(
"obstacle" ), QStringLiteral(
"1" ) ).toInt();
1017 obstacleFactor = renderingElem.attribute( QStringLiteral(
"obstacleFactor" ), QStringLiteral(
"1" ) ).toDouble();
1019 zIndex = renderingElem.attribute( QStringLiteral(
"zIndex" ), QStringLiteral(
"0.0" ) ).toDouble();
1021 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"dd_properties" ) );
1022 if ( !ddElem.isNull() )
1024 mDataDefinedProperties.
readXml( ddElem, sPropertyDefinitions );
1029 mDataDefinedProperties.
clear();
1030 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"data-defined" ) );
1031 readOldDataDefinedPropertyMap(
nullptr, &ddElem );
1078 QDomElement textStyleElem = mFormat.
writeXml( doc, context );
1081 textStyleElem.setAttribute( QStringLiteral(
"fieldName" ),
fieldName );
1082 textStyleElem.setAttribute( QStringLiteral(
"isExpression" ),
isExpression );
1083 textStyleElem.setAttribute( QStringLiteral(
"previewBkgrdColor" ),
previewBkgrdColor.name() );
1084 QDomElement replacementElem = doc.createElement( QStringLiteral(
"substitutions" ) );
1086 textStyleElem.appendChild( replacementElem );
1087 textStyleElem.setAttribute( QStringLiteral(
"useSubstitutions" ),
useSubstitutions );
1090 QDomElement textFormatElem = doc.createElement( QStringLiteral(
"text-format" ) );
1091 textFormatElem.setAttribute( QStringLiteral(
"wrapChar" ),
wrapChar );
1092 textFormatElem.setAttribute( QStringLiteral(
"autoWrapLength" ),
autoWrapLength );
1094 textFormatElem.setAttribute( QStringLiteral(
"multilineAlign" ), static_cast< unsigned int >(
multilineAlign ) );
1095 textFormatElem.setAttribute( QStringLiteral(
"addDirectionSymbol" ),
addDirectionSymbol );
1096 textFormatElem.setAttribute( QStringLiteral(
"leftDirectionSymbol" ),
leftDirectionSymbol );
1099 textFormatElem.setAttribute( QStringLiteral(
"placeDirectionSymbol" ), static_cast< unsigned int >(
placeDirectionSymbol ) );
1100 textFormatElem.setAttribute( QStringLiteral(
"formatNumbers" ),
formatNumbers );
1101 textFormatElem.setAttribute( QStringLiteral(
"decimals" ),
decimals );
1102 textFormatElem.setAttribute( QStringLiteral(
"plussign" ),
plusSign );
1105 QDomElement placementElem = doc.createElement( QStringLiteral(
"placement" ) );
1106 placementElem.setAttribute( QStringLiteral(
"placement" ),
placement );
1107 placementElem.setAttribute( QStringLiteral(
"placementFlags" ), static_cast< unsigned int >(
placementFlags ) );
1108 placementElem.setAttribute( QStringLiteral(
"centroidWhole" ),
centroidWhole );
1109 placementElem.setAttribute( QStringLiteral(
"centroidInside" ),
centroidInside );
1111 placementElem.setAttribute( QStringLiteral(
"fitInPolygonOnly" ),
fitInPolygonOnly );
1112 placementElem.setAttribute( QStringLiteral(
"dist" ),
dist );
1115 placementElem.setAttribute( QStringLiteral(
"offsetType" ), static_cast< unsigned int >(
offsetType ) );
1116 placementElem.setAttribute( QStringLiteral(
"quadOffset" ), static_cast< unsigned int >(
quadOffset ) );
1117 placementElem.setAttribute( QStringLiteral(
"xOffset" ),
xOffset );
1118 placementElem.setAttribute( QStringLiteral(
"yOffset" ),
yOffset );
1121 placementElem.setAttribute( QStringLiteral(
"rotationAngle" ),
angleOffset );
1122 placementElem.setAttribute( QStringLiteral(
"preserveRotation" ),
preserveRotation );
1125 placementElem.setAttribute( QStringLiteral(
"priority" ),
priority );
1126 placementElem.setAttribute( QStringLiteral(
"repeatDistance" ),
repeatDistance );
1130 placementElem.setAttribute( QStringLiteral(
"geometryGenerator" ),
geometryGenerator );
1132 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWkbTypes::GeometryType>() );
1133 placementElem.setAttribute( QStringLiteral(
"geometryGeneratorType" ), metaEnum.valueToKey(
geometryGeneratorType ) );
1136 QDomElement renderingElem = doc.createElement( QStringLiteral(
"rendering" ) );
1137 renderingElem.setAttribute( QStringLiteral(
"drawLabels" ),
drawLabels );
1138 renderingElem.setAttribute( QStringLiteral(
"scaleVisibility" ),
scaleVisibility );
1139 renderingElem.setAttribute( QStringLiteral(
"scaleMin" ),
maximumScale );
1140 renderingElem.setAttribute( QStringLiteral(
"scaleMax" ),
minimumScale );
1141 renderingElem.setAttribute( QStringLiteral(
"fontLimitPixelSize" ),
fontLimitPixelSize );
1142 renderingElem.setAttribute( QStringLiteral(
"fontMinPixelSize" ),
fontMinPixelSize );
1143 renderingElem.setAttribute( QStringLiteral(
"fontMaxPixelSize" ),
fontMaxPixelSize );
1144 renderingElem.setAttribute( QStringLiteral(
"displayAll" ),
displayAll );
1145 renderingElem.setAttribute( QStringLiteral(
"upsidedownLabels" ), static_cast< unsigned int >(
upsidedownLabels ) );
1147 renderingElem.setAttribute( QStringLiteral(
"labelPerPart" ),
labelPerPart );
1148 renderingElem.setAttribute( QStringLiteral(
"mergeLines" ),
mergeLines );
1149 renderingElem.setAttribute( QStringLiteral(
"minFeatureSize" ),
minFeatureSize );
1150 renderingElem.setAttribute( QStringLiteral(
"limitNumLabels" ),
limitNumLabels );
1151 renderingElem.setAttribute( QStringLiteral(
"maxNumLabels" ),
maxNumLabels );
1152 renderingElem.setAttribute( QStringLiteral(
"obstacle" ),
obstacle );
1153 renderingElem.setAttribute( QStringLiteral(
"obstacleFactor" ),
obstacleFactor );
1154 renderingElem.setAttribute( QStringLiteral(
"obstacleType" ), static_cast< unsigned int >(
obstacleType ) );
1155 renderingElem.setAttribute( QStringLiteral(
"zIndex" ),
zIndex );
1157 QDomElement ddElem = doc.createElement( QStringLiteral(
"dd_properties" ) );
1158 mDataDefinedProperties.
writeXml( ddElem, sPropertyDefinitions );
1160 QDomElement elem = doc.createElement( QStringLiteral(
"settings" ) );
1161 elem.appendChild( textStyleElem );
1162 elem.appendChild( textFormatElem );
1163 elem.appendChild( placementElem );
1164 elem.appendChild( renderingElem );
1165 elem.appendChild( ddElem );
1171 return QgsPalLabeling::checkMinimumSizeMM( ct, geom, minSize );
1181 QString textCopy( text );
1184 std::unique_ptr< QgsRenderContext > scopedRc;
1189 scopedRc->expressionContext().setFeature( *f );
1272 if ( wrapchr.isEmpty() )
1274 wrapchr = QStringLiteral(
"\n" );
1279 && ( !leftDirSymb.isEmpty() || !rightDirSymb.isEmpty() ) )
1281 QString dirSym = leftDirSymb;
1283 if ( fm->width( rightDirSymb ) > fm->width( dirSym ) )
1284 dirSym = rightDirSymb;
1288 textCopy.append( dirSym );
1292 textCopy.prepend( dirSym + QStringLiteral(
"\n" ) );
1296 double w = 0.0, h = 0.0;
1298 int lines = multiLineSplit.size();
1300 double labelHeight = fm->ascent() + fm->descent();
1302 h += fm->height() +
static_cast< double >( ( lines - 1 ) * labelHeight * multilineH );
1304 for (
const QString &line : multiLineSplit )
1306 w = std::max( w, fm->width( line ) );
1311 labelX = std::fabs( ptSize.x() -
ptZero.
x() );
1312 labelY = std::fabs( ptSize.y() -
ptZero.
y() );
1323 Q_ASSERT( labelFeature );
1335 registerObstacleFeature( f, context, labelFeature, obstacleGeometry );
1347 if ( obstacleGeometry.
isNull() )
1360 dataDefinedValues.clear();
1372 if ( useScaleVisibility )
1381 maxScale = 1 / std::fabs( maxScale );
1396 minScale = 1 / std::fabs( minScale );
1405 QFont labelFont = mFormat.
font();
1411 if ( exprVal.isValid() )
1413 QString units = exprVal.toString();
1414 if ( !units.isEmpty() )
1426 if ( fontSize <= 0.0 )
1433 if ( fontPixelSize < 1 )
1437 labelFont.setPixelSize( fontPixelSize );
1449 if ( fontMinPixel > labelFont.pixelSize() || labelFont.pixelSize() > fontMaxPixel )
1461 labelFont.setCapitalization( QFont::MixedCase );
1462 parseTextStyle( labelFont, fontunits, context );
1463 parseTextFormatting( context );
1464 parseTextBuffer( context );
1465 parseShapeBackground( context );
1466 parseDropShadow( context );
1486 labelText = result.isNull() ? QString() : result.toString();
1491 labelText = v.isNull() ? QString() : v.toString();
1503 if ( mFormat.
font().capitalization() != QFont::MixedCase )
1509 if ( exprVal.isValid() )
1511 QString fcase = exprVal.toString().trimmed();
1512 QgsDebugMsgLevel( QStringLiteral(
"exprVal FontCase:%1" ).arg( fcase ), 4 );
1514 if ( !fcase.isEmpty() )
1516 if ( fcase.compare( QLatin1String(
"NoChange" ), Qt::CaseInsensitive ) == 0 )
1520 else if ( fcase.compare( QLatin1String(
"Upper" ), Qt::CaseInsensitive ) == 0 )
1524 else if ( fcase.compare( QLatin1String(
"Lower" ), Qt::CaseInsensitive ) == 0 )
1528 else if ( fcase.compare( QLatin1String(
"Capitalize" ), Qt::CaseInsensitive ) == 0 )
1541 if ( decimalPlaces <= 0 )
1547 QVariant textV( labelText );
1549 double d = textV.toDouble( &ok );
1552 QString numberFormat;
1553 if ( d > 0 && signPlus )
1555 numberFormat.append(
'+' );
1557 numberFormat.append(
"%1" );
1558 labelText = numberFormat.arg( d, 0,
'f', decimalPlaces );
1563 std::unique_ptr<QFontMetricsF> labelFontMetrics(
new QFontMetricsF( labelFont ) );
1564 double labelX, labelY;
1570 double maxcharanglein = 20.0;
1571 double maxcharangleout = -20.0;
1580 if ( exprVal.isValid() )
1582 QString ptstr = exprVal.toString().trimmed();
1583 QgsDebugMsgLevel( QStringLiteral(
"exprVal CurvedCharAngleInOut:%1" ).arg( ptstr ), 4 );
1585 if ( !ptstr.isEmpty() )
1588 maxcharanglein = qBound( 20.0, static_cast< double >( maxcharanglePt.x() ), 60.0 );
1589 maxcharangleout = qBound( 20.0, static_cast< double >( maxcharanglePt.y() ), 95.0 );
1593 maxcharangleout = -( std::fabs( maxcharangleout ) );
1599 if ( exprVal.isValid() )
1601 QString str = exprVal.toString().trimmed();
1602 QgsDebugMsgLevel( QStringLiteral(
"exprVal CentroidWhole:%1" ).arg( str ), 4 );
1604 if ( !str.isEmpty() )
1606 if ( str.compare( QLatin1String(
"Visible" ), Qt::CaseInsensitive ) == 0 )
1608 wholeCentroid =
false;
1610 else if ( str.compare( QLatin1String(
"Whole" ), Qt::CaseInsensitive ) == 0 )
1612 wholeCentroid =
true;
1625 std::unique_ptr<QgsGeometry> scopedClonedGeom;
1632 geom = simplifier.
simplify( geom );
1642 bool doClip =
false;
1643 if ( !centroidPoly || !wholeCentroid )
1653 permissibleZone = geom;
1689 if ( !geos_geom_clone )
1718 if ( !obstacleGeometry.
isNull() )
1725 bool dataDefinedPosition =
false;
1726 bool layerDefinedRotation =
false;
1727 bool dataDefinedRotation =
false;
1728 double xPos = 0.0, yPos = 0.0,
angle = 0.0;
1729 bool ddXPos =
false, ddYPos =
false;
1730 double quadOffsetX = 0.0, quadOffsetY = 0.0;
1731 double offsetX = 0.0, offsetY = 0.0;
1734 bool ddFixedQuad =
false;
1738 if ( exprVal.isValid() )
1741 int quadInt = exprVal.toInt( &ok );
1742 QgsDebugMsgLevel( QStringLiteral(
"exprVal OffsetQuad:%1" ).arg( quadInt ), 4 );
1743 if ( ok && 0 <= quadInt && quadInt <= 8 )
1794 if ( exprVal.isValid() )
1796 QString ptstr = exprVal.toString().trimmed();
1797 QgsDebugMsgLevel( QStringLiteral(
"exprVal OffsetXY:%1" ).arg( ptstr ), 4 );
1799 if ( !ptstr.isEmpty() )
1810 if ( exprVal.isValid() )
1812 QString units = exprVal.toString().trimmed();
1813 QgsDebugMsgLevel( QStringLiteral(
"exprVal OffsetUnits:%1" ).arg( units ), 4 );
1814 if ( !units.isEmpty() )
1820 offUnit = decodedUnits;
1835 layerDefinedRotation =
true;
1843 if ( exprVal.isValid() )
1846 double rotD = exprVal.toDouble( &ok );
1847 QgsDebugMsgLevel( QStringLiteral(
"exprVal Rotation:%1" ).arg( rotD ), 4 );
1850 dataDefinedRotation =
true;
1854 angle = ( 360 - rotD ) * M_PI / 180.0;
1859 if ( exprVal.isValid() )
1861 if ( !exprVal.isNull() )
1862 xPos = exprVal.toDouble( &ddXPos );
1863 QgsDebugMsgLevel( QStringLiteral(
"exprVal PositionX:%1" ).arg( xPos ), 4 );
1866 if ( exprVal.isValid() )
1869 if ( !exprVal.isNull() )
1870 yPos = exprVal.toDouble( &ddYPos );
1871 QgsDebugMsgLevel( QStringLiteral(
"exprVal PositionY:%1" ).arg( yPos ), 4 );
1873 if ( ddXPos && ddYPos )
1875 dataDefinedPosition =
true;
1877 if ( layerDefinedRotation && !dataDefinedRotation )
1888 if ( exprVal.isValid() )
1890 QString haliString = exprVal.toString();
1891 QgsDebugMsgLevel( QStringLiteral(
"exprVal Hali:%1" ).arg( haliString ), 4 );
1892 if ( haliString.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
1894 xdiff -= labelX / 2.0;
1896 else if ( haliString.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
1904 if ( exprVal.isValid() )
1906 QString valiString = exprVal.toString();
1907 QgsDebugMsgLevel( QStringLiteral(
"exprVal Vali:%1" ).arg( valiString ), 4 );
1909 if ( valiString.compare( QLatin1String(
"Bottom" ), Qt::CaseInsensitive ) != 0 )
1911 if ( valiString.compare( QLatin1String(
"Top" ), Qt::CaseInsensitive ) == 0 )
1917 double descentRatio = labelFontMetrics->descent() / labelFontMetrics->height();
1918 if ( valiString.compare( QLatin1String(
"Base" ), Qt::CaseInsensitive ) == 0 )
1920 ydiff -= labelY * descentRatio;
1924 double capHeightRatio = ( labelFontMetrics->boundingRect(
'H' ).height() + 1 + labelFontMetrics->descent() ) / labelFontMetrics->height();
1925 ydiff -= labelY * capHeightRatio;
1926 if ( valiString.compare( QLatin1String(
"Half" ), Qt::CaseInsensitive ) == 0 )
1928 ydiff += labelY * ( capHeightRatio - descentRatio ) / 2.0;
1935 if ( dataDefinedRotation )
1938 double xd = xdiff * std::cos(
angle ) - ydiff * std::sin(
angle );
1939 double yd = xdiff * std::sin(
angle ) + ydiff * std::cos(
angle );
1978 if ( exprVal.isValid() )
1980 QString units = exprVal.toString().trimmed();
1981 QgsDebugMsgLevel( QStringLiteral(
"exprVal RepeatDistanceUnits:%1" ).arg( units ), 4 );
1982 if ( !units.isEmpty() )
1988 repeatUnits = decodedUnits;
2007 ( *labelFeature )->setFixedPosition(
QgsPointXY( xPos, yPos ) );
2009 ( *labelFeature )->setHasFixedAngle( dataDefinedRotation || ( !dataDefinedPosition && !
qgsDoubleNear(
angle, 0.0 ) ) );
2010 ( *labelFeature )->setFixedAngle(
angle );
2011 ( *labelFeature )->setQuadOffset( QPointF( quadOffsetX, quadOffsetY ) );
2012 ( *labelFeature )->setPositionOffset(
QgsPointXY( offsetX, offsetY ) );
2013 ( *labelFeature )->setOffsetType(
offsetType );
2014 ( *labelFeature )->setAlwaysShow( alwaysShow );
2015 ( *labelFeature )->setRepeatDistance( repeatDist );
2016 ( *labelFeature )->setLabelText( labelText );
2017 ( *labelFeature )->setPermissibleZone( permissibleZone );
2018 if ( geosObstacleGeomClone )
2020 ( *labelFeature )->setObstacleGeometry( std::move( geosObstacleGeomClone ) );
2025 ( *labelFeature )->setSymbolSize( QSizeF( obstacleGeometry.
boundingBox().
width(),
2032 double topMargin = std::max( 0.25 * labelFontMetrics->ascent(), 0.0 );
2033 double bottomMargin = 1.0 + labelFontMetrics->descent();
2034 QgsMargins vm( 0.0, topMargin, 0.0, bottomMargin );
2036 ( *labelFeature )->setVisualMargin( vm );
2039 QgsDebugMsgLevel( QStringLiteral(
"PAL font stored definedFont: %1, Style: %2" ).arg( labelFont.toString(), labelFont.styleName() ), 4 );
2045 labelFontMetrics.get(),
xform, maxcharanglein, maxcharangleout );
2057 if ( exprVal.isValid() )
2059 QString units = exprVal.toString().trimmed();
2060 QgsDebugMsgLevel( QStringLiteral(
"exprVal DistanceUnits:%1" ).arg( units ), 4 );
2061 if ( !units.isEmpty() )
2067 distUnit = decodedUnits;
2077 distance = ( distance < 0 ? -1 : 1 ) * std::max( std::fabs( distance ), 1.0 );
2083 ( *labelFeature )->setDistLabel( d );
2088 ( *labelFeature )->setHasFixedQuadrant(
true );
2091 pal::LineArrangementFlags featureArrangementFlags =
static_cast< pal::LineArrangementFlags
>(
placementFlags );
2094 if ( !dataDefinedLineArrangement.isEmpty() )
2098 ( *labelFeature )->setArrangementFlags( featureArrangementFlags );
2103 ( *labelFeature )->setZIndex( z );
2108 if ( exprVal.isValid() )
2111 double priorityD = exprVal.toDouble( &ok );
2114 priorityD = qBound( 0.0, priorityD, 10.0 );
2115 priorityD = 1 - priorityD / 10.0;
2116 ( *labelFeature )->setPriority( priorityD );
2120 ( *labelFeature )->setIsObstacle( isObstacle );
2125 if ( exprVal.isValid() )
2128 double factorD = exprVal.toDouble( &ok );
2131 factorD = qBound( 0.0, factorD, 10.0 );
2132 factorD = factorD / 5.0 + 0.0001;
2133 featObstacleFactor = factorD;
2136 ( *labelFeature )->setObstacleFactor( featObstacleFactor );
2139 if ( positionOrder.isEmpty() )
2140 positionOrder = QgsPalLayerSettings::DEFAULT_PLACEMENT_ORDER;
2144 if ( !dataDefinedOrder.isEmpty() )
2148 ( *labelFeature )->setPredefinedPositionOrder( positionOrder );
2159 if ( !obstacleGeometry.
isNull() )
2161 geom = obstacleGeometry;
2175 std::unique_ptr<QgsGeometry> scopedClonedGeom;
2181 geom = simplifier.
simplify( geom );
2185 std::unique_ptr<QgsGeometry> scopedPreparedGeom;
2193 if ( !geos_geom_clone )
2197 *obstacleFeature =
new QgsLabelFeature( f.
id(), std::move( geos_geom_clone ), QSizeF( 0, 0 ) );
2202 bool QgsPalLayerSettings::dataDefinedValEval( DataDefinedValueType valType,
2206 if ( !mDataDefinedProperties.
isActive( p ) )
2210 exprVal = mDataDefinedProperties.
value( p, context );
2211 if ( exprVal.isValid() )
2217 bool bol = exprVal.toBool();
2218 dataDefinedValues.insert( p, QVariant( bol ) );
2224 int size = exprVal.toInt( &ok );
2228 dataDefinedValues.insert( p, QVariant( size ) );
2236 int size = exprVal.toInt( &ok );
2238 if ( ok && size > 0 )
2240 dataDefinedValues.insert( p, QVariant( size ) );
2248 double size = exprVal.toDouble( &ok );
2252 dataDefinedValues.insert( p, QVariant( size ) );
2260 double size = exprVal.toDouble( &ok );
2262 if ( ok && size > 0.0 )
2264 dataDefinedValues.insert( p, QVariant( size ) );
2272 double rot = exprVal.toDouble( &ok );
2275 if ( rot < -180.0 && rot >= -360 )
2279 if ( rot > 180.0 && rot <= 360 )
2283 if ( rot >= -180 && rot <= 180 )
2285 dataDefinedValues.insert( p, QVariant( rot ) );
2294 int size = exprVal.toInt( &ok );
2295 if ( ok && size >= 0 && size <= 100 )
2297 dataDefinedValues.insert( p, QVariant( size ) );
2304 QString str = exprVal.toString();
2306 dataDefinedValues.insert( p, QVariant( str ) );
2311 QString unitstr = exprVal.toString().trimmed();
2313 if ( !unitstr.isEmpty() )
2322 QString colorstr = exprVal.toString().trimmed();
2325 if ( color.isValid() )
2327 dataDefinedValues.insert( p, QVariant( color ) );
2334 QString joinstr = exprVal.toString().trimmed();
2336 if ( !joinstr.isEmpty() )
2338 dataDefinedValues.insert( p, QVariant( static_cast< int >( _decodePenJoinStyle( joinstr ) ) ) );
2345 QString blendstr = exprVal.toString().trimmed();
2347 if ( !blendstr.isEmpty() )
2356 QString ptstr = exprVal.toString().trimmed();
2358 if ( !ptstr.isEmpty() )
2367 QString ptstr = exprVal.toString().trimmed();
2369 if ( !ptstr.isEmpty() )
2381 void QgsPalLayerSettings::parseTextStyle( QFont &labelFont,
2394 QString ddFontFamily;
2397 if ( exprVal.isValid() )
2399 QString family = exprVal.toString().trimmed();
2400 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font family:%1" ).arg( family ), 4 );
2402 if ( labelFont.family() != family )
2408 ddFontFamily = family;
2414 QString ddFontStyle;
2416 if ( exprVal.isValid() )
2418 QString fontstyle = exprVal.toString().trimmed();
2419 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font style:%1" ).arg( fontstyle ), 4 );
2420 ddFontStyle = fontstyle;
2434 QFont appFont = QApplication::font();
2435 bool newFontBuilt =
false;
2436 if ( ddBold || ddItalic )
2439 newFont = QFont( !ddFontFamily.isEmpty() ? ddFontFamily : labelFont.family() );
2440 newFontBuilt =
true;
2441 newFont.setBold( ddBold );
2442 newFont.setItalic( ddItalic );
2444 else if ( !ddFontStyle.isEmpty()
2445 && ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2447 if ( !ddFontFamily.isEmpty() )
2450 QFont styledfont = mFontDB.font( ddFontFamily, ddFontStyle, appFont.pointSize() );
2451 if ( appFont != styledfont )
2453 newFont = styledfont;
2454 newFontBuilt =
true;
2461 else if ( !ddFontFamily.isEmpty() )
2463 if ( ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2466 QFont styledfont = mFontDB.font( ddFontFamily, mFormat.
namedStyle(), appFont.pointSize() );
2467 if ( appFont != styledfont )
2469 newFont = styledfont;
2470 newFontBuilt =
true;
2475 newFont = QFont( ddFontFamily );
2476 newFontBuilt =
true;
2484 newFont.setPixelSize( labelFont.pixelSize() );
2485 newFont.setUnderline( labelFont.underline() );
2486 newFont.setStrikeOut( labelFont.strikeOut() );
2487 newFont.setWordSpacing( labelFont.wordSpacing() );
2488 newFont.setLetterSpacing( QFont::AbsoluteSpacing, labelFont.letterSpacing() );
2490 labelFont = newFont;
2494 double wordspace = labelFont.wordSpacing();
2500 double letterspace = labelFont.letterSpacing();
2510 labelFont.setStrikeOut( strikeout );
2518 labelFont.setUnderline( underline );
2544 drawBuffer = exprVal.toBool();
2553 double bufrSize = buffer.
size();
2556 bufrSize = exprVal.toDouble();
2560 double bufferOpacity = buffer.
opacity() * 100;
2563 bufferOpacity = exprVal.toDouble();
2566 drawBuffer = ( drawBuffer && bufrSize > 0.0 && bufferOpacity > 0 );
2597 wrapchr = exprVal.toString();
2603 evalAutoWrapLength = exprVal.toInt();
2612 if ( exprVal.isValid() )
2614 QString str = exprVal.toString().trimmed();
2615 QgsDebugMsgLevel( QStringLiteral(
"exprVal MultiLineAlignment:%1" ).arg( str ), 4 );
2617 if ( !str.isEmpty() )
2622 if ( str.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
2626 else if ( str.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
2630 else if ( str.compare( QLatin1String(
"Follow" ), Qt::CaseInsensitive ) == 0 )
2642 drawDirSymb = exprVal.toBool();
2655 if ( exprVal.isValid() )
2657 QString str = exprVal.toString().trimmed();
2658 QgsDebugMsgLevel( QStringLiteral(
"exprVal DirSymbPlacement:%1" ).arg( str ), 4 );
2660 if ( !str.isEmpty() )
2665 if ( str.compare( QLatin1String(
"Above" ), Qt::CaseInsensitive ) == 0 )
2669 else if ( str.compare( QLatin1String(
"Below" ), Qt::CaseInsensitive ) == 0 )
2684 void QgsPalLayerSettings::parseShapeBackground(
QgsRenderContext &context )
2691 bool drawShape = background.
enabled();
2694 drawShape = exprVal.toBool();
2703 double shapeOpacity = background.
opacity() * 100;
2706 shapeOpacity = 100.0 * exprVal.toDouble();
2709 drawShape = ( drawShape && shapeOpacity > 0 );
2721 if ( exprVal.isValid() )
2723 QString skind = exprVal.toString().trimmed();
2724 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeKind:%1" ).arg( skind ), 4 );
2726 if ( !skind.isEmpty() )
2731 if ( skind.compare( QLatin1String(
"Square" ), Qt::CaseInsensitive ) == 0 )
2735 else if ( skind.compare( QLatin1String(
"Ellipse" ), Qt::CaseInsensitive ) == 0 )
2739 else if ( skind.compare( QLatin1String(
"Circle" ), Qt::CaseInsensitive ) == 0 )
2743 else if ( skind.compare( QLatin1String(
"SVG" ), Qt::CaseInsensitive ) == 0 )
2747 shapeKind = shpkind;
2753 QString svgPath = background.
svgFile();
2756 if ( exprVal.isValid() )
2758 QString svgfile = exprVal.toString().trimmed();
2759 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSVGFile:%1" ).arg( svgfile ), 4 );
2769 if ( exprVal.isValid() )
2771 QString stype = exprVal.toString().trimmed();
2772 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSizeType:%1" ).arg( stype ), 4 );
2774 if ( !stype.isEmpty() )
2779 if ( stype.compare( QLatin1String(
"Fixed" ), Qt::CaseInsensitive ) == 0 )
2783 shpSizeType = sizType;
2789 double ddShpSizeX = background.
size().width();
2792 ddShpSizeX = exprVal.toDouble();
2796 double ddShpSizeY = background.
size().height();
2799 ddShpSizeY = exprVal.toDouble();
2805 && ( svgPath.isEmpty()
2806 || ( !svgPath.isEmpty()
2808 && ddShpSizeX == 0.0 ) ) )
2814 && ( ddShpSizeX == 0.0 || ddShpSizeY == 0.0 ) )
2835 if ( exprVal.isValid() )
2837 QString rotstr = exprVal.toString().trimmed();
2838 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeRotationType:%1" ).arg( rotstr ), 4 );
2840 if ( !rotstr.isEmpty() )
2845 if ( rotstr.compare( QLatin1String(
"Offset" ), Qt::CaseInsensitive ) == 0 )
2849 else if ( rotstr.compare( QLatin1String(
"Fixed" ), Qt::CaseInsensitive ) == 0 )
2899 bool drawShadow = shadow.
enabled();
2902 drawShadow = exprVal.toBool();
2911 double shadowOpacity = shadow.
opacity() * 100;
2914 shadowOpacity = exprVal.toDouble();
2921 shadowOffDist = exprVal.toDouble();
2928 shadowRad = exprVal.toDouble();
2931 drawShadow = ( drawShadow && shadowOpacity > 0 && !( shadowOffDist == 0.0 && shadowRad == 0.0 ) );
2944 if ( exprVal.isValid() )
2946 QString str = exprVal.toString().trimmed();
2947 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShadowUnder:%1" ).arg( str ), 4 );
2949 if ( !str.isEmpty() )
2954 if ( str.compare( QLatin1String(
"Text" ), Qt::CaseInsensitive ) == 0 )
2958 else if ( str.compare( QLatin1String(
"Buffer" ), Qt::CaseInsensitive ) == 0 )
2962 else if ( str.compare( QLatin1String(
"Background" ), Qt::CaseInsensitive ) == 0 )
3035 QStringList multiLineSplit;
3036 if ( !wrapCharacter.isEmpty() && wrapCharacter != QLatin1String(
"\n" ) )
3039 const QStringList lines = text.split( wrapCharacter );
3040 for (
const QString &line : lines )
3042 multiLineSplit.append( line.split(
'\n' ) );
3047 multiLineSplit = text.split(
'\n' );
3051 if ( autoWrapLength != 0 )
3053 QStringList autoWrappedLines;
3054 autoWrappedLines.reserve( multiLineSplit.count() );
3055 for (
const QString &line : qgis::as_const( multiLineSplit ) )
3057 autoWrappedLines.append(
QgsStringUtils::wordWrap( line, autoWrapLength, useMaxLineLengthWhenAutoWrapping ).split(
'\n' ) );
3059 multiLineSplit = autoWrappedLines;
3061 return multiLineSplit;
3066 QStringList graphemes;
3067 QTextBoundaryFinder boundaryFinder( QTextBoundaryFinder::Grapheme, text );
3068 int currentBoundary = -1;
3069 int previousBoundary = 0;
3070 while ( ( currentBoundary = boundaryFinder.toNextBoundary() ) > 0 )
3072 graphemes << text.mid( previousBoundary, currentBoundary - previousBoundary );
3073 previousBoundary = currentBoundary;
3103 QgsDebugMsgLevel( QStringLiteral(
"Ignoring feature due to transformation exception" ), 4 );
3109 return std::isfinite( point.
x() ) && std::isfinite( point.
y() );
3112 cp->removeInvalidRings();
3122 QgsDebugMsg( QStringLiteral(
"Error rotating geometry" ).arg( geom.
asWkt() ) );
3136 QVector< QgsGeometry> parts;
3137 parts.reserve( qgsgeometry_cast< const QgsGeometryCollection * >( geom.
constGet() )->numGeometries() );
3141 if ( !partGeom.isGeosValid() )
3143 partGeom = partGeom.
buffer( 0, 0 );
3145 parts.append( partGeom );
3152 if ( bufferGeom.
isNull() )
3154 QgsDebugMsg( QStringLiteral(
"Could not repair geometry: %1" ).arg( bufferGeom.
lastError() ) );
3161 if ( !clipGeometry.
isNull() &&
3197 double length = geom.
length();
3198 if ( length >= 0.0 )
3200 return ( length >= ( minSize * mapUnitsPerMM ) );
3205 double area = geom.
area();
3208 return ( std::sqrt( area ) >= ( minSize * mapUnitsPerMM ) );
3216 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3219 bool changed =
false;
3225 format.
setColor( ddColor.value<QColor>() );
3250 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3305 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3308 bool changed =
false;
3356 buffer.
setColor( ddColor.value<QColor>() );
3383 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3386 bool changed =
false;
3426 QSizeF size = background.
size();
3433 QSizeF size = background.
size();
3534 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3537 bool changed =
false;
3596 shadow.
setColor( ddColor.value<QColor>() );
3634 #if 0 // TODO: generalize some of this 3637 double cx = lp->
getX() + w / 2.0;
3638 double cy = lp->
getY() + h / 2.0;
3641 double sw = w * scale;
3642 double sh = h * scale;
3643 QRectF rect( -sw / 2, -sh / 2, sw, sh );
3649 if ( lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT &&
3650 lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT_OVER &&
3653 painter->rotate( rotation );
3656 painter->translate( rect.bottomLeft() );
3657 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
3658 painter->translate( -rect.bottomLeft() );
3661 QRectF rect( 0, 0, outPt2.
x() - outPt.
x(), outPt2.
y() - outPt.
y() );
3662 painter->translate( QPointF( outPt.
x(), outPt.
y() ) );
3663 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
3668 painter->setPen( QColor( 255, 0, 0, 64 ) );
3672 painter->setPen( QColor( 0, 0, 0, 64 ) );
3674 painter->drawRect( rect );
3678 rect.moveTo( outPt.
x(), outPt.
y() );
3696 QList<QgsLabelPosition> positions;
3698 QList<QgsLabelPosition *> positionPointers;
3699 if ( mLabelSearchTree )
3701 mLabelSearchTree->label( p, positionPointers );
3702 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
3703 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
3714 QList<QgsLabelPosition> positions;
3716 QList<QgsLabelPosition *> positionPointers;
3717 if ( mLabelSearchTree )
3719 mLabelSearchTree->labelsInRect( r, positionPointers );
3720 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
3721 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
3732 mLabelSearchTree->setMapSettings( settings );
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Label on bottom right of point.
Render units (eg mm/pixels/map units)
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
void registerFeature(const QgsFeature &f, QgsRenderContext &context, QgsLabelFeature **labelFeature=nullptr, QgsGeometry obstacleGeometry=QgsGeometry())
Register a feature for labeling.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the labeling property definitions.
double xOffset
Horizontal offset of label.
The class is used as a container of context for various read/write operations on other objects...
QString geometryGenerator
The geometry generator expression. Null if disabled.
Shape transparency (deprecated)
QColor strokeColor() const
Returns the color used for outlining the background shape.
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.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
void setScale(int scale)
Sets the scaling used for the drop shadow (in percentage of original size).
double convertToMapUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
Shape size is determined by adding a buffer margin around text.
void setLineHeight(double height)
Sets the line height for text.
void setRadiiUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's radii.
A rectangle specified with double values.
void setStrokeWidth(double width)
Sets the width of the shape's stroke (stroke).
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
double rendererScale() const
Returns the renderer map scale.
Label on bottom-left of point.
RotationType
Methods for determining the rotation of the background shape.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
double maxCurvedCharAngleOut
Maximum angle between outside curved label characters (valid range -20.0 to -95.0) ...
double maximumScale
The maximum map scale (i.e.
QString leftDirectionSymbol
String to use for left direction arrows.
void setOpacity(double opacity)
Sets the text's opacity.
Positive integer values (including 0)
void setOffsetUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shadow's offset.
QgsUnitTypes::RenderUnit repeatDistanceUnit
Units for repeating labels for a single feature.
QSizeF radii() const
Returns the radii used for rounding the corners of shapes.
QSizeF size() const
Returns the size of the background shape.
double opacity() const
Returns the text's opacity.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Added in QGIS v2.4.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the shape's size.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QPointF offset() const
Returns the offset used for drawing the background shape.
QColor fillColor() const
Returns the color used for filing the background shape.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double...
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
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...
static QString encodeSize(QSizeF size)
Encodes a QSizeF to a string.
double angleOffset
Label rotation, in degrees clockwise.
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
bool formatNumbers
Set to true to format numeric label text as numbers (e.g.
A class to query the labeling structure at a given point (small wrapper around pal RTree class) ...
void readXml(QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
Draw shadow under buffer.
UpsideDownLabels upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
double obstacleFactor
Obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels, 1.0 less likely to be covered
Label on top-left of point.
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
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...
ShadowPlacement
Placement positions for text shadow.
Place direction symbols on below label.
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point...
QgsTextShadowSettings & shadow()
Returns a reference to the text drop shadow settings.
double blurRadius() const
Returns the blur radius for the shadow.
static void drawLabelCandidateRect(pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform, QList< QgsLabelCandidate > *candidates=nullptr)
double getY(int i=0) const
Returns the down-left y coordinate.
Arranges candidates following the curvature of a line feature. Applies to line layers only...
double opacity() const
Returns the background shape's opacity.
void setStrokeColor(const QColor &color)
Sets the color used for outlining the background shape.
void setSize(double size)
Sets the size of the buffer.
A class to represent a 2D point.
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry...
double strokeWidth() const
Returns the width of the shape's stroke (stroke).
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the buffer size.
OperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
double offsetDistance() const
Returns the distance for offsetting the position of the shadow from the text.
bool obstacle
true if features for layer are obstacles to labels of other layers.
int decimals
Number of decimal places to show for numeric labels.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the buffer.
double repeatDistance
Distance for repeating labels for a single feature.
QVariant evaluate()
Evaluate the feature and return the result.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
static QPointF decodePoint(const QString &string)
Decodes a QSizeF from a string.
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
QuadrantPosition quadOffset
Sets the quadrant in which to offset labels from feature.
QgsUnitTypes::RenderUnit offsetUnits
Units for offsets of label.
void setOffsetUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's offset.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
Shadow transparency (deprecated)
QColor color() const
Returns the color that text will be rendered in.
double yOffset
Vertical offset of label.
Class that adds extra information to QgsLabelFeature for text labels.
Curve polygon geometry type.
QString evalErrorString() const
Returns evaluation error.
void setBlurRadius(double blurRadius)
Sets the blur radius for the shadow.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
void setDefinedFont(const QFont &f)
Sets font to be used for rendering.
void setOpacity(double opacity)
Sets the shadow's opacity.
X-coordinate data defined label position.
Min scale (deprecated, for old project compatibility only)
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
Container of fields for a vector layer.
Label on top-right of point.
bool addDirectionSymbol
If true, '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) will be ...
bool geometryGeneratorEnabled
Defines if the geometry generator is enabled or not. If disabled, the standard geometry will be taken...
A geometry is the spatial representation of a feature.
bool drawLabels
Whether to draw labels for this layer.
QgsGeometry buffer(double distance, int segments) const
Returns a buffer region around this geometry having the given width and with a specified number of se...
void setBackground(const QgsTextBackgroundSettings &backgroundSettings)
Sets the text's background settings.q.
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
bool mergeLines
true if connected line features with identical label text should be merged prior to generating label ...
Color with alpha channel.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the background shape.
QgsMapUnitScale repeatDistanceMapUnitScale
Map unit scale for repeating labels for a single feature.
MultiLineAlign multilineAlign
Horizontal alignment of multi-line labels.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
FeaturePart * getFeaturePart()
Returns the feature corresponding to this labelposition.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Positive double value (including 0)
Container for settings relating to a text background object.
const QgsCoordinateReferenceSystem & crs
Percentage of another measurement (e.g., canvas size, feature size)
static int sizeToPixel(double size, const QgsRenderContext &c, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale())
Calculates pixel size (considering output size should be in pixel or map units, scale factors and opt...
void setBlurRadiusUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shadow's blur radius.
QVector< PredefinedPointPosition > predefinedPositionOrder
Ordered list of predefined label positions for points.
SimplifyAlgorithm
Types of simplification algorithms that can be used.
int autoWrapLength
If non-zero, indicates that label text should be automatically wrapped to (ideally) the specified num...
QString parserErrorString() const
Returns parser error.
double maxCurvedCharAngleIn
Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
QgsCoordinateTransform ct
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
static QString encodePoint(QPointF point)
Encodes a QPointF to a string.
bool reverseDirectionSymbol
True if direction symbols should be reversed.
Rotation (value between 0-360 degrees)
double maxScale
The maximum scale, or 0.0 if unset.
ShapeType type() const
Returns the type of background shape (e.g., square, ellipse, SVG).
void setOffset(QPointF offset)
Sets the offset used for drawing the background shape.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
double zIndex
Z-Index of label, where labels with a higher z-index are rendered on top of labels with a lower z-ind...
double mapRotation() const
Returns current map rotation in degrees.
void setHasFixedPosition(bool enabled)
Sets whether the label should use a fixed position instead of being automatically placed...
QgsStringReplacementCollection substitutions
Substitution collection for automatic text substitution with labels.
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
The QgsMapSettings class contains configuration for rendering of the map.
static QString encodeColor(const QColor &color)
static bool staticWillUseLayer(QgsVectorLayer *layer)
called to find out whether the layer is used for labeling
void writeXml(QDomElement &elem, QDomDocument &doc) const
Writes the collection state to an XML element.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the property with the specified key from within the collection...
QgsGeometry mergeLines() const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
Place direction symbols on left/right of label.
Perform transforms between map coordinates and device coordinates.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the background shape.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
Shape rotation is a fixed angle.
Property
Data definable properties.
double cost() const
Returns the candidate label position's geographical cost.
No simplification can be applied.
ObstacleType obstacleType
Controls how features act as obstacles for labels.
static pal::LineArrangementFlags decodeLinePlacementFlags(const QString &string)
Decodes a string to set of line placement flags.
QPointF toQPointF() const
Converts a point to a QPointF.
bool displayAll
If true, all features will be labelled even when overlaps occur.
QColor color() const
Returns the color of the drop shadow.
void setIsObstacle(bool enabled)
Sets whether the feature will act as an obstacle for labels.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue)
Returns the value corresponding to the given key of an enum.
void setOffsetDistance(double distance)
Sets the distance for offsetting the position of the shadow from the text.
bool isGeosValid(QgsGeometry::ValidityFlags flags=nullptr) const
Checks validity of the geometry using GEOS.
static QString capitalize(const QString &string, Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
Offset distance applies from point geometry.
QList< QgsLabelPosition > labelsAtPosition(const QgsPointXY &p) const
Returns infos about labels at a given (map) position.
#define QgsDebugMsgLevel(str, level)
double tolerance() const
Gets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
int fontMaxPixelSize
Maximum pixel size for showing rendered map unit labels (1 - 10000).
static bool fontFamilyOnSystem(const QString &family)
Check whether font family is on system in a quick manner, which does not compare [foundry].
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
Maximum map scale (ie most "zoomed in")
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.
The geometries can be fully simplified by its BoundingBox.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the drop shadow.
double width() const
Returns the width of the rectangle.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context)
Write settings into a DOM element.
void setColor(const QColor &color)
Sets the color for the drop shadow.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setDataDefinedValues(const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &values)
Sets data-defined values.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
void setEnabled(bool enabled)
Sets whether the text shadow will be drawn.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
Horizontal alignment for data defined label position (Left, Center, Right)
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
LabelPosition * getNextPart() const
const QgsMapToPixel * xform
Property requires a numeric value.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void calculateInfo(bool curvedLabeling, QFontMetricsF *fm, const QgsMapToPixel *xform, double fontScale, double maxinangle, double maxoutangle)
calculate data for info(). setDefinedFont() must have been called already.
QString svgFile() const
Returns the absolute path to the background SVG file, if set.
Qt::PenJoinStyle joinStyle() const
Returns the join style used for drawing the background shape.
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
Upside-down labels (90 <= angle < 270) are shown upright.
SizeType
Methods for determining the background shape size.
double opacity() const
Returns the buffer opacity.
OffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
static QPainter::CompositionMode decodeBlendMode(const QString &s)
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
Label below point, slightly right of center.
void setSize(QSizeF size)
Sets the size of the background shape.
void clear() override
Removes all properties from the collection.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
double mapUnitsPerPixel() const
Returns current map units per pixel.
A store for object properties.
void setRadii(QSizeF radii)
Sets the radii used for rounding the corners of shapes.
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
Implementation of GeometrySimplifier using the "MapToPixel" algorithm.
Point geometry type, with support for z-dimension and m-values.
const QgsMapToPixel & mapToPixel() const
Double value (including negative values)
static QString encodeLinePlacementFlags(pal::LineArrangementFlags flags)
Encodes line placement flags to a string.
Minimum map scale (ie most "zoomed out")
Convert just the first letter of each word to uppercase, leave the rest untouched.
double length() const
Returns the length of geometry using GEOS.
Convert all characters to uppercase.
void setSizeType(SizeType type)
Sets the method used to determine the size of the background shape (e.g., fixed size or buffer around...
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc...
Definition for a property.
QList< QgsLabelPosition > labelsWithinRect(const QgsRectangle &r) const
Returns infos about labels within a given (map) rectangle.
Capitalization
Capitalization options.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
int maxNumLabels
The maximum number of labels which should be drawn for this layer.
void setType(ShapeType type)
Sets the type of background shape to draw (e.g., square, ellipse, SVG).
Place direction symbols on above label.
Draw shadow below all text components.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
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.
QgsExpressionContext & expressionContext()
Gets the expression context.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
Label rotation (deprecated, for old project compatibility only)
static QSizeF decodeSize(const QString &string)
Decodes a QSizeF from a string.
double rotation() const
Returns the rotation for the background shape, in degrees clockwise.
bool plusSign
Whether '+' signs should be prepended to positive numeric labels.
double lineHeight() const
Returns the line height for text.
void setEnabled(bool enabled)
Sets whether the text background will be drawn.
unsigned int placementFlags
int offsetAngle() const
Returns the angle for offsetting the position of the shadow from the text.
QgsWkbTypes::GeometryType geometryGeneratorType
The type of the result geometry of the geometry generator.
void calculateLabelSize(const QFontMetricsF *fm, const QString &text, double &labelX, double &labelY, const QgsFeature *f=nullptr, QgsRenderContext *context=nullptr)
Calculates the space required to render the provided text in map units.
ShapeType
Background shape types.
QString wrapChar
Wrapping character string.
QgsPalLayerSettings & operator=(const QgsPalLayerSettings &s)
copy operator - only copies the permanent members
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...
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Placement
Placement modes which determine how label candidates are generated for a feature. ...
static QString encodePredefinedPositionOrder(const QVector< QgsPalLayerSettings::PredefinedPointPosition > &positions)
Encodes an ordered list of predefined point label positions to a string.
QString rightDirectionSymbol
String to use for right direction arrows.
bool preserveRotation
True if label rotation should be preserved during label pin/unpin operations.
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a string...
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
QgsGeometry simplify(double tolerance) const
Returns a simplified version of this geometry using a specified tolerance value.
QgsExpression * getLabelExpression()
Returns the QgsExpression for this label settings.
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
This class contains information how to simplify geometries fetched from a vector layer.
Contains information about the context of a rendering operation.
Shape rotation is offset from text rotation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
bool centroidWhole
true if feature centroid should be calculated from the whole feature, or false if only the visible pa...
bool scaleVisibility
Set to true to limit label visibility to a range of scales.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the size.
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
static geos::unique_ptr asGeos(const QgsGeometry &geometry, double precision=0)
Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destr...
const QgsFeature * mCurFeat
double getAlpha() const
Returns the angle to rotate text (in rad).
Points (e.g., for font sizes)
Property requires a string value.
bool enabled() const
Returns whether the shadow is enabled.
Mixed case, ie no change.
QgsMapUnitScale distMapUnitScale
Map unit scale for label feature distance.
bool fitInPolygonOnly
true if only labels which completely fit within a polygon are allowed.
Container for settings relating to a text shadow.
QColor color() const
Returns the color of the buffer.
bool conflictsWithObstacle() const
Returns whether the position is marked as conflicting with an obstacle feature.
double getX(int i=0) const
Returns the down-left x coordinate.
double size() const
Returns the size of the buffer.
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
void setMapSettings(const QgsMapSettings &settings)
Sets the map settings associated with the labeling run.
Container for settings relating to a text buffer.
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported...
void setFillColor(const QColor &color)
Sets the color used for filing the background shape.
static bool updateFontViaStyle(QFont &f, const QString &fontstyle, bool fallback=false)
Updates font with named style and retain all font properties.
OffsetType offsetType
Offset type for layer (only applies in certain placement modes)
double dist
Distance from feature to the label.
Label on top of point, slightly right of center.
double size() const
Returns the size for rendered text.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
bool useSubstitutions
True if substitutions should be applied.
This class represents a coordinate reference system (CRS).
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's stroke width.
bool enabled() const
Returns whether the background is enabled.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
static QStringList splitToGraphemes(const QString &text)
Splits a text string to a list of graphemes, which are the smallest allowable character divisions in ...
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
LabelPosition is a candidate feature label position.
bool enabled() const
Returns whether the buffer is enabled.
int scale() const
Returns the scaling used for the drop shadow (in percentage of original size).
Shape rotation is synced with text rotation.
void setShadowPlacement(QgsTextShadowSettings::ShadowPlacement placement)
Sets the placement for the drop shadow.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the text.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
bool limitNumLabels
true if the number of labels drawn should be limited.
Draw shadow under background shape.
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
Convert all characters to lowercase.
void setShadow(const QgsTextShadowSettings &shadowSettings)
Sets the text's drop shadow settings.
bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames, const QgsFields &fields, const QgsMapSettings &mapSettings, const QgsCoordinateReferenceSystem &crs)
Prepare for registration of features.
QgsWkbTypes::GeometryType type
void readXml(const QDomElement &elem)
Reads the collection state from an XML element.
Custom exception class for Coordinate Reference System related exceptions.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
static QVector< QgsPalLayerSettings::PredefinedPointPosition > decodePredefinedPositionOrder(const QString &positionString)
Decodes a string to an ordered list of predefined point label positions.
QString process(const QString &input) const
Processes a given input string, applying any valid replacements which should be made using QgsStringR...
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
QgsPointXY center() const
Returns the center point of the rectangle.
double area() const
Returns the area of the geometry using GEOS.
Y-coordinate data defined label position.
Container for all settings relating to text rendering.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the buffer.
bool centroidInside
true if centroid positioned labels must be placed inside their corresponding feature polygon...
Max scale (deprecated, for old project compatibility only)
bool contains(const QgsPointXY *p) const
Tests for containment of a point (uses GEOS)
void setSvgFile(const QString &file)
Sets the path to the background SVG file.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Represents a vector layer which manages a vector based data sets.
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only...
double minScale
The minimum scale, or 0.0 if unset.
void setOpacity(double opacity)
Sets the buffer opacity.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
Square - buffered sizes only.
QString updateDataDefinedString(const QString &value)
int valueAsInt(int key, const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an integer...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
double minFeatureSize
Minimum feature size (in millimeters) for a feature to be labelled.
Vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top) ...
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
QString namedStyle() const
Returns the named style for the font used for rendering text (e.g., "bold").
QFont font() const
Returns the font used for rendering text.
void setRotationType(RotationType type)
Sets the method used for rotating the background shape.
int fontMinPixelSize
Minimum pixel size for showing rendered map unit labels (1 - 1000).
void setColor(const QColor &color)
Sets the color for the buffer.
int priority
Label priority.
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
bool labelPerPart
true if every part of a multi-part feature should be labeled.
QgsUnitTypes::RenderUnit distUnits
Units the distance from feature to the label.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
bool useMaxLineLengthForAutoWrap
If true, indicates that when auto wrapping label text the autoWrapLength length indicates the maximum...
double opacity() const
Returns the shadow's opacity.
QgsMapUnitScale labelOffsetMapUnitScale
Map unit scale for label offset.
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)...
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
2D size (width/height different)
The QgsMargins class defines the four margins of a rectangle.
void setOpacity(double opacity)
Sets the background shape's opacity.
RenderUnit
Rendering size units.
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
static QColor decodeColor(const QString &str)
Buffer transparency (deprecated)
double height() const
Returns the height of the rectangle.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the label's property collection, used for data defined overrides.
Text transparency (deprecated)
double minimumScale
The minimum map scale (i.e.
QString fieldName
Name of field (or an expression) to use for label text.
bool fontLimitPixelSize
true if label sizes should be limited by pixel size.
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels...
DirectionSymbols placeDirectionSymbol
Placement option for direction symbols.
void setOffsetAngle(int angle)
Sets the angle for offsetting the position of the shadow from the text.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
Color with no alpha channel.
void setRotation(double rotation)
Sets the rotation for the background shape, in degrees clockwise.