35 #include <QApplication> 38 #include <QFontMetrics> 41 #include <QDesktopWidget> 68 #include <QMessageBox> 82 const QVector< QgsPalLayerSettings::PredefinedPointPosition > QgsPalLayerSettings::DEFAULT_PLACEMENT_ORDER
101 void QgsPalLayerSettings::initPropertyDefinitions()
103 if ( !sPropertyDefinitions.isEmpty() )
106 const QString origin = QStringLiteral(
"labeling" );
118 "e.g. Helvetica or Helvetica [Cronyx]" ), origin )
122 "e.g. Bold Condensed or Light Italic" ), origin )
155 "<b>Ellipse</b>|<b>Circle</b>|<b>SVG</b>]" ), origin )
179 "<b>Buffer</b>|<b>Background</b>]" ), origin )
195 "<b>3</b>=Left|<b>4</b>=Over|<b>5</b>=Right|<br>" 196 "<b>6</b>=Below Left|<b>7</b>=Below|<b>8</b>=Below Right]" ), origin )
212 + QStringLiteral(
"[<b>TL</b>=Top left|<b>TSL</b>=Top, slightly left|<b>T</b>=Top middle|<br>" 213 "<b>TSR</b>=Top, slightly right|<b>TR</b>=Top right|<br>" 214 "<b>L</b>=Left|<b>R</b>=Right|<br>" 215 "<b>BL</b>=Bottom left|<b>BSL</b>=Bottom, slightly left|<b>B</b>=Bottom middle|<br>" 216 "<b>BSR</b>=Bottom, slightly right|<b>BR</b>=Bottom right]" ), origin )
220 + QStringLiteral(
"[<b>OL</b>=On line|<b>AL</b>=Above line|<b>BL</b>=Below line|<br>" 221 "<b>LO</b>=Respect line orientation]" ), origin )
228 "<b>Half</b>|<b>Cap</b>|<b>Top</b>]" ), origin )
252 initPropertyDefinitions();
255 isExpression =
false;
258 useSubstitutions =
false;
261 multilineAlign = MultiFollowPlacement;
262 addDirectionSymbol =
false;
263 leftDirectionSymbol = QStringLiteral(
"<" );
264 rightDirectionSymbol = QStringLiteral(
">" );
265 reverseDirectionSymbol =
false;
266 placeDirectionSymbol = SymbolLeftRight;
267 formatNumbers =
false;
272 placement = AroundPoint;
273 placementFlags = AboveLine | MapOrientation;
274 centroidWhole =
false;
275 centroidInside =
false;
276 predefinedPositionOrder = DEFAULT_PLACEMENT_ORDER;
277 fitInPolygonOnly =
false;
278 quadOffset = QuadrantOver;
284 offsetType = FromPoint;
286 preserveRotation =
true;
287 maxCurvedCharAngleIn = 25.0;
288 maxCurvedCharAngleOut = -25.0;
294 scaleVisibility =
false;
297 fontLimitPixelSize =
false;
298 fontMinPixelSize = 0;
299 fontMaxPixelSize = 10000;
301 upsidedownLabels = Upright;
303 labelPerPart =
false;
305 minFeatureSize = 0.0;
306 limitNumLabels =
false;
309 obstacleFactor = 1.0;
310 obstacleType = PolygonInterior;
320 , mDataDefinedProperties( s.mDataDefinedProperties )
407 mDataDefinedProperties = s.mDataDefinedProperties;
409 mCallout.reset( s.mCallout ? s.mCallout->clone() : nullptr );
464 for (
const QString &name : referencedColumns )
466 attributeNames.insert( name );
522 for (
const QString &name : referencedColumns )
524 attributeNames.insert( name );
530 const auto referencedColumns = mCallout->referencedFields( context );
531 for (
const QString &name : referencedColumns )
533 attributeNames.insert( name );
542 if ( mRenderStarted )
544 qWarning(
"Start render called for when a previous render was already underway!!" );
557 mCallout->startRender( context );
560 mRenderStarted =
true;
565 if ( !mRenderStarted )
567 qWarning(
"Stop render called for QgsPalLayerSettings without a startRender call!" );
573 mCallout->stopRender( context );
576 mRenderStarted =
false;
581 if ( mRenderStarted )
583 qWarning(
"stopRender was not called on QgsPalLayerSettings object!" );
594 initPropertyDefinitions();
595 return sPropertyDefinitions;
610 QString newValue = value;
611 if ( !value.isEmpty() && !value.contains( QLatin1String(
"~~" ) ) )
614 values << QStringLiteral(
"1" );
615 values << QStringLiteral(
"0" );
618 newValue = values.join( QStringLiteral(
"~~" ) );
626 QString newPropertyName =
"labeling/dataDefined/" + sPropertyDefinitions.value( p ).name();
627 QVariant newPropertyField = layer->
customProperty( newPropertyName, QVariant() );
629 if ( !newPropertyField.isValid() )
632 QString ddString = newPropertyField.toString();
634 if ( !ddString.isEmpty() && ddString != QLatin1String(
"0~~0~~~~" ) )
638 QStringList ddv = newStyleString.split( QStringLiteral(
"~~" ) );
640 bool active = ddv.at( 0 ).toInt();
641 if ( ddv.at( 1 ).toInt() )
657 void QgsPalLayerSettings::readOldDataDefinedPropertyMap(
QgsVectorLayer *layer, QDomElement *parentElem )
659 if ( !layer && !parentElem )
664 QgsPropertiesDefinition::const_iterator i = sPropertyDefinitions.constBegin();
665 for ( ; i != sPropertyDefinitions.constEnd(); ++i )
670 readOldDataDefinedProperty( layer, static_cast< Property >( i.key() ) );
672 else if ( parentElem )
675 QDomElement e = parentElem->firstChildElement( i.value().name() );
678 bool active = e.attribute( QStringLiteral(
"active" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
679 bool isExpression = e.attribute( QStringLiteral(
"useExpr" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
693 void QgsPalLayerSettings::readFromLayerCustomProperties(
QgsVectorLayer *layer )
695 if ( layer->
customProperty( QStringLiteral(
"labeling" ) ).toString() != QLatin1String(
"pal" ) )
720 QDomDocument doc( QStringLiteral(
"substitutions" ) );
721 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/substitutions" ) ).toString() );
722 QDomElement replacementElem = doc.firstChildElement( QStringLiteral(
"substitutions" ) );
752 if ( layer->
customProperty( QStringLiteral(
"labeling/distMapUnitScale" ) ).toString().isEmpty() )
755 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMinScale" ), 0.0 ).toDouble();
757 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMaxScale" ), 0.0 ).toDouble();
768 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetInMapUnits" ), QVariant(
true ) ).toBool() )
773 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitScale" ) ).toString().isEmpty() )
776 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMinScale" ), 0.0 ).toDouble();
778 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
786 QVariant tempAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant() );
787 if ( tempAngle.isValid() )
789 double oldAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant( 0.0 ) ).toDouble();
802 switch ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceUnit" ), QVariant( 1 ) ).toUInt() )
817 if ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitScale" ) ).toString().isEmpty() )
820 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMinScale" ), 0.0 ).toDouble();
822 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMaxScale" ), 0.0 ).toDouble();
831 double scalemn = layer->
customProperty( QStringLiteral(
"labeling/scaleMin" ), QVariant( 0 ) ).toDouble();
832 double scalemx = layer->
customProperty( QStringLiteral(
"labeling/scaleMax" ), QVariant( 0 ) ).toDouble();
835 QVariant scalevis = layer->
customProperty( QStringLiteral(
"labeling/scaleVisibility" ), QVariant() );
836 if ( scalevis.isValid() )
842 else if ( scalemn > 0 || scalemx > 0 )
869 zIndex = layer->
customProperty( QStringLiteral(
"labeling/zIndex" ), QVariant( 0.0 ) ).toDouble();
871 mDataDefinedProperties.
clear();
872 if ( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).isValid() )
874 QDomDocument doc( QStringLiteral(
"dd" ) );
875 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).toString() );
876 QDomElement elem = doc.firstChildElement( QStringLiteral(
"properties" ) );
877 mDataDefinedProperties.
readXml( elem, sPropertyDefinitions );
882 readOldDataDefinedPropertyMap( layer,
nullptr );
926 QDomElement textStyleElem = elem.firstChildElement( QStringLiteral(
"text-style" ) );
927 fieldName = textStyleElem.attribute( QStringLiteral(
"fieldName" ) );
928 isExpression = textStyleElem.attribute( QStringLiteral(
"isExpression" ) ).toInt();
930 mFormat.
readXml( elem, context );
932 previewBkgrdColor = QColor( textStyleElem.attribute( QStringLiteral(
"previewBkgrdColor" ), QStringLiteral(
"#ffffff" ) ) );
935 useSubstitutions = textStyleElem.attribute( QStringLiteral(
"useSubstitutions" ) ).toInt();
938 QDomElement textFormatElem = elem.firstChildElement( QStringLiteral(
"text-format" ) );
939 wrapChar = textFormatElem.attribute( QStringLiteral(
"wrapChar" ) );
940 autoWrapLength = textFormatElem.attribute( QStringLiteral(
"autoWrapLength" ), QStringLiteral(
"0" ) ).toInt();
941 useMaxLineLengthForAutoWrap = textFormatElem.attribute( QStringLiteral(
"useMaxLineLengthForAutoWrap" ), QStringLiteral(
"1" ) ).toInt();
943 addDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"addDirectionSymbol" ) ).toInt();
944 leftDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"leftDirectionSymbol" ), QStringLiteral(
"<" ) );
945 rightDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"rightDirectionSymbol" ), QStringLiteral(
">" ) );
948 formatNumbers = textFormatElem.attribute( QStringLiteral(
"formatNumbers" ) ).toInt();
949 decimals = textFormatElem.attribute( QStringLiteral(
"decimals" ) ).toInt();
950 plusSign = textFormatElem.attribute( QStringLiteral(
"plussign" ) ).toInt();
953 QDomElement placementElem = elem.firstChildElement( QStringLiteral(
"placement" ) );
954 placement =
static_cast< Placement >( placementElem.attribute( QStringLiteral(
"placement" ) ).toInt() );
955 placementFlags = placementElem.attribute( QStringLiteral(
"placementFlags" ) ).toUInt();
956 centroidWhole = placementElem.attribute( QStringLiteral(
"centroidWhole" ), QStringLiteral(
"0" ) ).toInt();
957 centroidInside = placementElem.attribute( QStringLiteral(
"centroidInside" ), QStringLiteral(
"0" ) ).toInt();
961 fitInPolygonOnly = placementElem.attribute( QStringLiteral(
"fitInPolygonOnly" ), QStringLiteral(
"0" ) ).toInt();
962 dist = placementElem.attribute( QStringLiteral(
"dist" ) ).toDouble();
963 if ( !placementElem.hasAttribute( QStringLiteral(
"distUnits" ) ) )
965 if ( placementElem.attribute( QStringLiteral(
"distInMapUnits" ) ).toInt() )
974 if ( !placementElem.hasAttribute( QStringLiteral(
"distMapUnitScale" ) ) )
977 double oldMin = placementElem.attribute( QStringLiteral(
"distMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
979 double oldMax = placementElem.attribute( QStringLiteral(
"distMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
988 xOffset = placementElem.attribute( QStringLiteral(
"xOffset" ), QStringLiteral(
"0" ) ).toDouble();
989 yOffset = placementElem.attribute( QStringLiteral(
"yOffset" ), QStringLiteral(
"0" ) ).toDouble();
990 if ( !placementElem.hasAttribute( QStringLiteral(
"offsetUnits" ) ) )
998 if ( !placementElem.hasAttribute( QStringLiteral(
"labelOffsetMapUnitScale" ) ) )
1001 double oldMin = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1003 double oldMax = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1011 if ( placementElem.hasAttribute( QStringLiteral(
"angleOffset" ) ) )
1013 double oldAngle = placementElem.attribute( QStringLiteral(
"angleOffset" ), QStringLiteral(
"0" ) ).toDouble();
1018 angleOffset = placementElem.attribute( QStringLiteral(
"rotationAngle" ), QStringLiteral(
"0" ) ).toDouble();
1021 preserveRotation = placementElem.attribute( QStringLiteral(
"preserveRotation" ), QStringLiteral(
"1" ) ).toInt();
1022 maxCurvedCharAngleIn = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleIn" ), QStringLiteral(
"25" ) ).toDouble();
1023 maxCurvedCharAngleOut = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleOut" ), QStringLiteral(
"-25" ) ).toDouble();
1024 priority = placementElem.attribute( QStringLiteral(
"priority" ) ).toInt();
1025 repeatDistance = placementElem.attribute( QStringLiteral(
"repeatDistance" ), QStringLiteral(
"0" ) ).toDouble();
1026 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceUnits" ) ) )
1029 switch ( placementElem.attribute( QStringLiteral(
"repeatDistanceUnit" ), QString::number( 1 ) ).toUInt() )
1049 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceMapUnitScale" ) ) )
1052 double oldMin = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1054 double oldMax = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1062 overrunDistance = placementElem.attribute( QStringLiteral(
"overrunDistance" ), QStringLiteral(
"0" ) ).toDouble();
1066 geometryGenerator = placementElem.attribute( QStringLiteral(
"geometryGenerator" ) );
1073 QDomElement renderingElem = elem.firstChildElement( QStringLiteral(
"rendering" ) );
1075 drawLabels = renderingElem.attribute( QStringLiteral(
"drawLabels" ), QStringLiteral(
"1" ) ).toInt();
1077 maximumScale = renderingElem.attribute( QStringLiteral(
"scaleMin" ), QStringLiteral(
"0" ) ).toDouble();
1078 minimumScale = renderingElem.attribute( QStringLiteral(
"scaleMax" ), QStringLiteral(
"0" ) ).toDouble();
1079 scaleVisibility = renderingElem.attribute( QStringLiteral(
"scaleVisibility" ) ).toInt();
1081 fontLimitPixelSize = renderingElem.attribute( QStringLiteral(
"fontLimitPixelSize" ), QStringLiteral(
"0" ) ).toInt();
1082 fontMinPixelSize = renderingElem.attribute( QStringLiteral(
"fontMinPixelSize" ), QStringLiteral(
"0" ) ).toInt();
1083 fontMaxPixelSize = renderingElem.attribute( QStringLiteral(
"fontMaxPixelSize" ), QStringLiteral(
"10000" ) ).toInt();
1084 displayAll = renderingElem.attribute( QStringLiteral(
"displayAll" ), QStringLiteral(
"0" ) ).toInt();
1087 labelPerPart = renderingElem.attribute( QStringLiteral(
"labelPerPart" ) ).toInt();
1088 mergeLines = renderingElem.attribute( QStringLiteral(
"mergeLines" ) ).toInt();
1089 minFeatureSize = renderingElem.attribute( QStringLiteral(
"minFeatureSize" ) ).toDouble();
1090 limitNumLabels = renderingElem.attribute( QStringLiteral(
"limitNumLabels" ), QStringLiteral(
"0" ) ).toInt();
1091 maxNumLabels = renderingElem.attribute( QStringLiteral(
"maxNumLabels" ), QStringLiteral(
"2000" ) ).toInt();
1092 obstacle = renderingElem.attribute( QStringLiteral(
"obstacle" ), QStringLiteral(
"1" ) ).toInt();
1093 obstacleFactor = renderingElem.attribute( QStringLiteral(
"obstacleFactor" ), QStringLiteral(
"1" ) ).toDouble();
1095 zIndex = renderingElem.attribute( QStringLiteral(
"zIndex" ), QStringLiteral(
"0.0" ) ).toDouble();
1097 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"dd_properties" ) );
1098 if ( !ddElem.isNull() )
1100 mDataDefinedProperties.
readXml( ddElem, sPropertyDefinitions );
1105 mDataDefinedProperties.
clear();
1106 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"data-defined" ) );
1107 readOldDataDefinedPropertyMap(
nullptr, &ddElem );
1148 const QString calloutType = elem.attribute( QStringLiteral(
"calloutType" ) );
1149 if ( calloutType.isEmpty() )
1161 QDomElement textStyleElem = mFormat.
writeXml( doc, context );
1164 textStyleElem.setAttribute( QStringLiteral(
"fieldName" ),
fieldName );
1165 textStyleElem.setAttribute( QStringLiteral(
"isExpression" ),
isExpression );
1166 QDomElement replacementElem = doc.createElement( QStringLiteral(
"substitutions" ) );
1168 textStyleElem.appendChild( replacementElem );
1169 textStyleElem.setAttribute( QStringLiteral(
"useSubstitutions" ),
useSubstitutions );
1172 QDomElement textFormatElem = doc.createElement( QStringLiteral(
"text-format" ) );
1173 textFormatElem.setAttribute( QStringLiteral(
"wrapChar" ),
wrapChar );
1174 textFormatElem.setAttribute( QStringLiteral(
"autoWrapLength" ),
autoWrapLength );
1176 textFormatElem.setAttribute( QStringLiteral(
"multilineAlign" ), static_cast< unsigned int >(
multilineAlign ) );
1177 textFormatElem.setAttribute( QStringLiteral(
"addDirectionSymbol" ),
addDirectionSymbol );
1178 textFormatElem.setAttribute( QStringLiteral(
"leftDirectionSymbol" ),
leftDirectionSymbol );
1181 textFormatElem.setAttribute( QStringLiteral(
"placeDirectionSymbol" ), static_cast< unsigned int >(
placeDirectionSymbol ) );
1182 textFormatElem.setAttribute( QStringLiteral(
"formatNumbers" ),
formatNumbers );
1183 textFormatElem.setAttribute( QStringLiteral(
"decimals" ),
decimals );
1184 textFormatElem.setAttribute( QStringLiteral(
"plussign" ),
plusSign );
1187 QDomElement placementElem = doc.createElement( QStringLiteral(
"placement" ) );
1188 placementElem.setAttribute( QStringLiteral(
"placement" ),
placement );
1189 placementElem.setAttribute( QStringLiteral(
"placementFlags" ), static_cast< unsigned int >(
placementFlags ) );
1190 placementElem.setAttribute( QStringLiteral(
"centroidWhole" ),
centroidWhole );
1191 placementElem.setAttribute( QStringLiteral(
"centroidInside" ),
centroidInside );
1193 placementElem.setAttribute( QStringLiteral(
"fitInPolygonOnly" ),
fitInPolygonOnly );
1194 placementElem.setAttribute( QStringLiteral(
"dist" ),
dist );
1197 placementElem.setAttribute( QStringLiteral(
"offsetType" ), static_cast< unsigned int >(
offsetType ) );
1198 placementElem.setAttribute( QStringLiteral(
"quadOffset" ), static_cast< unsigned int >(
quadOffset ) );
1199 placementElem.setAttribute( QStringLiteral(
"xOffset" ),
xOffset );
1200 placementElem.setAttribute( QStringLiteral(
"yOffset" ),
yOffset );
1203 placementElem.setAttribute( QStringLiteral(
"rotationAngle" ),
angleOffset );
1204 placementElem.setAttribute( QStringLiteral(
"preserveRotation" ),
preserveRotation );
1207 placementElem.setAttribute( QStringLiteral(
"priority" ),
priority );
1208 placementElem.setAttribute( QStringLiteral(
"repeatDistance" ),
repeatDistance );
1211 placementElem.setAttribute( QStringLiteral(
"overrunDistance" ),
overrunDistance );
1215 placementElem.setAttribute( QStringLiteral(
"geometryGenerator" ),
geometryGenerator );
1217 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWkbTypes::GeometryType>() );
1218 placementElem.setAttribute( QStringLiteral(
"geometryGeneratorType" ), metaEnum.valueToKey(
geometryGeneratorType ) );
1220 placementElem.setAttribute( QStringLiteral(
"layerType" ), metaEnum.valueToKey(
layerType ) );
1223 QDomElement renderingElem = doc.createElement( QStringLiteral(
"rendering" ) );
1224 renderingElem.setAttribute( QStringLiteral(
"drawLabels" ),
drawLabels );
1225 renderingElem.setAttribute( QStringLiteral(
"scaleVisibility" ),
scaleVisibility );
1226 renderingElem.setAttribute( QStringLiteral(
"scaleMin" ),
maximumScale );
1227 renderingElem.setAttribute( QStringLiteral(
"scaleMax" ),
minimumScale );
1228 renderingElem.setAttribute( QStringLiteral(
"fontLimitPixelSize" ),
fontLimitPixelSize );
1229 renderingElem.setAttribute( QStringLiteral(
"fontMinPixelSize" ),
fontMinPixelSize );
1230 renderingElem.setAttribute( QStringLiteral(
"fontMaxPixelSize" ),
fontMaxPixelSize );
1231 renderingElem.setAttribute( QStringLiteral(
"displayAll" ),
displayAll );
1232 renderingElem.setAttribute( QStringLiteral(
"upsidedownLabels" ), static_cast< unsigned int >(
upsidedownLabels ) );
1234 renderingElem.setAttribute( QStringLiteral(
"labelPerPart" ),
labelPerPart );
1235 renderingElem.setAttribute( QStringLiteral(
"mergeLines" ),
mergeLines );
1236 renderingElem.setAttribute( QStringLiteral(
"minFeatureSize" ),
minFeatureSize );
1237 renderingElem.setAttribute( QStringLiteral(
"limitNumLabels" ),
limitNumLabels );
1238 renderingElem.setAttribute( QStringLiteral(
"maxNumLabels" ),
maxNumLabels );
1239 renderingElem.setAttribute( QStringLiteral(
"obstacle" ),
obstacle );
1240 renderingElem.setAttribute( QStringLiteral(
"obstacleFactor" ),
obstacleFactor );
1241 renderingElem.setAttribute( QStringLiteral(
"obstacleType" ), static_cast< unsigned int >(
obstacleType ) );
1242 renderingElem.setAttribute( QStringLiteral(
"zIndex" ),
zIndex );
1244 QDomElement ddElem = doc.createElement( QStringLiteral(
"dd_properties" ) );
1245 mDataDefinedProperties.
writeXml( ddElem, sPropertyDefinitions );
1247 QDomElement elem = doc.createElement( QStringLiteral(
"settings" ) );
1248 elem.appendChild( textStyleElem );
1249 elem.appendChild( textFormatElem );
1250 elem.appendChild( placementElem );
1251 elem.appendChild( renderingElem );
1252 elem.appendChild( ddElem );
1256 elem.setAttribute( QStringLiteral(
"calloutType" ), mCallout->type() );
1257 mCallout->saveProperties( doc, elem, context );
1265 mCallout.reset( callout );
1272 QPixmap pixmap( size );
1273 pixmap.fill( Qt::transparent );
1275 painter.begin( &pixmap );
1277 painter.setRenderHint( QPainter::Antialiasing );
1279 QRect rect( 0, 0, size.width(), size.height() );
1282 painter.setPen( Qt::NoPen );
1284 if ( ( background1.lightnessF() < 0.7 ) )
1286 background1 = background1.darker( 125 );
1290 background1 = background1.lighter( 125 );
1293 QLinearGradient linearGrad( QPointF( 0, 0 ), QPointF( 0, rect.height() ) );
1294 linearGrad.setColorAt( 0, background1 );
1295 linearGrad.setColorAt( 1, background2 );
1296 painter.setBrush( QBrush( linearGrad ) );
1297 if ( size.width() > 30 )
1299 painter.drawRoundedRect( rect, 6, 6 );
1304 painter.drawRect( rect );
1306 painter.setBrush( Qt::NoBrush );
1307 painter.setPen( Qt::NoPen );
1315 context.
setScaleFactor( QgsApplication::desktop()->logicalDpiX() / 25.4 );
1326 double ytrans = 0.0;
1332 const QStringList text = QStringList() << ( previewText.isEmpty() ? QObject::tr(
"Aa" ) : previewText );
1334 QRectF textRect = rect;
1335 textRect.setLeft( xtrans + padding );
1336 textRect.setWidth( rect.width() - xtrans - 2 * padding );
1338 if ( textRect.width() > 2000 )
1339 textRect.setWidth( 2000 - 2 * padding );
1341 const double bottom = textRect.height() / 2 + textHeight / 2;
1342 textRect.setTop( bottom - textHeight );
1343 textRect.setBottom( bottom );
1354 QRectF labelRect( textRect.left() + ( textRect.width() - textWidth ) / 2.0, textRect.top(), textWidth, textRect.height() );
1361 if ( size.width() > 30 )
1366 rect.width() - iconWidth * 3, rect.height() - iconWidth * 3,
1367 iconWidth * 2, iconWidth * 2 ), Qt::AlignRight | Qt::AlignBottom );
1371 painter.setBrush( Qt::NoBrush );
1373 if ( size.width() > 30 )
1375 painter.drawRoundedRect( rect, 6, 6 );
1380 painter.drawRect( rect );
1389 return QgsPalLabeling::checkMinimumSizeMM( ct, geom, minSize );
1399 QString textCopy( text );
1402 std::unique_ptr< QgsRenderContext > scopedRc;
1407 scopedRc->expressionContext().setFeature( *f );
1523 if ( wrapchr.isEmpty() )
1525 wrapchr = QStringLiteral(
"\n" );
1530 && ( !leftDirSymb.isEmpty() || !rightDirSymb.isEmpty() ) )
1532 QString dirSym = leftDirSymb;
1534 if ( fm->width( rightDirSymb ) > fm->width( dirSym ) )
1535 dirSym = rightDirSymb;
1539 textCopy.append( dirSym );
1543 textCopy.prepend( dirSym + QStringLiteral(
"\n" ) );
1547 double w = 0.0, h = 0.0, rw = 0.0, rh = 0.0;
1548 double labelHeight = fm->ascent() + fm->descent();
1550 int lines = multiLineSplit.size();
1552 switch ( orientation )
1556 h += fm->height() +
static_cast< double >( ( lines - 1 ) * labelHeight * multilineH );
1558 for (
const auto &line : multiLineSplit )
1560 w = std::max( w, fm->width( line ) );
1567 double letterSpacing = mFormat.
scaledFont( *context ).letterSpacing();
1568 double labelWidth = fm->maxWidth();
1569 w = labelWidth + ( lines - 1 ) * labelWidth * multilineH;
1571 int maxLineLength = 0;
1572 for (
const auto &line : multiLineSplit )
1574 maxLineLength = std::max( maxLineLength, line.length() );
1576 h = fm->ascent() * maxLineLength + ( maxLineLength - 1 ) * letterSpacing;
1582 double widthHorizontal = 0.0;
1583 for (
const auto &line : multiLineSplit )
1585 widthHorizontal = std::max( w, fm->width( line ) );
1588 double widthVertical = 0.0;
1589 double letterSpacing = mFormat.
scaledFont( *context ).letterSpacing();
1590 double labelWidth = fm->maxWidth();
1591 widthVertical = labelWidth + ( lines - 1 ) * labelWidth * multilineH;
1593 double heightHorizontal = 0.0;
1594 heightHorizontal += fm->height() +
static_cast< double >( ( lines - 1 ) * labelHeight * multilineH );
1596 double heightVertical = 0.0;
1597 int maxLineLength = 0;
1598 for (
const auto &line : multiLineSplit )
1600 maxLineLength = std::max( maxLineLength, line.length() );
1602 heightVertical = fm->ascent() * maxLineLength + ( maxLineLength - 1 ) * letterSpacing;
1604 w = widthHorizontal;
1605 rw = heightVertical;
1606 h = heightHorizontal;
1614 labelX = std::fabs( ptSize.
x() -
ptZero.
x() );
1615 labelY = std::fabs( ptSize.
y() -
ptZero.
y() );
1620 if ( rotatedLabelX && rotatedLabelY )
1622 *rotatedLabelX = rw * uPP;
1623 *rotatedLabelY = rh * uPP;
1631 Q_ASSERT( labelFeature );
1645 registerObstacleFeature( f, context, labelFeature, obstacleGeometry );
1657 if ( obstacleGeometry.
isNull() )
1670 dataDefinedValues.clear();
1687 if ( useScaleVisibility )
1700 maxScale = 1 / std::fabs( maxScale );
1719 minScale = 1 / std::fabs( minScale );
1728 QFont labelFont = mFormat.
font();
1734 if ( exprVal.isValid() )
1736 QString units = exprVal.toString();
1737 if ( !units.isEmpty() )
1747 double fontSize = mFormat.
size();
1753 if ( fontSize <= 0.0 )
1760 if ( fontPixelSize < 1 )
1764 labelFont.setPixelSize( fontPixelSize );
1776 if ( fontMinPixel > labelFont.pixelSize() || labelFont.pixelSize() > fontMaxPixel )
1788 labelFont.setCapitalization( QFont::MixedCase );
1791 parseTextStyle( labelFont, fontunits, context );
1792 parseTextFormatting( context );
1793 parseTextBuffer( context );
1794 parseShapeBackground( context );
1795 parseDropShadow( context );
1816 labelText = result.isNull() ? QString() : result.toString();
1821 labelText = v.isNull() ? QString() : v.toString();
1833 if ( mFormat.
font().capitalization() != QFont::MixedCase )
1841 if ( exprVal.isValid() )
1843 QString fcase = exprVal.toString().trimmed();
1844 QgsDebugMsgLevel( QStringLiteral(
"exprVal FontCase:%1" ).arg( fcase ), 4 );
1846 if ( !fcase.isEmpty() )
1848 if ( fcase.compare( QLatin1String(
"NoChange" ), Qt::CaseInsensitive ) == 0 )
1852 else if ( fcase.compare( QLatin1String(
"Upper" ), Qt::CaseInsensitive ) == 0 )
1856 else if ( fcase.compare( QLatin1String(
"Lower" ), Qt::CaseInsensitive ) == 0 )
1860 else if ( fcase.compare( QLatin1String(
"Capitalize" ), Qt::CaseInsensitive ) == 0 )
1875 if ( evalFormatNumbers )
1879 if ( decimalPlaces <= 0 )
1885 QVariant textV( labelText );
1887 double d = textV.toDouble( &ok );
1890 QString numberFormat;
1891 if ( d > 0 && signPlus )
1893 numberFormat.append(
'+' );
1895 numberFormat.append(
"%1" );
1896 labelText = numberFormat.arg( d, 0,
'f', decimalPlaces );
1901 std::unique_ptr<QFontMetricsF> labelFontMetrics(
new QFontMetricsF( labelFont ) );
1902 double labelX, labelY, rotatedLabelX, rotatedLabelY;
1908 double maxcharanglein = 20.0;
1909 double maxcharangleout = -20.0;
1924 maxcharanglein = qBound( 20.0, static_cast< double >( maxcharanglePt.x() ), 60.0 );
1925 maxcharangleout = qBound( 20.0, static_cast< double >( maxcharanglePt.y() ), 95.0 );
1929 maxcharangleout = -( std::fabs( maxcharangleout ) );
1937 if ( exprVal.isValid() )
1939 QString str = exprVal.toString().trimmed();
1940 QgsDebugMsgLevel( QStringLiteral(
"exprVal CentroidWhole:%1" ).arg( str ), 4 );
1942 if ( !str.isEmpty() )
1944 if ( str.compare( QLatin1String(
"Visible" ), Qt::CaseInsensitive ) == 0 )
1946 wholeCentroid =
false;
1948 else if ( str.compare( QLatin1String(
"Whole" ), Qt::CaseInsensitive ) == 0 )
1950 wholeCentroid =
true;
1964 std::unique_ptr<QgsGeometry> scopedClonedGeom;
1971 geom = simplifier.
simplify( geom );
1981 bool doClip =
false;
1982 if ( !centroidPoly || !wholeCentroid )
1992 permissibleZone = geom;
2028 if ( !geos_geom_clone )
2057 if ( isObstacle && !obstacleGeometry.
isNull() )
2064 bool dataDefinedPosition =
false;
2065 bool layerDefinedRotation =
false;
2066 bool dataDefinedRotation =
false;
2067 double xPos = 0.0, yPos = 0.0,
angle = 0.0;
2068 bool ddXPos =
false, ddYPos =
false;
2069 double quadOffsetX = 0.0, quadOffsetY = 0.0;
2070 double offsetX = 0.0, offsetY = 0.0;
2073 bool ddFixedQuad =
false;
2077 context.expressionContext().setOriginalValueVariable( static_cast< int >( quadOff ) );
2079 if ( exprVal.isValid() )
2082 int quadInt = exprVal.toInt( &ok );
2083 if ( ok && 0 <= quadInt && quadInt <= 8 )
2151 if ( exprVal.isValid() )
2153 QString units = exprVal.toString().trimmed();
2154 if ( !units.isEmpty() )
2160 offUnit = decodedUnits;
2176 layerDefinedRotation =
true;
2184 context.expressionContext().setOriginalValueVariable(
angleOffset );
2186 if ( exprVal.isValid() )
2189 double rotD = exprVal.toDouble( &ok );
2192 dataDefinedRotation =
true;
2196 angle = ( 360 - rotD ) * M_PI / 180.0;
2204 if ( exprVal.isValid() )
2206 if ( !exprVal.isNull() )
2207 xPos = exprVal.toDouble( &ddXPos );
2212 if ( exprVal.isValid() )
2215 if ( !exprVal.isNull() )
2216 yPos = exprVal.toDouble( &ddYPos );
2218 if ( ddXPos && ddYPos )
2220 dataDefinedPosition =
true;
2222 if ( layerDefinedRotation && !dataDefinedRotation )
2235 if ( exprVal.isValid() )
2237 QString haliString = exprVal.toString();
2238 if ( haliString.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
2240 xdiff -= labelX / 2.0;
2242 else if ( haliString.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
2253 if ( exprVal.isValid() )
2255 QString valiString = exprVal.toString();
2256 if ( valiString.compare( QLatin1String(
"Bottom" ), Qt::CaseInsensitive ) != 0 )
2258 if ( valiString.compare( QLatin1String(
"Top" ), Qt::CaseInsensitive ) == 0 )
2264 double descentRatio = labelFontMetrics->descent() / labelFontMetrics->height();
2265 if ( valiString.compare( QLatin1String(
"Base" ), Qt::CaseInsensitive ) == 0 )
2267 ydiff -= labelY * descentRatio;
2271 double capHeightRatio = ( labelFontMetrics->boundingRect(
'H' ).height() + 1 + labelFontMetrics->descent() ) / labelFontMetrics->height();
2272 ydiff -= labelY * capHeightRatio;
2273 if ( valiString.compare( QLatin1String(
"Half" ), Qt::CaseInsensitive ) == 0 )
2275 ydiff += labelY * ( capHeightRatio - descentRatio ) / 2.0;
2283 if ( dataDefinedRotation )
2286 double xd = xdiff * std::cos(
angle ) - ydiff * std::sin(
angle );
2287 double yd = xdiff * std::sin(
angle ) + ydiff * std::cos(
angle );
2318 bool alwaysShow =
false;
2329 context.expressionContext().setOriginalValueVariable( repeatDist );
2338 if ( exprVal.isValid() )
2340 QString units = exprVal.toString().trimmed();
2341 if ( !units.isEmpty() )
2347 repeatUnits = decodedUnits;
2365 context.expressionContext().setOriginalValueVariable( overrunDistanceEval );
2379 if ( !dataDefinedPosition )
2383 context.expressionContext().setOriginalValueVariable(
labelPerPart );
2398 ( *labelFeature )->setFixedPosition(
QgsPointXY( xPos, yPos ) );
2400 ( *labelFeature )->setHasFixedAngle( dataDefinedRotation || ( !dataDefinedPosition && !
qgsDoubleNear(
angle, 0.0 ) ) );
2401 ( *labelFeature )->setFixedAngle(
angle );
2402 ( *labelFeature )->setQuadOffset( QPointF( quadOffsetX, quadOffsetY ) );
2403 ( *labelFeature )->setPositionOffset(
QgsPointXY( offsetX, offsetY ) );
2404 ( *labelFeature )->setOffsetType(
offsetType );
2405 ( *labelFeature )->setAlwaysShow( alwaysShow );
2406 ( *labelFeature )->setRepeatDistance( repeatDist );
2407 ( *labelFeature )->setLabelText( labelText );
2408 ( *labelFeature )->setPermissibleZone( permissibleZone );
2409 ( *labelFeature )->setOverrunDistance( overrunDistanceEval );
2410 ( *labelFeature )->setOverrunSmoothDistance( overrunSmoothDist );
2411 ( *labelFeature )->setLabelAllParts( labelAll );
2412 if ( geosObstacleGeomClone )
2414 ( *labelFeature )->setObstacleGeometry( std::move( geosObstacleGeomClone ) );
2419 ( *labelFeature )->setSymbolSize( QSizeF( obstacleGeometry.
boundingBox().
width(),
2426 double topMargin = std::max( 0.25 * labelFontMetrics->ascent(), 0.0 );
2427 double bottomMargin = 1.0 + labelFontMetrics->descent();
2428 QgsMargins vm( 0.0, topMargin, 0.0, bottomMargin );
2430 ( *labelFeature )->setVisualMargin( vm );
2433 QgsDebugMsgLevel( QStringLiteral(
"PAL font stored definedFont: %1, Style: %2" ).arg( labelFont.toString(), labelFont.styleName() ), 4 );
2439 labelFontMetrics.get(),
xform, maxcharanglein, maxcharangleout );
2445 double distance =
dist;
2448 context.expressionContext().setOriginalValueVariable( distance );
2457 if ( exprVal.isValid() )
2459 QString units = exprVal.toString().trimmed();
2460 QgsDebugMsgLevel( QStringLiteral(
"exprVal DistanceUnits:%1" ).arg( units ), 4 );
2461 if ( !units.isEmpty() )
2467 distUnit = decodedUnits;
2472 distance = context.convertToPainterUnits( distance, distUnit,
distMapUnitScale );
2478 distance = ( distance < 0 ? -1 : 1 ) * std::max( std::fabs( distance ), 1.0 );
2484 ( *labelFeature )->setDistLabel( d );
2489 ( *labelFeature )->setHasFixedQuadrant(
true );
2492 pal::LineArrangementFlags featureArrangementFlags =
static_cast< pal::LineArrangementFlags
>(
placementFlags );
2497 if ( !dataDefinedLineArrangement.isEmpty() )
2502 ( *labelFeature )->setArrangementFlags( featureArrangementFlags );
2508 context.expressionContext().setOriginalValueVariable( z );
2511 ( *labelFeature )->setZIndex( z );
2516 context.expressionContext().setOriginalValueVariable(
priority );
2518 if ( exprVal.isValid() )
2521 double priorityD = exprVal.toDouble( &ok );
2524 priorityD = qBound( 0.0, priorityD, 10.0 );
2525 priorityD = 1 - priorityD / 10.0;
2526 ( *labelFeature )->setPriority( priorityD );
2531 ( *labelFeature )->setIsObstacle( isObstacle );
2536 context.expressionContext().setOriginalValueVariable( featObstacleFactor );
2538 if ( exprVal.isValid() )
2541 double factorD = exprVal.toDouble( &ok );
2544 factorD = qBound( 0.0, factorD, 10.0 );
2545 factorD = factorD / 5.0 + 0.0001;
2546 featObstacleFactor = factorD;
2550 ( *labelFeature )->setObstacleFactor( featObstacleFactor );
2553 if ( positionOrder.isEmpty() )
2554 positionOrder = QgsPalLayerSettings::DEFAULT_PLACEMENT_ORDER;
2560 if ( !dataDefinedOrder.isEmpty() )
2565 ( *labelFeature )->setPredefinedPositionOrder( positionOrder );
2576 if ( !obstacleGeometry.
isNull() )
2578 geom = obstacleGeometry;
2592 std::unique_ptr<QgsGeometry> scopedClonedGeom;
2598 geom = simplifier.
simplify( geom );
2602 std::unique_ptr<QgsGeometry> scopedPreparedGeom;
2610 if ( !geos_geom_clone )
2614 *obstacleFeature =
new QgsLabelFeature( f.
id(), std::move( geos_geom_clone ), QSizeF( 0, 0 ) );
2616 ( *obstacleFeature )->setFeature( f );
2620 bool QgsPalLayerSettings::dataDefinedValEval( DataDefinedValueType valType,
2624 if ( !mDataDefinedProperties.
isActive( p ) )
2628 exprVal = mDataDefinedProperties.
value( p, context );
2629 if ( exprVal.isValid() )
2635 bool bol = exprVal.toBool();
2636 dataDefinedValues.insert( p, QVariant( bol ) );
2642 int size = exprVal.toInt( &ok );
2646 dataDefinedValues.insert( p, QVariant( size ) );
2654 int size = exprVal.toInt( &ok );
2656 if ( ok && size > 0 )
2658 dataDefinedValues.insert( p, QVariant( size ) );
2666 double size = exprVal.toDouble( &ok );
2670 dataDefinedValues.insert( p, QVariant( size ) );
2678 double size = exprVal.toDouble( &ok );
2680 if ( ok && size > 0.0 )
2682 dataDefinedValues.insert( p, QVariant( size ) );
2690 double rot = exprVal.toDouble( &ok );
2693 if ( rot < -180.0 && rot >= -360 )
2697 if ( rot > 180.0 && rot <= 360 )
2701 if ( rot >= -180 && rot <= 180 )
2703 dataDefinedValues.insert( p, QVariant( rot ) );
2712 int size = exprVal.toInt( &ok );
2713 if ( ok && size >= 0 && size <= 100 )
2715 dataDefinedValues.insert( p, QVariant( size ) );
2722 QString str = exprVal.toString();
2724 dataDefinedValues.insert( p, QVariant( str ) );
2729 QString unitstr = exprVal.toString().trimmed();
2731 if ( !unitstr.isEmpty() )
2740 QString colorstr = exprVal.toString().trimmed();
2743 if ( color.isValid() )
2745 dataDefinedValues.insert( p, QVariant( color ) );
2752 QString joinstr = exprVal.toString().trimmed();
2754 if ( !joinstr.isEmpty() )
2763 QString blendstr = exprVal.toString().trimmed();
2765 if ( !blendstr.isEmpty() )
2778 dataDefinedValues.insert( p, res );
2789 dataDefinedValues.insert( p, res );
2799 void QgsPalLayerSettings::parseTextStyle( QFont &labelFont,
2812 QString ddFontFamily;
2817 if ( exprVal.isValid() )
2819 QString family = exprVal.toString().trimmed();
2820 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font family:%1" ).arg( family ), 4 );
2822 if ( labelFont.family() != family )
2828 ddFontFamily = family;
2835 QString ddFontStyle;
2839 if ( exprVal.isValid() )
2841 QString fontstyle = exprVal.toString().trimmed();
2842 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font style:%1" ).arg( fontstyle ), 4 );
2843 ddFontStyle = fontstyle;
2848 bool ddBold =
false;
2856 bool ddItalic =
false;
2866 QFont appFont = QApplication::font();
2867 bool newFontBuilt =
false;
2868 if ( ddBold || ddItalic )
2871 newFont = QFont( !ddFontFamily.isEmpty() ? ddFontFamily : labelFont.family() );
2872 newFontBuilt =
true;
2873 newFont.setBold( ddBold );
2874 newFont.setItalic( ddItalic );
2876 else if ( !ddFontStyle.isEmpty()
2877 && ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2879 if ( !ddFontFamily.isEmpty() )
2882 QFont styledfont = mFontDB.font( ddFontFamily, ddFontStyle, appFont.pointSize() );
2883 if ( appFont != styledfont )
2885 newFont = styledfont;
2886 newFontBuilt =
true;
2893 else if ( !ddFontFamily.isEmpty() )
2895 if ( ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2898 QFont styledfont = mFontDB.font( ddFontFamily, mFormat.
namedStyle(), appFont.pointSize() );
2899 if ( appFont != styledfont )
2901 newFont = styledfont;
2902 newFontBuilt =
true;
2907 newFont = QFont( ddFontFamily );
2908 newFontBuilt =
true;
2916 newFont.setPixelSize( labelFont.pixelSize() );
2917 newFont.setUnderline( labelFont.underline() );
2918 newFont.setStrikeOut( labelFont.strikeOut() );
2919 newFont.setWordSpacing( labelFont.wordSpacing() );
2920 newFont.setLetterSpacing( QFont::AbsoluteSpacing, labelFont.letterSpacing() );
2922 labelFont = newFont;
2928 double wordspace = labelFont.wordSpacing();
2937 double letterspace = labelFont.letterSpacing();
2948 labelFont.setStrikeOut( strikeout );
2956 labelFont.setUnderline( underline );
2982 drawBuffer = exprVal.toBool();
2991 double bufrSize = buffer.
size();
2994 bufrSize = exprVal.toDouble();
2998 double bufferOpacity = buffer.
opacity() * 100;
3001 bufferOpacity = exprVal.toDouble();
3004 drawBuffer = ( drawBuffer && bufrSize > 0.0 && bufferOpacity > 0 );
3035 wrapchr = exprVal.toString();
3041 evalAutoWrapLength = exprVal.toInt();
3052 if ( exprVal.isValid() )
3054 QString str = exprVal.toString().trimmed();
3055 QgsDebugMsgLevel( QStringLiteral(
"exprVal MultiLineAlignment:%1" ).arg( str ), 4 );
3057 if ( !str.isEmpty() )
3062 if ( str.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
3066 else if ( str.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
3070 else if ( str.compare( QLatin1String(
"Follow" ), Qt::CaseInsensitive ) == 0 )
3085 if ( exprVal.isValid() )
3087 QString str = exprVal.toString().trimmed();
3088 if ( !str.isEmpty() )
3097 drawDirSymb = exprVal.toBool();
3110 if ( exprVal.isValid() )
3112 QString str = exprVal.toString().trimmed();
3113 QgsDebugMsgLevel( QStringLiteral(
"exprVal DirSymbPlacement:%1" ).arg( str ), 4 );
3115 if ( !str.isEmpty() )
3120 if ( str.compare( QLatin1String(
"Above" ), Qt::CaseInsensitive ) == 0 )
3124 else if ( str.compare( QLatin1String(
"Below" ), Qt::CaseInsensitive ) == 0 )
3139 void QgsPalLayerSettings::parseShapeBackground(
QgsRenderContext &context )
3146 bool drawShape = background.
enabled();
3149 drawShape = exprVal.toBool();
3158 double shapeOpacity = background.
opacity() * 100;
3161 shapeOpacity = 100.0 * exprVal.toDouble();
3164 drawShape = ( drawShape && shapeOpacity > 0 );
3178 if ( exprVal.isValid() )
3180 QString skind = exprVal.toString().trimmed();
3181 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeKind:%1" ).arg( skind ), 4 );
3183 if ( !skind.isEmpty() )
3192 QString svgPath = background.
svgFile();
3197 if ( exprVal.isValid() )
3199 QString svgfile = exprVal.toString().trimmed();
3200 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSVGFile:%1" ).arg( svgfile ), 4 );
3213 if ( exprVal.isValid() )
3215 QString stype = exprVal.toString().trimmed();
3216 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSizeType:%1" ).arg( stype ), 4 );
3218 if ( !stype.isEmpty() )
3227 double ddShpSizeX = background.
size().width();
3230 ddShpSizeX = exprVal.toDouble();
3234 double ddShpSizeY = background.
size().height();
3237 ddShpSizeY = exprVal.toDouble();
3243 && ( svgPath.isEmpty()
3244 || ( !svgPath.isEmpty()
3246 && ddShpSizeX == 0.0 ) ) )
3254 && ddShpSizeX == 0.0 ) ) )
3261 && ( ddShpSizeX == 0.0 || ddShpSizeY == 0.0 ) )
3284 if ( exprVal.isValid() )
3286 QString rotstr = exprVal.toString().trimmed();
3287 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeRotationType:%1" ).arg( rotstr ), 4 );
3289 if ( !rotstr.isEmpty() )
3340 bool drawShadow = shadow.
enabled();
3343 drawShadow = exprVal.toBool();
3352 double shadowOpacity = shadow.
opacity() * 100;
3355 shadowOpacity = exprVal.toDouble();
3362 shadowOffDist = exprVal.toDouble();
3369 shadowRad = exprVal.toDouble();
3372 drawShadow = ( drawShadow && shadowOpacity > 0 && !( shadowOffDist == 0.0 && shadowRad == 0.0 ) );
3387 if ( exprVal.isValid() )
3389 QString str = exprVal.toString().trimmed();
3390 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShadowUnder:%1" ).arg( str ), 4 );
3392 if ( !str.isEmpty() )
3465 QStringList multiLineSplit;
3466 if ( !wrapCharacter.isEmpty() && wrapCharacter != QLatin1String(
"\n" ) )
3469 const QStringList lines = text.split( wrapCharacter );
3470 for (
const QString &line : lines )
3472 multiLineSplit.append( line.split(
'\n' ) );
3477 multiLineSplit = text.split(
'\n' );
3481 if ( autoWrapLength != 0 )
3483 QStringList autoWrappedLines;
3484 autoWrappedLines.reserve( multiLineSplit.count() );
3485 for (
const QString &line : qgis::as_const( multiLineSplit ) )
3487 autoWrappedLines.append(
QgsStringUtils::wordWrap( line, autoWrapLength, useMaxLineLengthWhenAutoWrapping ).split(
'\n' ) );
3489 multiLineSplit = autoWrappedLines;
3491 return multiLineSplit;
3496 QStringList graphemes;
3497 QTextBoundaryFinder boundaryFinder( QTextBoundaryFinder::Grapheme, text );
3498 int currentBoundary = -1;
3499 int previousBoundary = 0;
3500 while ( ( currentBoundary = boundaryFinder.toNextBoundary() ) > 0 )
3502 graphemes << text.mid( previousBoundary, currentBoundary - previousBoundary );
3503 previousBoundary = currentBoundary;
3533 QgsDebugMsgLevel( QStringLiteral(
"Ignoring feature due to transformation exception" ), 4 );
3539 return std::isfinite( point.
x() ) && std::isfinite( point.
y() );
3542 cp->removeInvalidRings();
3552 QgsDebugMsg( QStringLiteral(
"Error rotating geometry" ).arg( geom.
asWkt() ) );
3566 QVector< QgsGeometry> parts;
3567 parts.reserve( qgsgeometry_cast< const QgsGeometryCollection * >( geom.
constGet() )->numGeometries() );
3571 if ( !partGeom.isGeosValid() )
3573 partGeom = partGeom.
buffer( 0, 0 );
3575 parts.append( partGeom );
3582 if ( bufferGeom.
isNull() )
3584 QgsDebugMsg( QStringLiteral(
"Could not repair geometry: %1" ).arg( bufferGeom.
lastError() ) );
3591 if ( !clipGeometry.
isNull() &&
3627 double length = geom.
length();
3628 if ( length >= 0.0 )
3630 return ( length >= ( minSize * mapUnitsPerMM ) );
3635 double area = geom.
area();
3638 return ( std::sqrt( area ) >= ( minSize * mapUnitsPerMM ) );
3646 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3649 bool changed =
false;
3655 format.
setColor( ddColor.value<QColor>() );
3680 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3742 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3745 bool changed =
false;
3793 buffer.
setColor( ddColor.value<QColor>() );
3820 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3823 bool changed =
false;
3863 QSizeF size = background.
size();
3870 QSizeF size = background.
size();
3971 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3974 bool changed =
false;
4033 shadow.
setColor( ddColor.value<QColor>() );
4071 #if 0 // TODO: generalize some of this 4074 double cx = lp->
getX() + w / 2.0;
4075 double cy = lp->
getY() + h / 2.0;
4078 double sw = w * scale;
4079 double sh = h * scale;
4080 QRectF rect( -sw / 2, -sh / 2, sw, sh );
4086 if ( lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT &&
4087 lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT_OVER &&
4090 painter->rotate( rotation );
4093 painter->translate( rect.bottomLeft() );
4094 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
4095 painter->translate( -rect.bottomLeft() );
4098 QRectF rect( 0, 0, outPt2.
x() - outPt.
x(), outPt2.
y() - outPt.
y() );
4099 painter->translate( QPointF( outPt.
x(), outPt.
y() ) );
4100 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
4105 painter->setPen( QColor( 255, 0, 0, 64 ) );
4109 painter->setPen( QColor( 0, 0, 0, 64 ) );
4111 painter->drawRect( rect );
4115 rect.moveTo( outPt.
x(), outPt.
y() );
4133 QList<QgsLabelPosition> positions;
4135 QList<QgsLabelPosition *> positionPointers;
4136 if ( mLabelSearchTree )
4138 mLabelSearchTree->label( p, positionPointers );
4139 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
4140 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
4151 QList<QgsLabelPosition> positions;
4153 QList<QgsLabelPosition *> positionPointers;
4154 if ( mLabelSearchTree )
4156 mLabelSearchTree->labelsInRect( r, positionPointers );
4157 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
4158 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
4169 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.
void setSymbol(const QgsSymbol *symbol)
Sets the feature symbol associated with this label.
Render units (eg mm/pixels/map units)
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
TextOrientation
Text orientation.
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).
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) ...
Abstract base class for callout renderers.
double maximumScale
The maximum map scale (i.e.
QString leftDirectionSymbol
String to use for left direction arrows.
static QgsCalloutRegistry * calloutRegistry()
Returns the application's callout registry, used for managing callout types.
Horizontally or vertically oriented text based on rotation (only available for map labeling) ...
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.
static QPointF toPoint(const QVariant &value, bool *ok=nullptr)
Converts a value to a point.
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
Returns the simplification settings to use when rendering vector layers.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the shape's size.
QgsMapUnitScale overrunDistanceMapUnitScale
Map unit scale for label overrun distance.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
void setOrientation(TextOrientation orientation)
Sets the orientation for the text.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
void registerFeature(const QgsFeature &f, QgsRenderContext &context, QgsLabelFeature **labelFeature=nullptr, QgsGeometry obstacleGeometry=QgsGeometry(), const QgsSymbol *symbol=nullptr)
Register a feature for labeling.
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.
virtual void stopRender(QgsRenderContext &context)
Finalises the callout after a set of rendering operations on the specified render context...
Abstract base class for all rendered symbols.
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.
static QgsTextBackgroundSettings::RotationType decodeBackgroundRotationType(const QString &string)
Decodes a string representation of a background rotation type to a type.
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...
void render(QgsRenderContext &context, QRectF rect, const double angle, const QgsGeometry &anchor, QgsCalloutContext &calloutContext)
Renders the callout onto the specified render context.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
static const double UI_SCALE_FACTOR
UI scaling factor.
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.
Contains additional contextual information about the context in which a callout is being rendered...
A class to query the labeling structure at a given point (small wrapper around pal RTree class) ...
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.
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
#define Q_NOWARN_DEPRECATED_PUSH
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 QgsTextBackgroundSettings::SizeType decodeBackgroundSizeType(const QString &string)
Decodes a string representation of a background size type to a type.
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.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
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.
static QPixmap labelSettingsPreviewPixmap(const QgsPalLayerSettings &settings, QSize size, const QString &previewText=QString(), int padding=0)
Returns a pixmap preview for label settings.
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.
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
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)
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the buffer size.
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.
static QSizeF toSize(const QVariant &value, bool *ok=nullptr)
Converts a value to a size.
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.
Property
Data definable properties.
double cost() const
Returns the candidate label position's geographical cost.
static QString encodeTextOrientation(QgsTextFormat::TextOrientation orientation)
Encodes a text orientation.
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.
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
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.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
bool isGeosValid(QgsGeometry::ValidityFlags flags=nullptr) const
Checks validity of the geometry using GEOS.
static QgsTextFormat::TextOrientation decodeTextOrientation(const QString &name, bool *ok=nullptr)
Attempts to decode a string representation of a text orientation.
Text within rectangle draw mode.
static QString capitalize(const QString &string, Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
QColor previewBackgroundColor() const
Returns the background color for text previews.
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...
TextOrientation orientation() const
Returns the orientation of the text.
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.
Vertically oriented text.
double width() const
Returns the width of the rectangle.
void setActive(bool active)
Sets whether the property is currently active.
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.
QgsPalLayerSettings & operator=(const QgsPalLayerSettings &s)
copy operator - only copies the permanent members
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.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
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 setRotatedSize(QSizeF size)
Sets an alternate label size to be used when a label rotation angle is between 45 to 135 and 235 to 3...
static QgsCallout * defaultCallout()
Create a new instance of a callout with default settings.
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
static QgsTextShadowSettings::ShadowPlacement decodeShadowPlacementType(const QString &string)
Decodes a string representation of a shadow placement type to a type.
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.
virtual void startRender(QgsRenderContext &context)
Prepares the callout for rendering on the specified render context.
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 planar, 2-dimensional length of geometry.
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.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
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.
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.
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true)
Draws text within a rectangle using the specified settings.
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)
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
Q_DECL_DEPRECATED QColor previewBkgrdColor
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.
ShapeType
Background shape types.
QString wrapChar
Wrapping character string.
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.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
void setFeature(const QgsFeature &feature)
Sets the original feature associated with this label.
#define Q_NOWARN_DEPRECATED_POP
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.
QFont scaledFont(const QgsRenderContext &context) const
Returns a font with the size scaled to match the format's size settings (including units and map unit...
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
bool enabled() const
Returns true if the the callout is enabled.
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.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the buffer 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 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 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.
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
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).
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.
void startRender(QgsRenderContext &context)
Prepares the label settings for rendering.
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
QgsCallout * callout() const
Returns the label callout renderer, responsible for drawing label callouts.
Distance which labels can extend past either end of linear features.
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
Convert all characters to lowercase.
double overrunDistance
Distance which labels are allowed to overrun past the start or end of line features.
void setShadow(const QgsTextShadowSettings &shadowSettings)
Sets the text's drop shadow settings.
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.
QgsUnitTypes::RenderUnit overrunDistanceUnit
Units for label overrun distance.
static QVector< QgsPalLayerSettings::PredefinedPointPosition > decodePredefinedPositionOrder(const QString &positionString)
Decodes a string to an ordered list of predefined point label positions.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the shape size.
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 planar, 2-dimensional area of the geometry.
Y-coordinate data defined label position.
void setCallout(QgsCallout *callout)
Sets the label callout renderer, responsible for drawing label callouts.
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
Returns true if the geometry contains the point p.
void setSvgFile(const QString &file)
Sets the path to the background SVG file.
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.
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.
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) ...
Whether all parts of multi-part features should be labeled.
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.
bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames, const QgsFields &fields, const QgsMapSettings &mapSettings, const QgsCoordinateReferenceSystem &crs)
Prepare for registration of features.
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.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units used for the shape's size.
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...
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
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)
QgsMarkerSymbol * markerSymbol() const
Returns the marker symbol to be rendered in the background.
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.
Horizontally oriented text.
void stopRender(QgsRenderContext &context)
Finalises the label settings after use.
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.
static QgsTextBackgroundSettings::ShapeType decodeShapeType(const QString &string)
Decodes a string representation of a background shape type to a type.
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, DrawMode mode, QFontMetricsF *fontMetrics=nullptr)
Returns the height of a text based on a given format.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
Color with no alpha channel.
QgsWkbTypes::GeometryType layerType
Geometry type of layers associated with these settings.
void setRotation(double rotation)
Sets the rotation for the background shape, in degrees clockwise.