32#include <QApplication>
35#include <QFontMetrics>
40#include <QTextBoundaryFinder>
98 if ( !sPropertyDefinitions()->isEmpty() )
101 const QString origin = QStringLiteral(
"labeling" );
113 "e.g. Helvetica or Helvetica [Cronyx]" ), origin )
117 "e.g. Bold Condensed or Light Italic" ), origin )
158 "<b>Ellipse</b>|<b>Circle</b>|<b>SVG</b>]" ), origin )
182 "<b>Buffer</b>|<b>Background</b>]" ), origin )
198 "<b>3</b>=Left|<b>4</b>=Over|<b>5</b>=Right|<br>"
199 "<b>6</b>=Below Left|<b>7</b>=Below|<b>8</b>=Below Right]" ), origin )
219 + QStringLiteral(
"[<b>TL</b>=Top left|<b>TSL</b>=Top, slightly left|<b>T</b>=Top middle|<br>"
220 "<b>TSR</b>=Top, slightly right|<b>TR</b>=Top right|<br>"
221 "<b>L</b>=Left|<b>R</b>=Right|<br>"
222 "<b>BL</b>=Bottom left|<b>BSL</b>=Bottom, slightly left|<b>B</b>=Bottom middle|<br>"
223 "<b>BSR</b>=Bottom, slightly right|<b>BR</b>=Bottom right]" ), origin )
227 + QStringLiteral(
"[<b>OL</b>=On line|<b>AL</b>=Above line|<b>BL</b>=Below line|<br>"
228 "<b>LO</b>=Respect line orientation]" ), origin )
237 "<b>Half</b>|<b>Cap</b>|<b>Top</b>]" ), origin )
262 : predefinedPositionOrder( *DEFAULT_PLACEMENT_ORDER() )
265 initPropertyDefinitions();
274 , mDataDefinedProperties( s.mDataDefinedProperties )
309 mPolygonPlacementFlags = s.mPolygonPlacementFlags;
325 mRotationUnit = s.mRotationUnit;
346 mDataDefinedProperties = s.mDataDefinedProperties;
348 mCallout.reset( s.mCallout ? s.mCallout->clone() : nullptr );
350 mPlacementSettings = s.mPlacementSettings;
351 mLineSettings = s.mLineSettings;
352 mObstacleSettings = s.mObstacleSettings;
353 mThinningSettings = s.mThinningSettings;
360 mLegendString = s.mLegendString;
362 mUnplacedVisibility = s.mUnplacedVisibility;
412 for (
const QString &name : referencedColumns )
414 attributeNames.insert( name );
478 for (
const QString &name : referencedColumns )
480 attributeNames.insert( name );
487 const auto referencedColumns = mCallout->referencedFields( context );
488 for (
const QString &name : referencedColumns )
490 attributeNames.insert( name );
499 QSet<QString> referenced;
527 referenced.unite( mCallout->referencedFields( context ) );
535 if ( mRenderStarted )
537 qWarning(
"Start render called for when a previous render was already underway!!" );
564 mCallout->startRender( context );
567 mRenderStarted =
true;
572 if ( !mRenderStarted )
574 qWarning(
"Stop render called for QgsPalLayerSettings without a startRender call!" );
580 mCallout->stopRender( context );
583 mRenderStarted =
false;
593 if ( mRenderStarted )
595 qWarning(
"stopRender was not called on QgsPalLayerSettings object!" );
606 initPropertyDefinitions();
607 return *sPropertyDefinitions();
621 return mRotationUnit;
626 mRotationUnit = angleUnit;
632 QString newValue = value;
633 if ( !value.isEmpty() && !value.contains( QLatin1String(
"~~" ) ) )
636 values << QStringLiteral(
"1" );
637 values << QStringLiteral(
"0" );
640 newValue = values.join( QLatin1String(
"~~" ) );
648 QString newPropertyName =
"labeling/dataDefined/" + sPropertyDefinitions()->value( p ).name();
649 QVariant newPropertyField = layer->
customProperty( newPropertyName, QVariant() );
651 if ( !newPropertyField.isValid() )
654 QString ddString = newPropertyField.toString();
656 if ( !ddString.isEmpty() && ddString != QLatin1String(
"0~~0~~~~" ) )
660 QStringList ddv = newStyleString.split( QStringLiteral(
"~~" ) );
662 bool active = ddv.at( 0 ).toInt();
663 if ( ddv.at( 1 ).toInt() )
679void QgsPalLayerSettings::readOldDataDefinedPropertyMap(
QgsVectorLayer *layer, QDomElement *parentElem )
681 if ( !layer && !parentElem )
686 QgsPropertiesDefinition::const_iterator i = sPropertyDefinitions()->constBegin();
687 for ( ; i != sPropertyDefinitions()->constEnd(); ++i )
692 readOldDataDefinedProperty( layer,
static_cast< Property >( i.key() ) );
694 else if ( parentElem )
697 QDomElement e = parentElem->firstChildElement( i.value().name() );
700 bool active = e.attribute( QStringLiteral(
"active" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
701 bool isExpression = e.attribute( QStringLiteral(
"useExpr" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
715void QgsPalLayerSettings::readFromLayerCustomProperties(
QgsVectorLayer *layer )
717 if ( layer->
customProperty( QStringLiteral(
"labeling" ) ).toString() != QLatin1String(
"pal" ) )
742 QDomDocument doc( QStringLiteral(
"substitutions" ) );
743 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/substitutions" ) ).toString() );
744 QDomElement replacementElem = doc.firstChildElement( QStringLiteral(
"substitutions" ) );
765 mLineSettings.
setPlacementFlags(
static_cast< Qgis::LabelLinePlacementFlags
>( layer->
customProperty( QStringLiteral(
"labeling/placementFlags" ) ).toUInt() ) );
774 if ( layer->
customProperty( QStringLiteral(
"labeling/distMapUnitScale" ) ).toString().isEmpty() )
777 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMinScale" ), 0.0 ).toDouble();
779 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMaxScale" ), 0.0 ).toDouble();
790 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetInMapUnits" ), QVariant(
true ) ).toBool() )
795 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitScale" ) ).toString().isEmpty() )
798 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMinScale" ), 0.0 ).toDouble();
800 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
808 QVariant tempAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant() );
809 if ( tempAngle.isValid() )
811 double oldAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant( 0.0 ) ).toDouble();
825 switch ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceUnit" ), QVariant( 1 ) ).toUInt() )
840 if ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitScale" ) ).toString().isEmpty() )
843 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMinScale" ), 0.0 ).toDouble();
845 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMaxScale" ), 0.0 ).toDouble();
854 double scalemn = layer->
customProperty( QStringLiteral(
"labeling/scaleMin" ), QVariant( 0 ) ).toDouble();
855 double scalemx = layer->
customProperty( QStringLiteral(
"labeling/scaleMax" ), QVariant( 0 ) ).toDouble();
858 QVariant scalevis = layer->
customProperty( QStringLiteral(
"labeling/scaleVisibility" ), QVariant() );
859 if ( scalevis.isValid() )
865 else if ( scalemn > 0 || scalemx > 0 )
881 if ( layer->
customProperty( QStringLiteral(
"labeling/displayAll" ), QVariant(
false ) ).toBool() )
899 mObstacleSettings.
setFactor( layer->
customProperty( QStringLiteral(
"labeling/obstacleFactor" ), QVariant( 1.0 ) ).toDouble() );
901 zIndex = layer->
customProperty( QStringLiteral(
"labeling/zIndex" ), QVariant( 0.0 ) ).toDouble();
903 mDataDefinedProperties.
clear();
904 if ( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).isValid() )
906 QDomDocument doc( QStringLiteral(
"dd" ) );
907 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).toString() );
908 QDomElement elem = doc.firstChildElement( QStringLiteral(
"properties" ) );
909 mDataDefinedProperties.
readXml( elem, *sPropertyDefinitions() );
914 readOldDataDefinedPropertyMap( layer,
nullptr );
958 QDomElement textStyleElem = elem.firstChildElement( QStringLiteral(
"text-style" ) );
959 fieldName = textStyleElem.attribute( QStringLiteral(
"fieldName" ) );
960 isExpression = textStyleElem.attribute( QStringLiteral(
"isExpression" ) ).toInt();
962 mFormat.
readXml( elem, context );
964 previewBkgrdColor = QColor( textStyleElem.attribute( QStringLiteral(
"previewBkgrdColor" ), QStringLiteral(
"#ffffff" ) ) );
967 useSubstitutions = textStyleElem.attribute( QStringLiteral(
"useSubstitutions" ) ).toInt();
968 mLegendString = textStyleElem.attribute( QStringLiteral(
"legendString" ), QObject::tr(
"Aa" ) );
971 QDomElement textFormatElem = elem.firstChildElement( QStringLiteral(
"text-format" ) );
972 wrapChar = textFormatElem.attribute( QStringLiteral(
"wrapChar" ) );
973 autoWrapLength = textFormatElem.attribute( QStringLiteral(
"autoWrapLength" ), QStringLiteral(
"0" ) ).toInt();
974 useMaxLineLengthForAutoWrap = textFormatElem.attribute( QStringLiteral(
"useMaxLineLengthForAutoWrap" ), QStringLiteral(
"1" ) ).toInt();
976 mLineSettings.
setAddDirectionSymbol( textFormatElem.attribute( QStringLiteral(
"addDirectionSymbol" ) ).toInt() );
977 mLineSettings.
setLeftDirectionSymbol( textFormatElem.attribute( QStringLiteral(
"leftDirectionSymbol" ), QStringLiteral(
"<" ) ) );
978 mLineSettings.
setRightDirectionSymbol( textFormatElem.attribute( QStringLiteral(
"rightDirectionSymbol" ), QStringLiteral(
">" ) ) );
979 mLineSettings.
setReverseDirectionSymbol( textFormatElem.attribute( QStringLiteral(
"reverseDirectionSymbol" ) ).toInt() );
981 formatNumbers = textFormatElem.attribute( QStringLiteral(
"formatNumbers" ) ).toInt();
982 decimals = textFormatElem.attribute( QStringLiteral(
"decimals" ) ).toInt();
983 plusSign = textFormatElem.attribute( QStringLiteral(
"plussign" ) ).toInt();
986 QDomElement placementElem = elem.firstChildElement( QStringLiteral(
"placement" ) );
988 mLineSettings.
setPlacementFlags(
static_cast< Qgis::LabelLinePlacementFlags
>( placementElem.attribute( QStringLiteral(
"placementFlags" ) ).toUInt() ) );
991 centroidWhole = placementElem.attribute( QStringLiteral(
"centroidWhole" ), QStringLiteral(
"0" ) ).toInt();
992 centroidInside = placementElem.attribute( QStringLiteral(
"centroidInside" ), QStringLiteral(
"0" ) ).toInt();
996 fitInPolygonOnly = placementElem.attribute( QStringLiteral(
"fitInPolygonOnly" ), QStringLiteral(
"0" ) ).toInt();
997 dist = placementElem.attribute( QStringLiteral(
"dist" ) ).toDouble();
998 if ( !placementElem.hasAttribute( QStringLiteral(
"distUnits" ) ) )
1000 if ( placementElem.attribute( QStringLiteral(
"distInMapUnits" ) ).toInt() )
1009 if ( !placementElem.hasAttribute( QStringLiteral(
"distMapUnitScale" ) ) )
1012 double oldMin = placementElem.attribute( QStringLiteral(
"distMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1014 double oldMax = placementElem.attribute( QStringLiteral(
"distMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1023 xOffset = placementElem.attribute( QStringLiteral(
"xOffset" ), QStringLiteral(
"0" ) ).toDouble();
1024 yOffset = placementElem.attribute( QStringLiteral(
"yOffset" ), QStringLiteral(
"0" ) ).toDouble();
1025 if ( !placementElem.hasAttribute( QStringLiteral(
"offsetUnits" ) ) )
1033 if ( !placementElem.hasAttribute( QStringLiteral(
"labelOffsetMapUnitScale" ) ) )
1036 double oldMin = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1038 double oldMax = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1046 if ( placementElem.hasAttribute( QStringLiteral(
"angleOffset" ) ) )
1048 double oldAngle = placementElem.attribute( QStringLiteral(
"angleOffset" ), QStringLiteral(
"0" ) ).toDouble();
1053 angleOffset = placementElem.attribute( QStringLiteral(
"rotationAngle" ), QStringLiteral(
"0" ) ).toDouble();
1056 preserveRotation = placementElem.attribute( QStringLiteral(
"preserveRotation" ), QStringLiteral(
"1" ) ).toInt();
1059 if ( rotationUnitString.startsWith( QLatin1String(
"Angle" ) ) )
1062 rotationUnitString = rotationUnitString.mid( 5 );
1067 maxCurvedCharAngleIn = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleIn" ), QStringLiteral(
"25" ) ).toDouble();
1068 maxCurvedCharAngleOut = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleOut" ), QStringLiteral(
"-25" ) ).toDouble();
1069 priority = placementElem.attribute( QStringLiteral(
"priority" ) ).toInt();
1070 repeatDistance = placementElem.attribute( QStringLiteral(
"repeatDistance" ), QStringLiteral(
"0" ) ).toDouble();
1071 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceUnits" ) ) )
1074 switch ( placementElem.attribute( QStringLiteral(
"repeatDistanceUnit" ), QString::number( 1 ) ).toUInt() )
1094 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceMapUnitScale" ) ) )
1097 double oldMin = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1099 double oldMax = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1107 mLineSettings.
setOverrunDistance( placementElem.attribute( QStringLiteral(
"overrunDistance" ), QStringLiteral(
"0" ) ).toDouble() );
1110 mLineSettings.
setLineAnchorPercent( placementElem.attribute( QStringLiteral(
"lineAnchorPercent" ), QStringLiteral(
"0.5" ) ).toDouble() );
1116 geometryGenerator = placementElem.attribute( QStringLiteral(
"geometryGenerator" ) );
1119 QString geometryTypeKey = placementElem.attribute( QStringLiteral(
"geometryGeneratorType" ) );
1121 if ( geometryTypeKey.endsWith( QLatin1String(
"Geometry" ) ) )
1122 geometryTypeKey.chop( 8 );
1127 QString layerTypeKey = placementElem.attribute( QStringLiteral(
"layerType" ) );
1129 if ( layerTypeKey.endsWith( QLatin1String(
"Geometry" ) ) )
1130 layerTypeKey.chop( 8 );
1135 mPlacementSettings.
setAllowDegradedPlacement( placementElem.attribute( QStringLiteral(
"allowDegraded" ), QStringLiteral(
"0" ) ).toInt() );
1138 QDomElement renderingElem = elem.firstChildElement( QStringLiteral(
"rendering" ) );
1140 drawLabels = renderingElem.attribute( QStringLiteral(
"drawLabels" ), QStringLiteral(
"1" ) ).toInt();
1142 maximumScale = renderingElem.attribute( QStringLiteral(
"scaleMin" ), QStringLiteral(
"0" ) ).toDouble();
1143 minimumScale = renderingElem.attribute( QStringLiteral(
"scaleMax" ), QStringLiteral(
"0" ) ).toDouble();
1144 scaleVisibility = renderingElem.attribute( QStringLiteral(
"scaleVisibility" ) ).toInt();
1146 fontLimitPixelSize = renderingElem.attribute( QStringLiteral(
"fontLimitPixelSize" ), QStringLiteral(
"0" ) ).toInt();
1147 fontMinPixelSize = renderingElem.attribute( QStringLiteral(
"fontMinPixelSize" ), QStringLiteral(
"0" ) ).toInt();
1148 fontMaxPixelSize = renderingElem.attribute( QStringLiteral(
"fontMaxPixelSize" ), QStringLiteral(
"10000" ) ).toInt();
1150 if ( placementElem.hasAttribute( QStringLiteral(
"overlapHandling" ) ) )
1157 if ( renderingElem.attribute( QStringLiteral(
"displayAll" ), QStringLiteral(
"0" ) ).toInt() )
1170 labelPerPart = renderingElem.attribute( QStringLiteral(
"labelPerPart" ) ).toInt();
1171 mLineSettings.
setMergeLines( renderingElem.attribute( QStringLiteral(
"mergeLines" ) ).toInt() );
1172 mThinningSettings.
setMinimumFeatureSize( renderingElem.attribute( QStringLiteral(
"minFeatureSize" ) ).toDouble() );
1173 mThinningSettings.
setLimitNumberLabelsEnabled( renderingElem.attribute( QStringLiteral(
"limitNumLabels" ), QStringLiteral(
"0" ) ).toInt() );
1174 mThinningSettings.
setMaximumNumberLabels( renderingElem.attribute( QStringLiteral(
"maxNumLabels" ), QStringLiteral(
"2000" ) ).toInt() );
1175 mObstacleSettings.
setIsObstacle( renderingElem.attribute( QStringLiteral(
"obstacle" ), QStringLiteral(
"1" ) ).toInt() );
1176 mObstacleSettings.
setFactor( renderingElem.attribute( QStringLiteral(
"obstacleFactor" ), QStringLiteral(
"1" ) ).toDouble() );
1178 zIndex = renderingElem.attribute( QStringLiteral(
"zIndex" ), QStringLiteral(
"0.0" ) ).toDouble();
1181 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"dd_properties" ) );
1182 if ( !ddElem.isNull() )
1184 mDataDefinedProperties.
readXml( ddElem, *sPropertyDefinitions() );
1189 mDataDefinedProperties.
clear();
1190 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"data-defined" ) );
1191 readOldDataDefinedPropertyMap(
nullptr, &ddElem );
1232 const QString calloutType = elem.attribute( QStringLiteral(
"calloutType" ) );
1233 if ( calloutType.isEmpty() )
1245 QDomElement textStyleElem = mFormat.
writeXml( doc, context );
1248 textStyleElem.setAttribute( QStringLiteral(
"fieldName" ),
fieldName );
1249 textStyleElem.setAttribute( QStringLiteral(
"isExpression" ),
isExpression );
1250 QDomElement replacementElem = doc.createElement( QStringLiteral(
"substitutions" ) );
1252 textStyleElem.appendChild( replacementElem );
1253 textStyleElem.setAttribute( QStringLiteral(
"useSubstitutions" ),
useSubstitutions );
1254 textStyleElem.setAttribute( QStringLiteral(
"legendString" ), mLegendString );
1257 QDomElement textFormatElem = doc.createElement( QStringLiteral(
"text-format" ) );
1258 textFormatElem.setAttribute( QStringLiteral(
"wrapChar" ),
wrapChar );
1259 textFormatElem.setAttribute( QStringLiteral(
"autoWrapLength" ),
autoWrapLength );
1261 textFormatElem.setAttribute( QStringLiteral(
"multilineAlign" ),
static_cast< unsigned int >(
multilineAlign ) );
1262 textFormatElem.setAttribute( QStringLiteral(
"addDirectionSymbol" ), mLineSettings.
addDirectionSymbol() );
1263 textFormatElem.setAttribute( QStringLiteral(
"leftDirectionSymbol" ), mLineSettings.
leftDirectionSymbol() );
1264 textFormatElem.setAttribute( QStringLiteral(
"rightDirectionSymbol" ), mLineSettings.
rightDirectionSymbol() );
1265 textFormatElem.setAttribute( QStringLiteral(
"reverseDirectionSymbol" ), mLineSettings.
reverseDirectionSymbol() );
1266 textFormatElem.setAttribute( QStringLiteral(
"placeDirectionSymbol" ),
static_cast< unsigned int >( mLineSettings.
directionSymbolPlacement() ) );
1267 textFormatElem.setAttribute( QStringLiteral(
"formatNumbers" ),
formatNumbers );
1268 textFormatElem.setAttribute( QStringLiteral(
"decimals" ),
decimals );
1269 textFormatElem.setAttribute( QStringLiteral(
"plussign" ),
plusSign );
1272 QDomElement placementElem = doc.createElement( QStringLiteral(
"placement" ) );
1273 placementElem.setAttribute( QStringLiteral(
"placement" ),
static_cast< int >(
placement ) );
1274 placementElem.setAttribute( QStringLiteral(
"polygonPlacementFlags" ),
static_cast< int >( mPolygonPlacementFlags ) );
1275 placementElem.setAttribute( QStringLiteral(
"placementFlags" ),
static_cast< unsigned int >( mLineSettings.
placementFlags() ) );
1276 placementElem.setAttribute( QStringLiteral(
"centroidWhole" ),
centroidWhole );
1277 placementElem.setAttribute( QStringLiteral(
"centroidInside" ),
centroidInside );
1279 placementElem.setAttribute( QStringLiteral(
"fitInPolygonOnly" ),
fitInPolygonOnly );
1280 placementElem.setAttribute( QStringLiteral(
"dist" ),
dist );
1283 placementElem.setAttribute( QStringLiteral(
"offsetType" ),
static_cast< unsigned int >(
offsetType ) );
1284 placementElem.setAttribute( QStringLiteral(
"quadOffset" ),
static_cast< unsigned int >(
quadOffset ) );
1285 placementElem.setAttribute( QStringLiteral(
"xOffset" ),
xOffset );
1286 placementElem.setAttribute( QStringLiteral(
"yOffset" ),
yOffset );
1289 placementElem.setAttribute( QStringLiteral(
"rotationAngle" ),
angleOffset );
1290 placementElem.setAttribute( QStringLiteral(
"preserveRotation" ),
preserveRotation );
1293 const QString rotationUnitString = QStringLiteral(
"Angle" ) +
qgsEnumValueToKey( mRotationUnit );
1294 placementElem.setAttribute( QStringLiteral(
"rotationUnit" ), rotationUnitString );
1298 placementElem.setAttribute( QStringLiteral(
"priority" ),
priority );
1299 placementElem.setAttribute( QStringLiteral(
"repeatDistance" ),
repeatDistance );
1302 placementElem.setAttribute( QStringLiteral(
"overrunDistance" ), mLineSettings.
overrunDistance() );
1305 placementElem.setAttribute( QStringLiteral(
"lineAnchorPercent" ), mLineSettings.
lineAnchorPercent() );
1306 placementElem.setAttribute( QStringLiteral(
"lineAnchorType" ),
static_cast< int >( mLineSettings.
anchorType() ) );
1307 placementElem.setAttribute( QStringLiteral(
"lineAnchorClipping" ),
static_cast< int >( mLineSettings.
anchorClipping() ) );
1310 placementElem.setAttribute( QStringLiteral(
"geometryGenerator" ),
geometryGenerator );
1317 placementElem.setAttribute( QStringLiteral(
"allowDegraded" ), mPlacementSettings.
allowDegradedPlacement() ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
1320 QDomElement renderingElem = doc.createElement( QStringLiteral(
"rendering" ) );
1321 renderingElem.setAttribute( QStringLiteral(
"drawLabels" ),
drawLabels );
1322 renderingElem.setAttribute( QStringLiteral(
"scaleVisibility" ),
scaleVisibility );
1323 renderingElem.setAttribute( QStringLiteral(
"scaleMin" ),
maximumScale );
1324 renderingElem.setAttribute( QStringLiteral(
"scaleMax" ),
minimumScale );
1325 renderingElem.setAttribute( QStringLiteral(
"fontLimitPixelSize" ),
fontLimitPixelSize );
1326 renderingElem.setAttribute( QStringLiteral(
"fontMinPixelSize" ),
fontMinPixelSize );
1327 renderingElem.setAttribute( QStringLiteral(
"fontMaxPixelSize" ),
fontMaxPixelSize );
1328 renderingElem.setAttribute( QStringLiteral(
"upsidedownLabels" ),
static_cast< unsigned int >(
upsidedownLabels ) );
1330 renderingElem.setAttribute( QStringLiteral(
"labelPerPart" ),
labelPerPart );
1331 renderingElem.setAttribute( QStringLiteral(
"mergeLines" ), mLineSettings.
mergeLines() );
1332 renderingElem.setAttribute( QStringLiteral(
"minFeatureSize" ), mThinningSettings.
minimumFeatureSize() );
1334 renderingElem.setAttribute( QStringLiteral(
"maxNumLabels" ), mThinningSettings.
maximumNumberLabels() );
1335 renderingElem.setAttribute( QStringLiteral(
"obstacle" ), mObstacleSettings.
isObstacle() );
1336 renderingElem.setAttribute( QStringLiteral(
"obstacleFactor" ), mObstacleSettings.
factor() );
1337 renderingElem.setAttribute( QStringLiteral(
"obstacleType" ),
static_cast< unsigned int >( mObstacleSettings.
type() ) );
1338 renderingElem.setAttribute( QStringLiteral(
"zIndex" ),
zIndex );
1339 renderingElem.setAttribute( QStringLiteral(
"unplacedVisibility" ),
static_cast< int >( mUnplacedVisibility ) );
1341 QDomElement ddElem = doc.createElement( QStringLiteral(
"dd_properties" ) );
1342 mDataDefinedProperties.
writeXml( ddElem, *sPropertyDefinitions() );
1344 QDomElement elem = doc.createElement( QStringLiteral(
"settings" ) );
1345 elem.appendChild( textStyleElem );
1346 elem.appendChild( textFormatElem );
1347 elem.appendChild( placementElem );
1348 elem.appendChild( renderingElem );
1349 elem.appendChild( ddElem );
1353 elem.setAttribute( QStringLiteral(
"calloutType" ), mCallout->type() );
1354 mCallout->saveProperties( doc, elem, context );
1371 QPixmap pixmap( size * devicePixelRatio );
1372 pixmap.fill( Qt::transparent );
1373 pixmap.setDevicePixelRatio( devicePixelRatio );
1375 painter.begin( &pixmap );
1377 painter.setRenderHint( QPainter::Antialiasing );
1379 const QRectF rect( 0, 0, size.width(), size.height() );
1382 painter.setPen( Qt::NoPen );
1384 if ( ( background1.lightnessF() < 0.7 ) )
1386 background1 = background1.darker( 125 );
1390 background1 = background1.lighter( 125 );
1393 QLinearGradient linearGrad( QPointF( 0, 0 ), QPointF( 0, rect.height() ) );
1394 linearGrad.setColorAt( 0, background1 );
1395 linearGrad.setColorAt( 1, background2 );
1396 painter.setBrush( QBrush( linearGrad ) );
1397 if ( size.width() > 30 )
1399 painter.drawRoundedRect( rect, 6, 6 );
1404 painter.drawRect( rect );
1406 painter.setBrush( Qt::NoBrush );
1407 painter.setPen( Qt::NoPen );
1422 QWidget *activeWindow = QApplication::activeWindow();
1423 if ( QScreen *screen = activeWindow ? activeWindow->screen() : nullptr )
1443 ? fontSize * tempFormat.
buffer().
size() / 100
1448 double ytrans = 0.0;
1451 ? fontSize * tempFormat.
buffer().
size() / 100
1456 const QStringList text = QStringList() << ( previewText.isEmpty() ? settings.
legendString() : previewText );
1458 QRectF textRect = rect;
1459 textRect.setLeft( xtrans + padding );
1460 textRect.setWidth( rect.width() - xtrans - 2 * padding );
1462 if ( textRect.width() > 2000 )
1463 textRect.setWidth( 2000 - 2 * padding );
1465 const double bottom = textRect.height() / 2 + textHeight / 2;
1466 textRect.setTop( bottom - textHeight );
1467 textRect.setBottom( bottom );
1478 QRectF labelRect( textRect.left() + ( textRect.width() - textWidth ) / 2.0, textRect.top(), textWidth, textRect.height() );
1485 if ( size.width() > 30 )
1490 rect.width() - iconWidth * 3, rect.height() - iconWidth * 3,
1491 iconWidth * 2, iconWidth * 2 ), Qt::AlignRight | Qt::AlignBottom );
1495 painter.setBrush( Qt::NoBrush );
1497 if ( size.width() > 30 )
1499 painter.drawRoundedRect( rect, 6, 6 );
1504 painter.drawRect( rect );
1513 return mUnplacedVisibility;
1518 mUnplacedVisibility = visibility;
1523 return QgsPalLabeling::checkMinimumSizeMM(
ct, geom, minSize );
1526void QgsPalLayerSettings::calculateLabelSize(
const QFontMetricsF *fm,
const QString &text,
double &labelX,
double &labelY,
const QgsFeature *f,
QgsRenderContext *context,
double *rotatedLabelX,
double *rotatedLabelY,
QgsTextDocument *document,
QgsTextDocumentMetrics *documentMetrics, QRectF *outerBounds )
1533 QString textCopy( text );
1536 std::unique_ptr< QgsRenderContext > scopedRc;
1541 scopedRc->expressionContext().setFeature( *f );
1657 if ( wrapchr.isEmpty() )
1659 wrapchr = QStringLiteral(
"\n" );
1664 && ( !leftDirSymb.isEmpty() || !rightDirSymb.isEmpty() ) )
1666 QString dirSym = leftDirSymb;
1668 if ( fm->horizontalAdvance( rightDirSymb ) > fm->horizontalAdvance( dirSym ) )
1669 dirSym = rightDirSymb;
1671 switch ( placeDirSymb )
1674 textCopy.append( dirSym );
1679 textCopy.prepend( dirSym + QStringLiteral(
"\n" ) );
1684 double w = 0.0, h = 0.0, rw = 0.0, rh = 0.0;
1685 double labelHeight = fm->ascent() + fm->descent();
1699 const int lines = multiLineSplit.size();
1703 switch ( orientation )
1709 for (
const QString &line : std::as_const( multiLineSplit ) )
1711 w = std::max( w, fm->horizontalAdvance( line ) );
1718 double letterSpacing = mFormat.
scaledFont( *context ).letterSpacing();
1719 double labelWidth = fm->maxWidth();
1722 int maxLineLength = 0;
1723 for (
const QString &line : std::as_const( multiLineSplit ) )
1725 maxLineLength = std::max( maxLineLength,
static_cast<int>( line.length() ) );
1727 h = fm->ascent() * maxLineLength + ( maxLineLength - 1 ) * letterSpacing;
1733 double widthHorizontal = 0.0;
1734 for (
const QString &line : std::as_const( multiLineSplit ) )
1736 widthHorizontal = std::max( w, fm->horizontalAdvance( line ) );
1739 double widthVertical = 0.0;
1740 double letterSpacing = mFormat.
scaledFont( *context ).letterSpacing();
1741 double labelWidth = fm->maxWidth();
1744 double heightHorizontal = 0.0;
1747 double heightVertical = 0.0;
1748 int maxLineLength = 0;
1749 for (
const QString &line : std::as_const( multiLineSplit ) )
1751 maxLineLength = std::max( maxLineLength,
static_cast<int>( line.length() ) );
1753 heightVertical = fm->ascent() * maxLineLength + ( maxLineLength - 1 ) * letterSpacing;
1755 w = widthHorizontal;
1756 rw = heightVertical;
1757 h = heightHorizontal;
1766 labelX = std::fabs( ptSize.
x() -
ptZero.
x() );
1767 labelY = std::fabs( ptSize.
y() -
ptZero.
y() );
1772 if ( rotatedLabelX && rotatedLabelY )
1774 *rotatedLabelX = rw * uPP;
1775 *rotatedLabelY = rh * uPP;
1779 if ( outerBounds && documentMetrics )
1783 *outerBounds = QRectF( outerBoundsPixels.left() * uPP,
1784 outerBoundsPixels.top() * uPP,
1785 outerBoundsPixels.width() * uPP,
1786 outerBoundsPixels.height() * uPP );
1801 bool isObstacle = mObstacleSettings.
isObstacle();
1809 return registerObstacleFeature( f, context, obstacleGeometry );
1824 if ( obstacleGeometry.
isNull() )
1837 dataDefinedValues.clear();
1854 if ( useScaleVisibility )
1867 maxScale = 1 / std::fabs( maxScale );
1886 minScale = 1 / std::fabs( minScale );
1895 QFont labelFont = mFormat.
font();
1903 QString units = exprVal.toString();
1904 if ( !units.isEmpty() )
1914 double fontSize = mFormat.
size();
1920 if ( fontSize <= 0.0 )
1927 if ( fontPixelSize < 1 )
1931 labelFont.setPixelSize( fontPixelSize );
1943 if ( fontMinPixel > labelFont.pixelSize() || labelFont.pixelSize() > fontMaxPixel )
1955 labelFont.setCapitalization( QFont::MixedCase );
1957 parseTextStyle( labelFont, fontunits, context );
1960 parseTextFormatting( context );
1961 parseTextBuffer( context );
1962 parseTextMask( context );
1963 parseShapeBackground( context );
1964 parseDropShadow( context );
2012 QString fcase = exprVal.toString().trimmed();
2013 QgsDebugMsgLevel( QStringLiteral(
"exprVal FontCase:%1" ).arg( fcase ), 4 );
2015 if ( !fcase.isEmpty() )
2017 if ( fcase.compare( QLatin1String(
"NoChange" ), Qt::CaseInsensitive ) == 0 )
2021 else if ( fcase.compare( QLatin1String(
"Upper" ), Qt::CaseInsensitive ) == 0 )
2025 else if ( fcase.compare( QLatin1String(
"Lower" ), Qt::CaseInsensitive ) == 0 )
2029 else if ( fcase.compare( QLatin1String(
"Capitalize" ), Qt::CaseInsensitive ) == 0 )
2033 else if ( fcase.compare( QLatin1String(
"Title" ), Qt::CaseInsensitive ) == 0 )
2037#if defined(HAS_KDE_QT5_SMALL_CAPS_FIX) || QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)
2038 else if ( fcase.compare( QLatin1String(
"SmallCaps" ), Qt::CaseInsensitive ) == 0 )
2042 else if ( fcase.compare( QLatin1String(
"AllSmallCaps" ), Qt::CaseInsensitive ) == 0 )
2058 if ( evalFormatNumbers )
2062 if ( decimalPlaces <= 0 )
2068 QVariant textV( labelText );
2070 double d = textV.toDouble( &ok );
2073 QString numberFormat;
2074 if ( d > 0 && signPlus )
2076 numberFormat.append(
'+' );
2078 numberFormat.append(
"%1" );
2079 labelText = numberFormat.arg( QLocale().toString( d,
'f', decimalPlaces ) );
2084 std::unique_ptr<QFontMetricsF> labelFontMetrics(
new QFontMetricsF( labelFont ) );
2087 double rotatedLabelX;
2088 double rotatedLabelY;
2093 if (
format().allowHtmlFormatting() && !labelText.isEmpty() )
2097 calculateLabelSize( labelFontMetrics.get(), labelText, labelWidth, labelHeight,
mCurFeat, &context, &rotatedLabelX, &rotatedLabelY, &doc, &documentMetrics, &outerBounds );
2101 calculateLabelSize( labelFontMetrics.get(), labelText, labelWidth, labelHeight,
mCurFeat, &context, &rotatedLabelX, &rotatedLabelY,
nullptr,
nullptr, &outerBounds );
2106 double maxcharanglein = 20.0;
2107 double maxcharangleout = -20.0;
2125 maxcharanglein = std::clamp(
static_cast< double >( maxcharanglePt.x() ), 20.0, 60.0 );
2126 maxcharangleout = std::clamp(
static_cast< double >( maxcharanglePt.y() ), 20.0, 95.0 );
2130 maxcharangleout = -( std::fabs( maxcharangleout ) );
2151 QString
str = exprVal.toString().trimmed();
2154 if ( !
str.isEmpty() )
2156 if (
str.compare( QLatin1String(
"Visible" ), Qt::CaseInsensitive ) == 0 )
2158 wholeCentroid =
false;
2160 else if (
str.compare( QLatin1String(
"Whole" ), Qt::CaseInsensitive ) == 0 )
2162 wholeCentroid =
true;
2176 std::unique_ptr<QgsGeometry> scopedClonedGeom;
2182 geom = simplifier.
simplify( geom );
2199 bool doClip =
false;
2200 if ( !centroidPoly || !wholeCentroid )
2206 Qgis::LabelPolygonPlacementFlags polygonPlacement = mPolygonPlacementFlags;
2212 if ( dataDefinedOutside.type() == QVariant::String )
2214 const QString value = dataDefinedOutside.toString().trimmed();
2215 if ( value.compare( QLatin1String(
"force" ), Qt::CaseInsensitive ) == 0 )
2221 else if ( value.compare( QLatin1String(
"yes" ), Qt::CaseInsensitive ) == 0 )
2226 else if ( value.compare( QLatin1String(
"no" ), Qt::CaseInsensitive ) == 0 )
2234 if ( dataDefinedOutside.toBool() )
2270 permissibleZone = geom;
2306 double minimumSize = 0.0;
2316 if ( !checkMinimumSizeMM( context, geom, featureThinningSettings.
minimumFeatureSize() ) )
2321 if ( !geos_geom_clone )
2350 bool layerDefinedRotation =
false;
2351 bool dataDefinedRotation =
false;
2352 double xPos = 0.0, yPos = 0.0;
2353 double angleInRadians = 0.0;
2354 double quadOffsetX = 0.0, quadOffsetY = 0.0;
2355 double offsetX = 0.0, offsetY = 0.0;
2367 bool ddFixedQuad =
false;
2376 int quadInt = exprVal.toInt( &ok );
2377 if ( ok && 0 <= quadInt && quadInt <= 8 )
2447 QString units = exprVal.toString().trimmed();
2448 if ( !units.isEmpty() )
2454 offUnit = decodedUnits;
2469 layerDefinedRotation =
true;
2470 angleInRadians = ( 360 -
angleOffset ) * M_PI / 180;
2482 const double rotation = exprVal.toDouble( &ok );
2485 dataDefinedRotation =
true;
2493 angleInRadians = ( 360 - rotationDegrees ) * M_PI / 180.0;
2498 bool hasDataDefinedPosition =
false;
2500 bool ddPosition =
false;
2512 bool ddXPos =
false, ddYPos =
false;
2513 xPos = xPosProperty.toDouble( &ddXPos );
2514 yPos = yPosProperty.toDouble( &ddYPos );
2515 if ( ddXPos && ddYPos )
2516 hasDataDefinedPosition =
true;
2527 if ( pointPosProperty.userType() == QMetaType::type(
"QgsReferencedGeometry" ) )
2532 if ( !referencedGeometryPoint.
isNull()
2536 else if ( pointPosProperty.userType() == QMetaType::type(
"QgsGeometry" ) )
2543 hasDataDefinedPosition =
true;
2554 if ( hasDataDefinedPosition )
2557 if ( layerDefinedRotation && !dataDefinedRotation )
2559 angleInRadians = 0.0;
2568 QString haliString = exprVal.toString();
2569 if ( haliString.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
2571 xdiff -= labelWidth / 2.0;
2573 else if ( haliString.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
2575 xdiff -= labelWidth;
2586 QString valiString = exprVal.toString();
2587 if ( valiString.compare( QLatin1String(
"Bottom" ), Qt::CaseInsensitive ) != 0 )
2589 if ( valiString.compare( QLatin1String(
"Top" ), Qt::CaseInsensitive ) == 0 )
2591 ydiff -= labelHeight;;
2595 double descentRatio = labelFontMetrics->descent() / labelFontMetrics->height();
2596 if ( valiString.compare( QLatin1String(
"Base" ), Qt::CaseInsensitive ) == 0 )
2598 ydiff -= labelHeight * descentRatio;
2602 double capHeightRatio = ( labelFontMetrics->boundingRect(
'H' ).height() + 1 + labelFontMetrics->descent() ) / labelFontMetrics->height();
2603 ydiff -= labelHeight * capHeightRatio;
2604 if ( valiString.compare( QLatin1String(
"Half" ), Qt::CaseInsensitive ) == 0 )
2606 ydiff += labelHeight * ( capHeightRatio - descentRatio ) / 2.0;
2614 if ( dataDefinedRotation )
2617 double xd = xdiff * std::cos( angleInRadians ) - ydiff * std::sin( angleInRadians );
2618 double yd = xdiff * std::sin( angleInRadians ) + ydiff * std::cos( angleInRadians );
2628 if (
const QgsPoint *point = qgsgeometry_cast< const QgsPoint * >( ddPoint.
constGet() ) )
2636 QgsMessageLog::logMessage( QObject::tr(
"Invalid data defined label position (%1, %2)" ).arg( xPos ).arg( yPos ), QObject::tr(
"Labeling" ) );
2637 hasDataDefinedPosition =
false;
2656 bool alwaysShow =
false;
2678 QString units = exprVal.toString().trimmed();
2679 if ( !units.isEmpty() )
2685 repeatUnits = decodedUnits;
2711 bool labelAll =
labelPerPart && !hasDataDefinedPosition;
2712 if ( !hasDataDefinedPosition )
2722 std::unique_ptr< QgsTextLabelFeature > labelFeature = std::make_unique< QgsTextLabelFeature>( feature.
id(), std::move( geos_geom_clone ), QSizeF( labelWidth, labelHeight ) );
2723 labelFeature->setAnchorPosition( anchorPosition );
2724 labelFeature->setFeature( feature );
2725 labelFeature->setSymbol( symbol );
2726 labelFeature->setDocument( doc, documentMetrics );
2728 labelFeature->setRotatedSize( QSizeF( rotatedLabelX, rotatedLabelY ) );
2731 labelFeature->setHasFixedPosition( hasDataDefinedPosition );
2732 labelFeature->setFixedPosition(
QgsPointXY( xPos, yPos ) );
2734 labelFeature->setHasFixedAngle( dataDefinedRotation || ( !hasDataDefinedPosition && !
qgsDoubleNear( angleInRadians, 0.0 ) ) );
2735 labelFeature->setFixedAngle( angleInRadians );
2736 labelFeature->setQuadOffset( QPointF( quadOffsetX, quadOffsetY ) );
2737 labelFeature->setPositionOffset(
QgsPointXY( offsetX, offsetY ) );
2739 labelFeature->setAlwaysShow( alwaysShow );
2740 labelFeature->setRepeatDistance( repeatDist );
2741 labelFeature->setLabelText( labelText );
2742 labelFeature->setPermissibleZone( permissibleZone );
2743 labelFeature->setOverrunDistance( overrunDistanceEval );
2744 labelFeature->setOverrunSmoothDistance( overrunSmoothDist );
2748 labelFeature->setLabelAllParts( labelAll );
2750 labelFeature->setMinimumSize( minimumSize );
2754 labelFeature->setSymbolSize( QSizeF( obstacleGeometry.
boundingBox().
width(),
2758 if ( outerBounds.left() != 0 || outerBounds.top() != 0 || !
qgsDoubleNear( outerBounds.width(), labelWidth ) || !
qgsDoubleNear( outerBounds.height(), labelHeight ) )
2760 labelFeature->setOuterBounds( outerBounds );
2765 double topMargin = std::max( 0.25 * labelFontMetrics->ascent(), 0.0 );
2766 double bottomMargin = 1.0 + labelFontMetrics->descent();
2767 QgsMargins vm( 0.0, topMargin, 0.0, bottomMargin );
2769 labelFeature->setVisualMargin( vm );
2772 QgsDebugMsgLevel( QStringLiteral(
"PAL font stored definedFont: %1, Style: %2" ).arg( labelFont.toString(), labelFont.styleName() ), 4 );
2773 labelFeature->setDefinedFont( labelFont );
2775 labelFeature->setMaximumCharacterAngleInside( std::clamp( maxcharanglein, 20.0, 60.0 ) * M_PI / 180 );
2776 labelFeature->setMaximumCharacterAngleOutside( std::clamp( maxcharangleout, -95.0, -20.0 ) * M_PI / 180 );
2800 double distance =
dist;
2814 QString units = exprVal.toString().trimmed();
2815 QgsDebugMsgLevel( QStringLiteral(
"exprVal DistanceUnits:%1" ).arg( units ), 4 );
2816 if ( !units.isEmpty() )
2822 distUnit = decodedUnits;
2836 distance = ( distance < 0 ? -1 : 1 ) * std::max( std::fabs( distance ), 1.0 );
2848 distance = std::max( distance, 2.0 );
2853 distance = std::max( distance, 2.0 );
2860 labelFeature->setDistLabel( d );
2865 labelFeature->setHasFixedQuadrant(
true );
2870 labelFeature->setPolygonPlacementFlags( polygonPlacement );
2879 labelFeature->setZIndex( z );
2889 double priorityD = exprVal.toDouble( &ok );
2892 priorityD = std::clamp( priorityD, 0.0, 10.0 );
2893 priorityD = 1 - priorityD / 10.0;
2894 labelFeature->setPriority( priorityD );
2907 labelFeature->setAllowDegradedPlacement( allowDegradedPlacement );
2916 const QString cleanedString = handlingString.trimmed();
2917 if ( cleanedString.compare( QLatin1String(
"prevent" ), Qt::CaseInsensitive ) == 0 )
2919 else if ( cleanedString.compare( QLatin1String(
"allowifneeded" ), Qt::CaseInsensitive ) == 0 )
2921 else if ( cleanedString.compare( QLatin1String(
"alwaysallow" ), Qt::CaseInsensitive ) == 0 )
2924 labelFeature->setOverlapHandling( overlapHandling );
2931 labelFeature->setObstacleSettings( os );
2934 if ( positionOrder.isEmpty() )
2935 positionOrder = *DEFAULT_PLACEMENT_ORDER();
2941 if ( !dataDefinedOrder.isEmpty() )
2946 labelFeature->setPredefinedPositionOrder( positionOrder );
2949 labelFeature->setDataDefinedValues( dataDefinedValues );
2951 return labelFeature;
2959 if ( !obstacleGeometry.
isNull() )
2961 geom = obstacleGeometry;
2976 if ( ls->numPoints() < 2 )
2982 std::unique_ptr<QgsGeometry> scopedClonedGeom;
2988 geom = simplifier.
simplify( geom );
2992 std::unique_ptr<QgsGeometry> scopedPreparedGeom;
3000 if ( !geos_geom_clone )
3004 std::unique_ptr< QgsLabelFeature > obstacleFeature = std::make_unique< QgsLabelFeature >( f.
id(), std::move( geos_geom_clone ), QSizeF( 0, 0 ) );
3005 obstacleFeature->setFeature( f );
3010 obstacleFeature->setObstacleSettings( os );
3013 return obstacleFeature;
3016bool QgsPalLayerSettings::dataDefinedValEval( DataDefinedValueType valType,
3020 if ( !mDataDefinedProperties.
isActive( p ) )
3024 exprVal = mDataDefinedProperties.
value( p, context );
3031 bool bol = exprVal.toBool();
3032 dataDefinedValues.insert( p, QVariant( bol ) );
3038 int size = exprVal.toInt( &ok );
3042 dataDefinedValues.insert( p, QVariant( size ) );
3050 int size = exprVal.toInt( &ok );
3052 if ( ok && size > 0 )
3054 dataDefinedValues.insert( p, QVariant( size ) );
3062 double size = exprVal.toDouble( &ok );
3066 dataDefinedValues.insert( p, QVariant( size ) );
3074 double size = exprVal.toDouble( &ok );
3076 if ( ok && size > 0.0 )
3078 dataDefinedValues.insert( p, QVariant( size ) );
3086 double rot = exprVal.toDouble( &ok );
3089 if ( rot < -180.0 && rot >= -360 )
3093 if ( rot > 180.0 && rot <= 360 )
3097 if ( rot >= -180 && rot <= 180 )
3099 dataDefinedValues.insert( p, QVariant( rot ) );
3108 int size = exprVal.toInt( &ok );
3109 if ( ok && size >= 0 && size <= 100 )
3111 dataDefinedValues.insert( p, QVariant( size ) );
3118 QString
str = exprVal.toString();
3120 dataDefinedValues.insert( p, QVariant(
str ) );
3125 QString unitstr = exprVal.toString().trimmed();
3127 if ( !unitstr.isEmpty() )
3136 QString colorstr = exprVal.toString().trimmed();
3139 if ( color.isValid() )
3141 dataDefinedValues.insert( p, QVariant( color ) );
3148 QString joinstr = exprVal.toString().trimmed();
3150 if ( !joinstr.isEmpty() )
3159 QString blendstr = exprVal.toString().trimmed();
3161 if ( !blendstr.isEmpty() )
3174 dataDefinedValues.insert( p, res );
3185 dataDefinedValues.insert( p, res );
3195void QgsPalLayerSettings::parseTextStyle( QFont &labelFont,
3208 QString ddFontFamily;
3215 QString family = exprVal.toString().trimmed();
3216 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font family:%1" ).arg( family ), 4 );
3219 if ( labelFont.family() != family )
3225 ddFontFamily = family;
3232 QString ddFontStyle;
3238 QString fontstyle = exprVal.toString().trimmed();
3239 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font style:%1" ).arg( fontstyle ), 4 );
3240 ddFontStyle = fontstyle;
3245 bool ddBold =
false;
3253 bool ddItalic =
false;
3263 QFont appFont = QApplication::font();
3264 bool newFontBuilt =
false;
3265 if ( ddBold || ddItalic )
3269 newFontBuilt =
true;
3270 newFont.setBold( ddBold );
3271 newFont.setItalic( ddItalic );
3273 else if ( !ddFontStyle.isEmpty()
3274 && ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
3276 if ( !ddFontFamily.isEmpty() )
3280 mFontDB = std::make_unique< QFontDatabase >();
3282 QFont styledfont = mFontDB->font( ddFontFamily, ddFontStyle, appFont.pointSize() );
3283 if ( appFont != styledfont )
3285 newFont = styledfont;
3286 newFontBuilt =
true;
3293 else if ( !ddFontFamily.isEmpty() )
3295 if ( ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
3299 mFontDB = std::make_unique< QFontDatabase >();
3300 QFont styledfont = mFontDB->font( ddFontFamily, mFormat.
namedStyle(), appFont.pointSize() );
3301 if ( appFont != styledfont )
3303 newFont = styledfont;
3304 newFontBuilt =
true;
3310 newFontBuilt =
true;
3318 newFont.setPixelSize( labelFont.pixelSize() );
3319 newFont.setUnderline( labelFont.underline() );
3320 newFont.setStrikeOut( labelFont.strikeOut() );
3321 newFont.setWordSpacing( labelFont.wordSpacing() );
3322 newFont.setLetterSpacing( QFont::AbsoluteSpacing, labelFont.letterSpacing() );
3324 labelFont = newFont;
3328 double wordspace = labelFont.wordSpacing();
3337 double letterspace = labelFont.letterSpacing();
3350 labelFont.setStrikeOut( strikeout );
3365 labelFont.setUnderline( underline );
3391 drawBuffer = exprVal.toBool();
3404 double bufrSize = buffer.
size();
3407 bufrSize = exprVal.toDouble();
3411 double bufferOpacity = buffer.
opacity() * 100;
3414 bufferOpacity = exprVal.toDouble();
3417 drawBuffer = ( drawBuffer && bufrSize > 0.0 && bufferOpacity > 0 );
3447 bool maskEnabled = mask.
enabled();
3450 maskEnabled = exprVal.toBool();
3459 double bufrSize = mask.
size();
3462 bufrSize = exprVal.toDouble();
3466 double opacity = mask.
opacity() * 100;
3469 opacity = exprVal.toDouble();
3472 maskEnabled = ( maskEnabled && bufrSize > 0.0 && opacity > 0 );
3497 wrapchr = exprVal.toString();
3503 evalAutoWrapLength = exprVal.toInt();
3516 QString
str = exprVal.toString().trimmed();
3519 if ( !
str.isEmpty() )
3524 if (
str.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
3528 else if (
str.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
3532 else if (
str.compare( QLatin1String(
"Follow" ), Qt::CaseInsensitive ) == 0 )
3536 else if (
str.compare( QLatin1String(
"Justify" ), Qt::CaseInsensitive ) == 0 )
3553 QString
str = exprVal.toString().trimmed();
3554 if ( !
str.isEmpty() )
3563 drawDirSymb = exprVal.toBool();
3578 QString
str = exprVal.toString().trimmed();
3581 if ( !
str.isEmpty() )
3586 if (
str.compare( QLatin1String(
"Above" ), Qt::CaseInsensitive ) == 0 )
3590 else if (
str.compare( QLatin1String(
"Below" ), Qt::CaseInsensitive ) == 0 )
3612 bool drawShape = background.
enabled();
3615 drawShape = exprVal.toBool();
3624 double shapeOpacity = background.
opacity() * 100;
3627 shapeOpacity = 100.0 * exprVal.toDouble();
3630 drawShape = ( drawShape && shapeOpacity > 0 );
3646 QString skind = exprVal.toString().trimmed();
3647 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeKind:%1" ).arg( skind ), 4 );
3649 if ( !skind.isEmpty() )
3658 QString svgPath = background.
svgFile();
3665 QString svgfile = exprVal.toString().trimmed();
3666 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSVGFile:%1" ).arg( svgfile ), 4 );
3681 QString stype = exprVal.toString().trimmed();
3682 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSizeType:%1" ).arg( stype ), 4 );
3684 if ( !stype.isEmpty() )
3693 double ddShpSizeX = background.
size().width();
3696 ddShpSizeX = exprVal.toDouble();
3700 double ddShpSizeY = background.
size().height();
3703 ddShpSizeY = exprVal.toDouble();
3709 && ( svgPath.isEmpty()
3710 || ( !svgPath.isEmpty()
3712 && ddShpSizeX == 0.0 ) ) )
3720 && ddShpSizeX == 0.0 ) ) )
3727 && ( ddShpSizeX == 0.0 || ddShpSizeY == 0.0 ) )
3752 QString rotstr = exprVal.toString().trimmed();
3753 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeRotationType:%1" ).arg( rotstr ), 4 );
3755 if ( !rotstr.isEmpty() )
3806 bool drawShadow = shadow.
enabled();
3809 drawShadow = exprVal.toBool();
3818 double shadowOpacity = shadow.
opacity() * 100;
3821 shadowOpacity = exprVal.toDouble();
3828 shadowOffDist = exprVal.toDouble();
3835 shadowRad = exprVal.toDouble();
3838 drawShadow = ( drawShadow && shadowOpacity > 0 && !( shadowOffDist == 0.0 && shadowRad == 0.0 ) );
3855 QString
str = exprVal.toString().trimmed();
3858 if ( !
str.isEmpty() )
3893 switch ( layer->
type() )
3897 const QgsVectorLayer *vl = qobject_cast< const QgsVectorLayer * >( layer );
3908 return !labeling->styles().empty();
3958QStringList
QgsPalLabeling::splitToLines(
const QString &text,
const QString &wrapCharacter,
const int autoWrapLength,
const bool useMaxLineLengthWhenAutoWrapping )
3960 QStringList multiLineSplit;
3961 if ( !wrapCharacter.isEmpty() && wrapCharacter != QLatin1String(
"\n" ) )
3964 const QStringList lines = text.split( wrapCharacter );
3965 for (
const QString &line : lines )
3967 multiLineSplit.append( line.split(
'\n' ) );
3972 multiLineSplit = text.split(
'\n' );
3976 if ( autoWrapLength != 0 )
3978 QStringList autoWrappedLines;
3979 autoWrappedLines.reserve( multiLineSplit.count() );
3980 for (
const QString &line : std::as_const( multiLineSplit ) )
3982 autoWrappedLines.append(
QgsStringUtils::wordWrap( line, autoWrapLength, useMaxLineLengthWhenAutoWrapping ).split(
'\n' ) );
3984 multiLineSplit = autoWrappedLines;
3986 return multiLineSplit;
3991 QStringList graphemes;
3992 QTextBoundaryFinder boundaryFinder( QTextBoundaryFinder::Grapheme, text );
3993 int currentBoundary = -1;
3994 int previousBoundary = 0;
3995 while ( ( currentBoundary = boundaryFinder.toNextBoundary() ) > 0 )
3997 graphemes << text.mid( previousBoundary, currentBoundary - previousBoundary );
3998 previousBoundary = currentBoundary;
4028 QgsDebugMsgLevel( QStringLiteral(
"Ignoring feature due to transformation exception" ), 4 );
4034 return std::isfinite( point.
x() ) && std::isfinite( point.
y() );
4038 cp->removeInvalidRings();
4040 else if (
QgsMultiSurface *ms = qgsgeometry_cast< QgsMultiSurface * >( geom.
get() ) )
4042 for (
int i = 0; i < ms->numGeometries(); ++i )
4044 if (
QgsCurvePolygon *cp = qgsgeometry_cast< QgsCurvePolygon * >( ms->geometryN( i ) ) )
4045 cp->removeInvalidRings();
4062 const bool mustClip = ( !clipGeometry.
isNull() &&
4066 bool mustClipExact =
false;
4090 QVector< QgsGeometry> parts;
4091 parts.reserve( qgsgeometry_cast< const QgsGeometryCollection * >( geom.
constGet() )->numGeometries() );
4100 parts.append( partGeom );
4108 if ( bufferGeom.
isNull() )
4117 if ( mustClipExact )
4152 double length = geom.
length();
4153 if ( length >= 0.0 )
4155 return ( length >= ( minSize * mapUnitsPerMM ) );
4160 double area = geom.
area();
4163 return ( std::sqrt( area ) >= ( minSize * mapUnitsPerMM ) );
4171 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4174 bool changed =
false;
4180 format.
setColor( ddColor.value<QColor>() );
4205 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4267 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4270 bool changed =
false;
4318 buffer.
setColor( ddColor.value<QColor>() );
4345 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4347 if ( ddValues.isEmpty() )
4351 bool changed =
false;
4411 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4414 bool changed =
false;
4454 QSizeF size = background.
size();
4461 QSizeF size = background.
size();
4562 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4565 bool changed =
false;
4624 shadow.
setColor( ddColor.value<QColor>() );