35 #include <QApplication>
38 #include <QFontMetrics>
41 #include <QDesktopWidget>
70 #include <QMessageBox>
106 if ( !sPropertyDefinitions()->isEmpty() )
109 const QString origin = QStringLiteral(
"labeling" );
121 "e.g. Helvetica or Helvetica [Cronyx]" ), origin )
125 "e.g. Bold Condensed or Light Italic" ), origin )
165 "<b>Ellipse</b>|<b>Circle</b>|<b>SVG</b>]" ), origin )
189 "<b>Buffer</b>|<b>Background</b>]" ), origin )
205 "<b>3</b>=Left|<b>4</b>=Over|<b>5</b>=Right|<br>"
206 "<b>6</b>=Below Left|<b>7</b>=Below|<b>8</b>=Below Right]" ), origin )
222 + QStringLiteral(
"[<b>TL</b>=Top left|<b>TSL</b>=Top, slightly left|<b>T</b>=Top middle|<br>"
223 "<b>TSR</b>=Top, slightly right|<b>TR</b>=Top right|<br>"
224 "<b>L</b>=Left|<b>R</b>=Right|<br>"
225 "<b>BL</b>=Bottom left|<b>BSL</b>=Bottom, slightly left|<b>B</b>=Bottom middle|<br>"
226 "<b>BSR</b>=Bottom, slightly right|<b>BR</b>=Bottom right]" ), origin )
230 + QStringLiteral(
"[<b>OL</b>=On line|<b>AL</b>=Above line|<b>BL</b>=Below line|<br>"
231 "<b>LO</b>=Respect line orientation]" ), origin )
239 "<b>Half</b>|<b>Cap</b>|<b>Top</b>]" ), origin )
262 : predefinedPositionOrder( *DEFAULT_PLACEMENT_ORDER() )
265 initPropertyDefinitions();
272 , mDataDefinedProperties( s.mDataDefinedProperties )
313 mPolygonPlacementFlags = s.mPolygonPlacementFlags;
354 mDataDefinedProperties = s.mDataDefinedProperties;
356 mCallout.reset( s.mCallout ? s.mCallout->clone() :
nullptr );
358 mObstacleSettings = s.mObstacleSettings;
359 mThinningSettings = s.mThinningSettings;
414 for (
const QString &name : referencedColumns )
416 attributeNames.insert( name );
472 for (
const QString &name : referencedColumns )
474 attributeNames.insert( name );
481 const auto referencedColumns = mCallout->referencedFields( context );
482 for (
const QString &name : referencedColumns )
484 attributeNames.insert( name );
493 QSet<QString> referenced;
521 referenced.unite( mCallout->referencedFields( context ) );
529 if ( mRenderStarted )
531 qWarning(
"Start render called for when a previous render was already underway!!" );
544 mCallout->startRender( context );
547 mRenderStarted =
true;
552 if ( !mRenderStarted )
554 qWarning(
"Stop render called for QgsPalLayerSettings without a startRender call!" );
560 mCallout->stopRender( context );
563 mRenderStarted =
false;
568 if ( mRenderStarted )
570 qWarning(
"stopRender was not called on QgsPalLayerSettings object!" );
581 initPropertyDefinitions();
582 return *sPropertyDefinitions();
597 QString newValue = value;
598 if ( !value.isEmpty() && !value.contains( QLatin1String(
"~~" ) ) )
601 values << QStringLiteral(
"1" );
602 values << QStringLiteral(
"0" );
605 newValue = values.join( QStringLiteral(
"~~" ) );
613 QString newPropertyName =
"labeling/dataDefined/" + sPropertyDefinitions()->value( p ).name();
614 QVariant newPropertyField = layer->
customProperty( newPropertyName, QVariant() );
616 if ( !newPropertyField.isValid() )
619 QString ddString = newPropertyField.toString();
621 if ( !ddString.isEmpty() && ddString != QLatin1String(
"0~~0~~~~" ) )
625 QStringList ddv = newStyleString.split( QStringLiteral(
"~~" ) );
627 bool active = ddv.at( 0 ).toInt();
628 if ( ddv.at( 1 ).toInt() )
644 void QgsPalLayerSettings::readOldDataDefinedPropertyMap(
QgsVectorLayer *layer, QDomElement *parentElem )
646 if ( !layer && !parentElem )
651 QgsPropertiesDefinition::const_iterator i = sPropertyDefinitions()->constBegin();
652 for ( ; i != sPropertyDefinitions()->constEnd(); ++i )
657 readOldDataDefinedProperty( layer,
static_cast< Property >( i.key() ) );
659 else if ( parentElem )
662 QDomElement e = parentElem->firstChildElement( i.value().name() );
665 bool active = e.attribute( QStringLiteral(
"active" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
666 bool isExpression = e.attribute( QStringLiteral(
"useExpr" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
680 void QgsPalLayerSettings::readFromLayerCustomProperties(
QgsVectorLayer *layer )
682 if ( layer->
customProperty( QStringLiteral(
"labeling" ) ).toString() != QLatin1String(
"pal" ) )
707 QDomDocument doc( QStringLiteral(
"substitutions" ) );
708 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/substitutions" ) ).toString() );
709 QDomElement replacementElem = doc.firstChildElement( QStringLiteral(
"substitutions" ) );
739 if ( layer->
customProperty( QStringLiteral(
"labeling/distMapUnitScale" ) ).toString().isEmpty() )
742 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMinScale" ), 0.0 ).toDouble();
744 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMaxScale" ), 0.0 ).toDouble();
755 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetInMapUnits" ), QVariant(
true ) ).toBool() )
760 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitScale" ) ).toString().isEmpty() )
763 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMinScale" ), 0.0 ).toDouble();
765 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
773 QVariant tempAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant() );
774 if ( tempAngle.isValid() )
776 double oldAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant( 0.0 ) ).toDouble();
789 switch ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceUnit" ), QVariant( 1 ) ).toUInt() )
804 if ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitScale" ) ).toString().isEmpty() )
807 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMinScale" ), 0.0 ).toDouble();
809 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMaxScale" ), 0.0 ).toDouble();
818 double scalemn = layer->
customProperty( QStringLiteral(
"labeling/scaleMin" ), QVariant( 0 ) ).toDouble();
819 double scalemx = layer->
customProperty( QStringLiteral(
"labeling/scaleMax" ), QVariant( 0 ) ).toDouble();
822 QVariant scalevis = layer->
customProperty( QStringLiteral(
"labeling/scaleVisibility" ), QVariant() );
823 if ( scalevis.isValid() )
829 else if ( scalemn > 0 || scalemx > 0 )
854 mObstacleSettings.
setFactor( layer->
customProperty( QStringLiteral(
"labeling/obstacleFactor" ), QVariant( 1.0 ) ).toDouble() );
856 zIndex = layer->
customProperty( QStringLiteral(
"labeling/zIndex" ), QVariant( 0.0 ) ).toDouble();
858 mDataDefinedProperties.
clear();
859 if ( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).isValid() )
861 QDomDocument doc( QStringLiteral(
"dd" ) );
862 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).toString() );
863 QDomElement elem = doc.firstChildElement( QStringLiteral(
"properties" ) );
864 mDataDefinedProperties.
readXml( elem, *sPropertyDefinitions() );
869 readOldDataDefinedPropertyMap( layer,
nullptr );
913 QDomElement textStyleElem = elem.firstChildElement( QStringLiteral(
"text-style" ) );
914 fieldName = textStyleElem.attribute( QStringLiteral(
"fieldName" ) );
915 isExpression = textStyleElem.attribute( QStringLiteral(
"isExpression" ) ).toInt();
917 mFormat.
readXml( elem, context );
919 previewBkgrdColor = QColor( textStyleElem.attribute( QStringLiteral(
"previewBkgrdColor" ), QStringLiteral(
"#ffffff" ) ) );
922 useSubstitutions = textStyleElem.attribute( QStringLiteral(
"useSubstitutions" ) ).toInt();
925 QDomElement textFormatElem = elem.firstChildElement( QStringLiteral(
"text-format" ) );
926 wrapChar = textFormatElem.attribute( QStringLiteral(
"wrapChar" ) );
927 autoWrapLength = textFormatElem.attribute( QStringLiteral(
"autoWrapLength" ), QStringLiteral(
"0" ) ).toInt();
928 useMaxLineLengthForAutoWrap = textFormatElem.attribute( QStringLiteral(
"useMaxLineLengthForAutoWrap" ), QStringLiteral(
"1" ) ).toInt();
930 addDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"addDirectionSymbol" ) ).toInt();
931 leftDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"leftDirectionSymbol" ), QStringLiteral(
"<" ) );
932 rightDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"rightDirectionSymbol" ), QStringLiteral(
">" ) );
935 formatNumbers = textFormatElem.attribute( QStringLiteral(
"formatNumbers" ) ).toInt();
936 decimals = textFormatElem.attribute( QStringLiteral(
"decimals" ) ).toInt();
937 plusSign = textFormatElem.attribute( QStringLiteral(
"plussign" ) ).toInt();
940 QDomElement placementElem = elem.firstChildElement( QStringLiteral(
"placement" ) );
941 placement =
static_cast< Placement >( placementElem.attribute( QStringLiteral(
"placement" ) ).toInt() );
942 placementFlags = placementElem.attribute( QStringLiteral(
"placementFlags" ) ).toUInt();
943 mPolygonPlacementFlags =
static_cast< QgsLabeling::PolygonPlacementFlags
>( placementElem.attribute( QStringLiteral(
"polygonPlacementFlags" ), QString::number(
static_cast< int >( QgsLabeling::PolygonPlacementFlag::AllowPlacementInsideOfPolygon ) ) ).toInt() );
945 centroidWhole = placementElem.attribute( QStringLiteral(
"centroidWhole" ), QStringLiteral(
"0" ) ).toInt();
946 centroidInside = placementElem.attribute( QStringLiteral(
"centroidInside" ), QStringLiteral(
"0" ) ).toInt();
950 fitInPolygonOnly = placementElem.attribute( QStringLiteral(
"fitInPolygonOnly" ), QStringLiteral(
"0" ) ).toInt();
951 dist = placementElem.attribute( QStringLiteral(
"dist" ) ).toDouble();
952 if ( !placementElem.hasAttribute( QStringLiteral(
"distUnits" ) ) )
954 if ( placementElem.attribute( QStringLiteral(
"distInMapUnits" ) ).toInt() )
963 if ( !placementElem.hasAttribute( QStringLiteral(
"distMapUnitScale" ) ) )
966 double oldMin = placementElem.attribute( QStringLiteral(
"distMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
968 double oldMax = placementElem.attribute( QStringLiteral(
"distMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
977 xOffset = placementElem.attribute( QStringLiteral(
"xOffset" ), QStringLiteral(
"0" ) ).toDouble();
978 yOffset = placementElem.attribute( QStringLiteral(
"yOffset" ), QStringLiteral(
"0" ) ).toDouble();
979 if ( !placementElem.hasAttribute( QStringLiteral(
"offsetUnits" ) ) )
987 if ( !placementElem.hasAttribute( QStringLiteral(
"labelOffsetMapUnitScale" ) ) )
990 double oldMin = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
992 double oldMax = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1000 if ( placementElem.hasAttribute( QStringLiteral(
"angleOffset" ) ) )
1002 double oldAngle = placementElem.attribute( QStringLiteral(
"angleOffset" ), QStringLiteral(
"0" ) ).toDouble();
1007 angleOffset = placementElem.attribute( QStringLiteral(
"rotationAngle" ), QStringLiteral(
"0" ) ).toDouble();
1010 preserveRotation = placementElem.attribute( QStringLiteral(
"preserveRotation" ), QStringLiteral(
"1" ) ).toInt();
1011 maxCurvedCharAngleIn = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleIn" ), QStringLiteral(
"25" ) ).toDouble();
1012 maxCurvedCharAngleOut = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleOut" ), QStringLiteral(
"-25" ) ).toDouble();
1013 priority = placementElem.attribute( QStringLiteral(
"priority" ) ).toInt();
1014 repeatDistance = placementElem.attribute( QStringLiteral(
"repeatDistance" ), QStringLiteral(
"0" ) ).toDouble();
1015 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceUnits" ) ) )
1018 switch ( placementElem.attribute( QStringLiteral(
"repeatDistanceUnit" ), QString::number( 1 ) ).toUInt() )
1038 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceMapUnitScale" ) ) )
1041 double oldMin = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1043 double oldMax = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1051 overrunDistance = placementElem.attribute( QStringLiteral(
"overrunDistance" ), QStringLiteral(
"0" ) ).toDouble();
1055 geometryGenerator = placementElem.attribute( QStringLiteral(
"geometryGenerator" ) );
1062 QDomElement renderingElem = elem.firstChildElement( QStringLiteral(
"rendering" ) );
1064 drawLabels = renderingElem.attribute( QStringLiteral(
"drawLabels" ), QStringLiteral(
"1" ) ).toInt();
1066 maximumScale = renderingElem.attribute( QStringLiteral(
"scaleMin" ), QStringLiteral(
"0" ) ).toDouble();
1067 minimumScale = renderingElem.attribute( QStringLiteral(
"scaleMax" ), QStringLiteral(
"0" ) ).toDouble();
1068 scaleVisibility = renderingElem.attribute( QStringLiteral(
"scaleVisibility" ) ).toInt();
1070 fontLimitPixelSize = renderingElem.attribute( QStringLiteral(
"fontLimitPixelSize" ), QStringLiteral(
"0" ) ).toInt();
1071 fontMinPixelSize = renderingElem.attribute( QStringLiteral(
"fontMinPixelSize" ), QStringLiteral(
"0" ) ).toInt();
1072 fontMaxPixelSize = renderingElem.attribute( QStringLiteral(
"fontMaxPixelSize" ), QStringLiteral(
"10000" ) ).toInt();
1073 displayAll = renderingElem.attribute( QStringLiteral(
"displayAll" ), QStringLiteral(
"0" ) ).toInt();
1076 labelPerPart = renderingElem.attribute( QStringLiteral(
"labelPerPart" ) ).toInt();
1077 mergeLines = renderingElem.attribute( QStringLiteral(
"mergeLines" ) ).toInt();
1078 mThinningSettings.
setMinimumFeatureSize( renderingElem.attribute( QStringLiteral(
"minFeatureSize" ) ).toDouble() );
1079 mThinningSettings.
setLimitNumberLabelsEnabled( renderingElem.attribute( QStringLiteral(
"limitNumLabels" ), QStringLiteral(
"0" ) ).toInt() );
1080 mThinningSettings.
setMaximumNumberLabels( renderingElem.attribute( QStringLiteral(
"maxNumLabels" ), QStringLiteral(
"2000" ) ).toInt() );
1081 mObstacleSettings.
setIsObstacle( renderingElem.attribute( QStringLiteral(
"obstacle" ), QStringLiteral(
"1" ) ).toInt() );
1082 mObstacleSettings.
setFactor( renderingElem.attribute( QStringLiteral(
"obstacleFactor" ), QStringLiteral(
"1" ) ).toDouble() );
1084 zIndex = renderingElem.attribute( QStringLiteral(
"zIndex" ), QStringLiteral(
"0.0" ) ).toDouble();
1086 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"dd_properties" ) );
1087 if ( !ddElem.isNull() )
1089 mDataDefinedProperties.
readXml( ddElem, *sPropertyDefinitions() );
1094 mDataDefinedProperties.
clear();
1095 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"data-defined" ) );
1096 readOldDataDefinedPropertyMap(
nullptr, &ddElem );
1137 const QString calloutType = elem.attribute( QStringLiteral(
"calloutType" ) );
1138 if ( calloutType.isEmpty() )
1150 QDomElement textStyleElem = mFormat.
writeXml( doc, context );
1153 textStyleElem.setAttribute( QStringLiteral(
"fieldName" ),
fieldName );
1154 textStyleElem.setAttribute( QStringLiteral(
"isExpression" ),
isExpression );
1155 QDomElement replacementElem = doc.createElement( QStringLiteral(
"substitutions" ) );
1157 textStyleElem.appendChild( replacementElem );
1158 textStyleElem.setAttribute( QStringLiteral(
"useSubstitutions" ),
useSubstitutions );
1161 QDomElement textFormatElem = doc.createElement( QStringLiteral(
"text-format" ) );
1162 textFormatElem.setAttribute( QStringLiteral(
"wrapChar" ),
wrapChar );
1163 textFormatElem.setAttribute( QStringLiteral(
"autoWrapLength" ),
autoWrapLength );
1165 textFormatElem.setAttribute( QStringLiteral(
"multilineAlign" ),
static_cast< unsigned int >(
multilineAlign ) );
1166 textFormatElem.setAttribute( QStringLiteral(
"addDirectionSymbol" ),
addDirectionSymbol );
1167 textFormatElem.setAttribute( QStringLiteral(
"leftDirectionSymbol" ),
leftDirectionSymbol );
1170 textFormatElem.setAttribute( QStringLiteral(
"placeDirectionSymbol" ),
static_cast< unsigned int >(
placeDirectionSymbol ) );
1171 textFormatElem.setAttribute( QStringLiteral(
"formatNumbers" ),
formatNumbers );
1172 textFormatElem.setAttribute( QStringLiteral(
"decimals" ),
decimals );
1173 textFormatElem.setAttribute( QStringLiteral(
"plussign" ),
plusSign );
1176 QDomElement placementElem = doc.createElement( QStringLiteral(
"placement" ) );
1177 placementElem.setAttribute( QStringLiteral(
"placement" ),
placement );
1178 placementElem.setAttribute( QStringLiteral(
"polygonPlacementFlags" ),
static_cast< int >( mPolygonPlacementFlags ) );
1179 placementElem.setAttribute( QStringLiteral(
"placementFlags" ),
static_cast< unsigned int >(
placementFlags ) );
1180 placementElem.setAttribute( QStringLiteral(
"centroidWhole" ),
centroidWhole );
1181 placementElem.setAttribute( QStringLiteral(
"centroidInside" ),
centroidInside );
1183 placementElem.setAttribute( QStringLiteral(
"fitInPolygonOnly" ),
fitInPolygonOnly );
1184 placementElem.setAttribute( QStringLiteral(
"dist" ),
dist );
1187 placementElem.setAttribute( QStringLiteral(
"offsetType" ),
static_cast< unsigned int >(
offsetType ) );
1188 placementElem.setAttribute( QStringLiteral(
"quadOffset" ),
static_cast< unsigned int >(
quadOffset ) );
1189 placementElem.setAttribute( QStringLiteral(
"xOffset" ),
xOffset );
1190 placementElem.setAttribute( QStringLiteral(
"yOffset" ),
yOffset );
1193 placementElem.setAttribute( QStringLiteral(
"rotationAngle" ),
angleOffset );
1194 placementElem.setAttribute( QStringLiteral(
"preserveRotation" ),
preserveRotation );
1197 placementElem.setAttribute( QStringLiteral(
"priority" ),
priority );
1198 placementElem.setAttribute( QStringLiteral(
"repeatDistance" ),
repeatDistance );
1201 placementElem.setAttribute( QStringLiteral(
"overrunDistance" ),
overrunDistance );
1205 placementElem.setAttribute( QStringLiteral(
"geometryGenerator" ),
geometryGenerator );
1207 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWkbTypes::GeometryType>() );
1208 placementElem.setAttribute( QStringLiteral(
"geometryGeneratorType" ), metaEnum.valueToKey(
geometryGeneratorType ) );
1210 placementElem.setAttribute( QStringLiteral(
"layerType" ), metaEnum.valueToKey(
layerType ) );
1213 QDomElement renderingElem = doc.createElement( QStringLiteral(
"rendering" ) );
1214 renderingElem.setAttribute( QStringLiteral(
"drawLabels" ),
drawLabels );
1215 renderingElem.setAttribute( QStringLiteral(
"scaleVisibility" ),
scaleVisibility );
1216 renderingElem.setAttribute( QStringLiteral(
"scaleMin" ),
maximumScale );
1217 renderingElem.setAttribute( QStringLiteral(
"scaleMax" ),
minimumScale );
1218 renderingElem.setAttribute( QStringLiteral(
"fontLimitPixelSize" ),
fontLimitPixelSize );
1219 renderingElem.setAttribute( QStringLiteral(
"fontMinPixelSize" ),
fontMinPixelSize );
1220 renderingElem.setAttribute( QStringLiteral(
"fontMaxPixelSize" ),
fontMaxPixelSize );
1221 renderingElem.setAttribute( QStringLiteral(
"displayAll" ),
displayAll );
1222 renderingElem.setAttribute( QStringLiteral(
"upsidedownLabels" ),
static_cast< unsigned int >(
upsidedownLabels ) );
1224 renderingElem.setAttribute( QStringLiteral(
"labelPerPart" ),
labelPerPart );
1225 renderingElem.setAttribute( QStringLiteral(
"mergeLines" ),
mergeLines );
1226 renderingElem.setAttribute( QStringLiteral(
"minFeatureSize" ), mThinningSettings.
minimumFeatureSize() );
1228 renderingElem.setAttribute( QStringLiteral(
"maxNumLabels" ), mThinningSettings.
maximumNumberLabels() );
1229 renderingElem.setAttribute( QStringLiteral(
"obstacle" ), mObstacleSettings.
isObstacle() );
1230 renderingElem.setAttribute( QStringLiteral(
"obstacleFactor" ), mObstacleSettings.
factor() );
1231 renderingElem.setAttribute( QStringLiteral(
"obstacleType" ),
static_cast< unsigned int >( mObstacleSettings.
type() ) );
1232 renderingElem.setAttribute( QStringLiteral(
"zIndex" ),
zIndex );
1234 QDomElement ddElem = doc.createElement( QStringLiteral(
"dd_properties" ) );
1235 mDataDefinedProperties.
writeXml( ddElem, *sPropertyDefinitions() );
1237 QDomElement elem = doc.createElement( QStringLiteral(
"settings" ) );
1238 elem.appendChild( textStyleElem );
1239 elem.appendChild( textFormatElem );
1240 elem.appendChild( placementElem );
1241 elem.appendChild( renderingElem );
1242 elem.appendChild( ddElem );
1246 elem.setAttribute( QStringLiteral(
"calloutType" ), mCallout->type() );
1247 mCallout->saveProperties( doc, elem, context );
1262 QPixmap pixmap( size );
1263 pixmap.fill( Qt::transparent );
1265 painter.begin( &pixmap );
1267 painter.setRenderHint( QPainter::Antialiasing );
1269 QRect rect( 0, 0, size.width(), size.height() );
1272 painter.setPen( Qt::NoPen );
1274 if ( ( background1.lightnessF() < 0.7 ) )
1276 background1 = background1.darker( 125 );
1280 background1 = background1.lighter( 125 );
1283 QLinearGradient linearGrad( QPointF( 0, 0 ), QPointF( 0, rect.height() ) );
1284 linearGrad.setColorAt( 0, background1 );
1285 linearGrad.setColorAt( 1, background2 );
1286 painter.setBrush( QBrush( linearGrad ) );
1287 if ( size.width() > 30 )
1289 painter.drawRoundedRect( rect, 6, 6 );
1294 painter.drawRect( rect );
1296 painter.setBrush( Qt::NoBrush );
1297 painter.setPen( Qt::NoPen );
1305 context.
setScaleFactor( QgsApplication::desktop()->logicalDpiX() / 25.4 );
1316 double ytrans = 0.0;
1322 const QStringList text = QStringList() << ( previewText.isEmpty() ? QObject::tr(
"Aa" ) : previewText );
1324 QRectF textRect = rect;
1325 textRect.setLeft( xtrans + padding );
1326 textRect.setWidth( rect.width() - xtrans - 2 * padding );
1328 if ( textRect.width() > 2000 )
1329 textRect.setWidth( 2000 - 2 * padding );
1331 const double bottom = textRect.height() / 2 + textHeight / 2;
1332 textRect.setTop( bottom - textHeight );
1333 textRect.setBottom( bottom );
1344 QRectF labelRect( textRect.left() + ( textRect.width() - textWidth ) / 2.0, textRect.top(), textWidth, textRect.height() );
1351 if ( size.width() > 30 )
1356 rect.width() - iconWidth * 3, rect.height() - iconWidth * 3,
1357 iconWidth * 2, iconWidth * 2 ), Qt::AlignRight | Qt::AlignBottom );
1361 painter.setBrush( Qt::NoBrush );
1363 if ( size.width() > 30 )
1365 painter.drawRoundedRect( rect, 6, 6 );
1370 painter.drawRect( rect );
1379 return QgsPalLabeling::checkMinimumSizeMM(
ct, geom, minSize );
1389 QString textCopy( text );
1392 std::unique_ptr< QgsRenderContext > scopedRc;
1397 scopedRc->expressionContext().setFeature( *f );
1513 if ( wrapchr.isEmpty() )
1515 wrapchr = QStringLiteral(
"\n" );
1520 && ( !leftDirSymb.isEmpty() || !rightDirSymb.isEmpty() ) )
1522 QString dirSym = leftDirSymb;
1524 if ( fm->width( rightDirSymb ) > fm->width( dirSym ) )
1525 dirSym = rightDirSymb;
1529 textCopy.append( dirSym );
1533 textCopy.prepend( dirSym + QStringLiteral(
"\n" ) );
1537 double w = 0.0, h = 0.0, rw = 0.0, rh = 0.0;
1538 double labelHeight = fm->ascent() + fm->descent();
1540 QStringList multiLineSplit;
1552 int lines = multiLineSplit.size();
1554 switch ( orientation )
1558 h += fm->height() +
static_cast< double >( ( lines - 1 ) * labelHeight * multilineH );
1560 for (
const auto &line : multiLineSplit )
1562 w = std::max( w, fm->width( line ) );
1569 double letterSpacing = mFormat.
scaledFont( *context ).letterSpacing();
1570 double labelWidth = fm->maxWidth();
1571 w = labelWidth + ( lines - 1 ) * labelWidth * multilineH;
1573 int maxLineLength = 0;
1574 for (
const auto &line : multiLineSplit )
1576 maxLineLength = std::max( maxLineLength, line.length() );
1578 h = fm->ascent() * maxLineLength + ( maxLineLength - 1 ) * letterSpacing;
1584 double widthHorizontal = 0.0;
1585 for (
const auto &line : multiLineSplit )
1587 widthHorizontal = std::max( w, fm->width( line ) );
1590 double widthVertical = 0.0;
1591 double letterSpacing = mFormat.
scaledFont( *context ).letterSpacing();
1592 double labelWidth = fm->maxWidth();
1593 widthVertical = labelWidth + ( lines - 1 ) * labelWidth * multilineH;
1595 double heightHorizontal = 0.0;
1596 heightHorizontal += fm->height() +
static_cast< double >( ( lines - 1 ) * labelHeight * multilineH );
1598 double heightVertical = 0.0;
1599 int maxLineLength = 0;
1600 for (
const auto &line : multiLineSplit )
1602 maxLineLength = std::max( maxLineLength, line.length() );
1604 heightVertical = fm->ascent() * maxLineLength + ( maxLineLength - 1 ) * letterSpacing;
1606 w = widthHorizontal;
1607 rw = heightVertical;
1608 h = heightHorizontal;
1616 labelX = std::fabs( ptSize.
x() -
ptZero.
x() );
1617 labelY = std::fabs( ptSize.
y() -
ptZero.
y() );
1622 if ( rotatedLabelX && rotatedLabelY )
1624 *rotatedLabelX = rw * uPP;
1625 *rotatedLabelY = rh * uPP;
1633 Q_ASSERT( labelFeature );
1639 bool isObstacle = mObstacleSettings.
isObstacle();
1647 registerObstacleFeature( f, context, labelFeature, obstacleGeometry );
1659 if ( obstacleGeometry.
isNull() )
1672 dataDefinedValues.clear();
1689 if ( useScaleVisibility )
1702 maxScale = 1 / std::fabs( maxScale );
1721 minScale = 1 / std::fabs( minScale );
1730 QFont labelFont = mFormat.
font();
1736 if ( exprVal.isValid() )
1738 QString units = exprVal.toString();
1739 if ( !units.isEmpty() )
1749 double fontSize = mFormat.
size();
1755 if ( fontSize <= 0.0 )
1762 if ( fontPixelSize < 1 )
1766 labelFont.setPixelSize( fontPixelSize );
1778 if ( fontMinPixel > labelFont.pixelSize() || labelFont.pixelSize() > fontMaxPixel )
1790 labelFont.setCapitalization( QFont::MixedCase );
1792 parseTextStyle( labelFont, fontunits, context );
1795 parseTextFormatting( context );
1796 parseTextBuffer( context );
1797 parseTextMask( context );
1798 parseShapeBackground( context );
1799 parseDropShadow( context );
1820 labelText = result.isNull() ? QString() : result.toString();
1825 labelText = v.isNull() ? QString() : v.toString();
1837 if ( mFormat.
font().capitalization() != QFont::MixedCase )
1845 if ( exprVal.isValid() )
1847 QString fcase = exprVal.toString().trimmed();
1848 QgsDebugMsgLevel( QStringLiteral(
"exprVal FontCase:%1" ).arg( fcase ), 4 );
1850 if ( !fcase.isEmpty() )
1852 if ( fcase.compare( QLatin1String(
"NoChange" ), Qt::CaseInsensitive ) == 0 )
1856 else if ( fcase.compare( QLatin1String(
"Upper" ), Qt::CaseInsensitive ) == 0 )
1860 else if ( fcase.compare( QLatin1String(
"Lower" ), Qt::CaseInsensitive ) == 0 )
1864 else if ( fcase.compare( QLatin1String(
"Capitalize" ), Qt::CaseInsensitive ) == 0 )
1879 if ( evalFormatNumbers )
1883 if ( decimalPlaces <= 0 )
1889 QVariant textV( labelText );
1891 double d = textV.toDouble( &ok );
1894 QString numberFormat;
1895 if ( d > 0 && signPlus )
1897 numberFormat.append(
'+' );
1899 numberFormat.append(
"%1" );
1900 labelText = numberFormat.arg( d, 0,
'f', decimalPlaces );
1905 std::unique_ptr<QFontMetricsF> labelFontMetrics(
new QFontMetricsF( labelFont ) );
1906 double labelX, labelY, rotatedLabelX, rotatedLabelY;
1909 if (
format().allowHtmlFormatting() )
1913 calculateLabelSize( labelFontMetrics.get(), labelText, labelX, labelY,
mCurFeat, &context, &rotatedLabelX, &rotatedLabelY,
format().allowHtmlFormatting() ? &doc :
nullptr );
1917 double maxcharanglein = 20.0;
1918 double maxcharangleout = -20.0;
1933 maxcharanglein = qBound( 20.0,
static_cast< double >( maxcharanglePt.x() ), 60.0 );
1934 maxcharangleout = qBound( 20.0,
static_cast< double >( maxcharanglePt.y() ), 95.0 );
1938 maxcharangleout = -( std::fabs( maxcharangleout ) );
1946 if ( exprVal.isValid() )
1948 QString str = exprVal.toString().trimmed();
1949 QgsDebugMsgLevel( QStringLiteral(
"exprVal CentroidWhole:%1" ).arg( str ), 4 );
1951 if ( !str.isEmpty() )
1953 if ( str.compare( QLatin1String(
"Visible" ), Qt::CaseInsensitive ) == 0 )
1955 wholeCentroid =
false;
1957 else if ( str.compare( QLatin1String(
"Whole" ), Qt::CaseInsensitive ) == 0 )
1959 wholeCentroid =
true;
1973 std::unique_ptr<QgsGeometry> scopedClonedGeom;
1980 geom = simplifier.
simplify( geom );
1990 bool doClip =
false;
1991 if ( !centroidPoly || !wholeCentroid )
1997 QgsLabeling::PolygonPlacementFlags polygonPlacement = mPolygonPlacementFlags;
2001 if ( dataDefinedOutside.isValid() )
2003 if ( dataDefinedOutside.type() == QVariant::String )
2005 const QString value = dataDefinedOutside.toString().trimmed();
2006 if ( value.compare( QLatin1String(
"force" ), Qt::CaseInsensitive ) == 0 )
2009 polygonPlacement &= ~static_cast< int >( QgsLabeling::PolygonPlacementFlag::AllowPlacementInsideOfPolygon );
2010 polygonPlacement |= QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon;
2012 else if ( value.compare( QLatin1String(
"yes" ), Qt::CaseInsensitive ) == 0 )
2015 polygonPlacement |= QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon;
2017 else if ( value.compare( QLatin1String(
"no" ), Qt::CaseInsensitive ) == 0 )
2020 polygonPlacement &= ~static_cast< int >( QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon );
2025 if ( dataDefinedOutside.toBool() )
2028 polygonPlacement |= QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon;
2033 polygonPlacement &= ~static_cast< int >( QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon );
2045 permissibleZone = geom;
2084 if ( !geos_geom_clone )
2113 bool dataDefinedPosition =
false;
2114 bool layerDefinedRotation =
false;
2115 bool dataDefinedRotation =
false;
2116 double xPos = 0.0, yPos = 0.0,
angle = 0.0;
2117 bool ddXPos =
false, ddYPos =
false;
2118 double quadOffsetX = 0.0, quadOffsetY = 0.0;
2119 double offsetX = 0.0, offsetY = 0.0;
2131 bool ddFixedQuad =
false;
2137 if ( exprVal.isValid() )
2140 int quadInt = exprVal.toInt( &ok );
2141 if ( ok && 0 <= quadInt && quadInt <= 8 )
2209 if ( exprVal.isValid() )
2211 QString units = exprVal.toString().trimmed();
2212 if ( !units.isEmpty() )
2218 offUnit = decodedUnits;
2234 layerDefinedRotation =
true;
2244 if ( exprVal.isValid() )
2247 double rotD = exprVal.toDouble( &ok );
2250 dataDefinedRotation =
true;
2254 angle = ( 360 - rotD ) * M_PI / 180.0;
2262 if ( exprVal.isValid() )
2264 if ( !exprVal.isNull() )
2265 xPos = exprVal.toDouble( &ddXPos );
2270 if ( exprVal.isValid() )
2273 if ( !exprVal.isNull() )
2274 yPos = exprVal.toDouble( &ddYPos );
2276 if ( ddXPos && ddYPos )
2278 dataDefinedPosition =
true;
2280 if ( layerDefinedRotation && !dataDefinedRotation )
2289 if ( exprVal.isValid() )
2291 QString haliString = exprVal.toString();
2292 if ( haliString.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
2294 xdiff -= labelX / 2.0;
2296 else if ( haliString.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
2307 if ( exprVal.isValid() )
2309 QString valiString = exprVal.toString();
2310 if ( valiString.compare( QLatin1String(
"Bottom" ), Qt::CaseInsensitive ) != 0 )
2312 if ( valiString.compare( QLatin1String(
"Top" ), Qt::CaseInsensitive ) == 0 )
2318 double descentRatio = labelFontMetrics->descent() / labelFontMetrics->height();
2319 if ( valiString.compare( QLatin1String(
"Base" ), Qt::CaseInsensitive ) == 0 )
2321 ydiff -= labelY * descentRatio;
2325 double capHeightRatio = ( labelFontMetrics->boundingRect(
'H' ).height() + 1 + labelFontMetrics->descent() ) / labelFontMetrics->height();
2326 ydiff -= labelY * capHeightRatio;
2327 if ( valiString.compare( QLatin1String(
"Half" ), Qt::CaseInsensitive ) == 0 )
2329 ydiff += labelY * ( capHeightRatio - descentRatio ) / 2.0;
2337 if ( dataDefinedRotation )
2340 double xd = xdiff * std::cos(
angle ) - ydiff * std::sin(
angle );
2341 double yd = xdiff * std::sin(
angle ) + ydiff * std::cos(
angle );
2376 bool alwaysShow =
false;
2396 if ( exprVal.isValid() )
2398 QString units = exprVal.toString().trimmed();
2399 if ( !units.isEmpty() )
2405 repeatUnits = decodedUnits;
2437 if ( !dataDefinedPosition )
2458 ( *labelFeature )->setFixedPosition(
QgsPointXY( xPos, yPos ) );
2460 ( *labelFeature )->setHasFixedAngle( dataDefinedRotation || ( !dataDefinedPosition && !
qgsDoubleNear(
angle, 0.0 ) ) );
2461 ( *labelFeature )->setFixedAngle(
angle );
2462 ( *labelFeature )->setQuadOffset( QPointF( quadOffsetX, quadOffsetY ) );
2463 ( *labelFeature )->setPositionOffset(
QgsPointXY( offsetX, offsetY ) );
2464 ( *labelFeature )->setOffsetType(
offsetType );
2465 ( *labelFeature )->setAlwaysShow( alwaysShow );
2466 ( *labelFeature )->setRepeatDistance( repeatDist );
2467 ( *labelFeature )->setLabelText( labelText );
2468 ( *labelFeature )->setPermissibleZone( permissibleZone );
2469 ( *labelFeature )->setOverrunDistance( overrunDistanceEval );
2470 ( *labelFeature )->setOverrunSmoothDistance( overrunSmoothDist );
2471 ( *labelFeature )->setLabelAllParts( labelAll );
2475 ( *labelFeature )->setSymbolSize( QSizeF( obstacleGeometry.
boundingBox().
width(),
2481 double topMargin = std::max( 0.25 * labelFontMetrics->ascent(), 0.0 );
2482 double bottomMargin = 1.0 + labelFontMetrics->descent();
2483 QgsMargins vm( 0.0, topMargin, 0.0, bottomMargin );
2485 ( *labelFeature )->setVisualMargin( vm );
2488 QgsDebugMsgLevel( QStringLiteral(
"PAL font stored definedFont: %1, Style: %2" ).arg( labelFont.toString(), labelFont.styleName() ), 4 );
2494 labelFontMetrics.get(),
xform, maxcharanglein, maxcharangleout,
format().allowHtmlFormatting() ? &doc :
nullptr );
2500 double distance =
dist;
2512 if ( exprVal.isValid() )
2514 QString units = exprVal.toString().trimmed();
2515 QgsDebugMsgLevel( QStringLiteral(
"exprVal DistanceUnits:%1" ).arg( units ), 4 );
2516 if ( !units.isEmpty() )
2522 distUnit = decodedUnits;
2535 distance = ( distance < 0 ? -1 : 1 ) * std::max( std::fabs( distance ), 1.0 );
2543 distance = std::max( distance, 2.0 );
2549 ( *labelFeature )->setDistLabel( d );
2554 ( *labelFeature )->setHasFixedQuadrant(
true );
2557 QgsLabeling::LinePlacementFlags featureArrangementFlags =
static_cast< QgsLabeling::LinePlacementFlags
>(
placementFlags );
2562 if ( !dataDefinedLineArrangement.isEmpty() )
2567 ( *labelFeature )->setArrangementFlags( featureArrangementFlags );
2569 ( *labelFeature )->setPolygonPlacementFlags( polygonPlacement );
2578 ( *labelFeature )->setZIndex( z );
2585 if ( exprVal.isValid() )
2588 double priorityD = exprVal.toDouble( &ok );
2591 priorityD = qBound( 0.0, priorityD, 10.0 );
2592 priorityD = 1 - priorityD / 10.0;
2593 ( *labelFeature )->setPriority( priorityD );
2605 if ( positionOrder.isEmpty() )
2606 positionOrder = *DEFAULT_PLACEMENT_ORDER();
2612 if ( !dataDefinedOrder.isEmpty() )
2617 ( *labelFeature )->setPredefinedPositionOrder( positionOrder );
2628 if ( !obstacleGeometry.
isNull() )
2630 geom = obstacleGeometry;
2644 std::unique_ptr<QgsGeometry> scopedClonedGeom;
2650 geom = simplifier.
simplify( geom );
2654 std::unique_ptr<QgsGeometry> scopedPreparedGeom;
2662 if ( !geos_geom_clone )
2666 *obstacleFeature =
new QgsLabelFeature( f.
id(), std::move( geos_geom_clone ), QSizeF( 0, 0 ) );
2667 ( *obstacleFeature )->setFeature( f );
2672 ( *obstacleFeature )->setObstacleSettings( os );
2677 bool QgsPalLayerSettings::dataDefinedValEval( DataDefinedValueType valType,
2681 if ( !mDataDefinedProperties.
isActive( p ) )
2685 exprVal = mDataDefinedProperties.
value( p, context );
2686 if ( exprVal.isValid() )
2692 bool bol = exprVal.toBool();
2693 dataDefinedValues.insert( p, QVariant( bol ) );
2699 int size = exprVal.toInt( &ok );
2703 dataDefinedValues.insert( p, QVariant( size ) );
2711 int size = exprVal.toInt( &ok );
2713 if ( ok && size > 0 )
2715 dataDefinedValues.insert( p, QVariant( size ) );
2723 double size = exprVal.toDouble( &ok );
2727 dataDefinedValues.insert( p, QVariant( size ) );
2735 double size = exprVal.toDouble( &ok );
2737 if ( ok && size > 0.0 )
2739 dataDefinedValues.insert( p, QVariant( size ) );
2747 double rot = exprVal.toDouble( &ok );
2750 if ( rot < -180.0 && rot >= -360 )
2754 if ( rot > 180.0 && rot <= 360 )
2758 if ( rot >= -180 && rot <= 180 )
2760 dataDefinedValues.insert( p, QVariant( rot ) );
2769 int size = exprVal.toInt( &ok );
2770 if ( ok && size >= 0 && size <= 100 )
2772 dataDefinedValues.insert( p, QVariant( size ) );
2779 QString str = exprVal.toString();
2781 dataDefinedValues.insert( p, QVariant( str ) );
2786 QString unitstr = exprVal.toString().trimmed();
2788 if ( !unitstr.isEmpty() )
2797 QString colorstr = exprVal.toString().trimmed();
2800 if ( color.isValid() )
2802 dataDefinedValues.insert( p, QVariant( color ) );
2809 QString joinstr = exprVal.toString().trimmed();
2811 if ( !joinstr.isEmpty() )
2820 QString blendstr = exprVal.toString().trimmed();
2822 if ( !blendstr.isEmpty() )
2835 dataDefinedValues.insert( p, res );
2846 dataDefinedValues.insert( p, res );
2856 void QgsPalLayerSettings::parseTextStyle( QFont &labelFont,
2869 QString ddFontFamily;
2874 if ( exprVal.isValid() )
2876 QString family = exprVal.toString().trimmed();
2877 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font family:%1" ).arg( family ), 4 );
2879 if ( labelFont.family() != family )
2885 ddFontFamily = family;
2892 QString ddFontStyle;
2896 if ( exprVal.isValid() )
2898 QString fontstyle = exprVal.toString().trimmed();
2899 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font style:%1" ).arg( fontstyle ), 4 );
2900 ddFontStyle = fontstyle;
2905 bool ddBold =
false;
2913 bool ddItalic =
false;
2923 QFont appFont = QApplication::font();
2924 bool newFontBuilt =
false;
2925 if ( ddBold || ddItalic )
2928 newFont = QFont( !ddFontFamily.isEmpty() ? ddFontFamily : labelFont.family() );
2929 newFontBuilt =
true;
2930 newFont.setBold( ddBold );
2931 newFont.setItalic( ddItalic );
2933 else if ( !ddFontStyle.isEmpty()
2934 && ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2936 if ( !ddFontFamily.isEmpty() )
2939 QFont styledfont = mFontDB.font( ddFontFamily, ddFontStyle, appFont.pointSize() );
2940 if ( appFont != styledfont )
2942 newFont = styledfont;
2943 newFontBuilt =
true;
2950 else if ( !ddFontFamily.isEmpty() )
2952 if ( ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2955 QFont styledfont = mFontDB.font( ddFontFamily, mFormat.
namedStyle(), appFont.pointSize() );
2956 if ( appFont != styledfont )
2958 newFont = styledfont;
2959 newFontBuilt =
true;
2964 newFont = QFont( ddFontFamily );
2965 newFontBuilt =
true;
2973 newFont.setPixelSize( labelFont.pixelSize() );
2974 newFont.setUnderline( labelFont.underline() );
2975 newFont.setStrikeOut( labelFont.strikeOut() );
2976 newFont.setWordSpacing( labelFont.wordSpacing() );
2977 newFont.setLetterSpacing( QFont::AbsoluteSpacing, labelFont.letterSpacing() );
2979 labelFont = newFont;
2983 double wordspace = labelFont.wordSpacing();
2992 double letterspace = labelFont.letterSpacing();
3005 labelFont.setStrikeOut( strikeout );
3013 labelFont.setUnderline( underline );
3039 drawBuffer = exprVal.toBool();
3053 double bufrSize = buffer.
size();
3056 bufrSize = exprVal.toDouble();
3060 double bufferOpacity = buffer.
opacity() * 100;
3063 bufferOpacity = exprVal.toDouble();
3066 drawBuffer = ( drawBuffer && bufrSize > 0.0 && bufferOpacity > 0 );
3096 bool maskEnabled = mask.
enabled();
3099 maskEnabled = exprVal.toBool();
3108 double bufrSize = mask.
size();
3111 bufrSize = exprVal.toDouble();
3115 double opacity = mask.
opacity() * 100;
3118 opacity = exprVal.toDouble();
3121 maskEnabled = ( maskEnabled && bufrSize > 0.0 && opacity > 0 );
3146 wrapchr = exprVal.toString();
3152 evalAutoWrapLength = exprVal.toInt();
3163 if ( exprVal.isValid() )
3165 QString str = exprVal.toString().trimmed();
3166 QgsDebugMsgLevel( QStringLiteral(
"exprVal MultiLineAlignment:%1" ).arg( str ), 4 );
3168 if ( !str.isEmpty() )
3173 if ( str.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
3177 else if ( str.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
3181 else if ( str.compare( QLatin1String(
"Follow" ), Qt::CaseInsensitive ) == 0 )
3196 if ( exprVal.isValid() )
3198 QString str = exprVal.toString().trimmed();
3199 if ( !str.isEmpty() )
3208 drawDirSymb = exprVal.toBool();
3221 if ( exprVal.isValid() )
3223 QString str = exprVal.toString().trimmed();
3224 QgsDebugMsgLevel( QStringLiteral(
"exprVal DirSymbPlacement:%1" ).arg( str ), 4 );
3226 if ( !str.isEmpty() )
3231 if ( str.compare( QLatin1String(
"Above" ), Qt::CaseInsensitive ) == 0 )
3235 else if ( str.compare( QLatin1String(
"Below" ), Qt::CaseInsensitive ) == 0 )
3250 void QgsPalLayerSettings::parseShapeBackground(
QgsRenderContext &context )
3257 bool drawShape = background.
enabled();
3260 drawShape = exprVal.toBool();
3269 double shapeOpacity = background.
opacity() * 100;
3272 shapeOpacity = 100.0 * exprVal.toDouble();
3275 drawShape = ( drawShape && shapeOpacity > 0 );
3289 if ( exprVal.isValid() )
3291 QString skind = exprVal.toString().trimmed();
3292 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeKind:%1" ).arg( skind ), 4 );
3294 if ( !skind.isEmpty() )
3303 QString svgPath = background.
svgFile();
3308 if ( exprVal.isValid() )
3310 QString svgfile = exprVal.toString().trimmed();
3311 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSVGFile:%1" ).arg( svgfile ), 4 );
3324 if ( exprVal.isValid() )
3326 QString stype = exprVal.toString().trimmed();
3327 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSizeType:%1" ).arg( stype ), 4 );
3329 if ( !stype.isEmpty() )
3338 double ddShpSizeX = background.
size().width();
3341 ddShpSizeX = exprVal.toDouble();
3345 double ddShpSizeY = background.
size().height();
3348 ddShpSizeY = exprVal.toDouble();
3354 && ( svgPath.isEmpty()
3355 || ( !svgPath.isEmpty()
3357 && ddShpSizeX == 0.0 ) ) )
3365 && ddShpSizeX == 0.0 ) ) )
3372 && ( ddShpSizeX == 0.0 || ddShpSizeY == 0.0 ) )
3395 if ( exprVal.isValid() )
3397 QString rotstr = exprVal.toString().trimmed();
3398 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeRotationType:%1" ).arg( rotstr ), 4 );
3400 if ( !rotstr.isEmpty() )
3451 bool drawShadow = shadow.
enabled();
3454 drawShadow = exprVal.toBool();
3463 double shadowOpacity = shadow.
opacity() * 100;
3466 shadowOpacity = exprVal.toDouble();
3473 shadowOffDist = exprVal.toDouble();
3480 shadowRad = exprVal.toDouble();
3483 drawShadow = ( drawShadow && shadowOpacity > 0 && !( shadowOffDist == 0.0 && shadowRad == 0.0 ) );
3498 if ( exprVal.isValid() )
3500 QString str = exprVal.toString().trimmed();
3501 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShadowUnder:%1" ).arg( str ), 4 );
3503 if ( !str.isEmpty() )
3574 QStringList
QgsPalLabeling::splitToLines(
const QString &text,
const QString &wrapCharacter,
const int autoWrapLength,
const bool useMaxLineLengthWhenAutoWrapping )
3576 QStringList multiLineSplit;
3577 if ( !wrapCharacter.isEmpty() && wrapCharacter != QLatin1String(
"\n" ) )
3580 const QStringList lines = text.split( wrapCharacter );
3581 for (
const QString &line : lines )
3583 multiLineSplit.append( line.split(
'\n' ) );
3588 multiLineSplit = text.split(
'\n' );
3592 if ( autoWrapLength != 0 )
3594 QStringList autoWrappedLines;
3595 autoWrappedLines.reserve( multiLineSplit.count() );
3596 for (
const QString &line : qgis::as_const( multiLineSplit ) )
3598 autoWrappedLines.append(
QgsStringUtils::wordWrap( line, autoWrapLength, useMaxLineLengthWhenAutoWrapping ).split(
'\n' ) );
3600 multiLineSplit = autoWrappedLines;
3602 return multiLineSplit;
3607 QStringList graphemes;
3608 QTextBoundaryFinder boundaryFinder( QTextBoundaryFinder::Grapheme, text );
3609 int currentBoundary = -1;
3610 int previousBoundary = 0;
3611 while ( ( currentBoundary = boundaryFinder.toNextBoundary() ) > 0 )
3613 graphemes << text.mid( previousBoundary, currentBoundary - previousBoundary );
3614 previousBoundary = currentBoundary;
3644 QgsDebugMsgLevel( QStringLiteral(
"Ignoring feature due to transformation exception" ), 4 );
3650 return std::isfinite( point.
x() ) && std::isfinite( point.
y() );
3653 cp->removeInvalidRings();
3663 QgsDebugMsg( QStringLiteral(
"Error rotating geometry" ).arg( geom.
asWkt() ) );
3677 QVector< QgsGeometry> parts;
3678 parts.reserve( qgsgeometry_cast< const QgsGeometryCollection * >( geom.
constGet() )->numGeometries() );
3684 partGeom = partGeom.
buffer( 0, 0 );
3686 parts.append( partGeom );
3693 if ( bufferGeom.
isNull() )
3695 QgsDebugMsg( QStringLiteral(
"Could not repair geometry: %1" ).arg( bufferGeom.
lastError() ) );
3702 if ( !clipGeometry.
isNull() &&
3738 double length = geom.
length();
3739 if ( length >= 0.0 )
3741 return ( length >= ( minSize * mapUnitsPerMM ) );
3746 double area = geom.
area();
3749 return ( std::sqrt( area ) >= ( minSize * mapUnitsPerMM ) );
3757 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3760 bool changed =
false;
3766 format.
setColor( ddColor.value<QColor>() );
3791 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3853 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3856 bool changed =
false;
3904 buffer.
setColor( ddColor.value<QColor>() );
3931 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3933 if ( ddValues.isEmpty() )
3937 bool changed =
false;
3997 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4000 bool changed =
false;
4040 QSizeF size = background.
size();
4047 QSizeF size = background.
size();
4148 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4151 bool changed =
false;
4210 shadow.
setColor( ddColor.value<QColor>() );
4248 #if 0 // TODO: generalize some of this
4251 double cx = lp->
getX() + w / 2.0;
4252 double cy = lp->
getY() + h / 2.0;
4255 double sw = w * scale;
4256 double sh = h * scale;
4257 QRectF rect( -sw / 2, -sh / 2, sw, sh );
4259 painter->translate( xform->
transform( QPointF( cx, cy ) ).toQPointF() );
4263 if ( lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT &&
4264 lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT_OVER &&
4267 painter->rotate( rotation );
4270 painter->translate( rect.bottomLeft() );
4271 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
4272 painter->translate( -rect.bottomLeft() );
4275 QRectF rect( 0, 0, outPt2.
x() - outPt.
x(), outPt2.
y() - outPt.
y() );
4276 painter->translate( QPointF( outPt.
x(), outPt.
y() ) );
4277 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
4282 painter->setPen( QColor( 255, 0, 0, 64 ) );
4286 painter->setPen( QColor( 0, 0, 0, 64 ) );
4288 painter->drawRect( rect );
4292 rect.moveTo( outPt.
x(), outPt.
y() );
4310 QList<QgsLabelPosition> positions;
4312 QList<QgsLabelPosition *> positionPointers;
4313 if ( mLabelSearchTree )
4315 mLabelSearchTree->label( p, positionPointers );
4316 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
4317 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
4328 QList<QgsLabelPosition> positions;
4330 QList<QgsLabelPosition *> positionPointers;
4331 if ( mLabelSearchTree )
4333 mLabelSearchTree->labelsInRect( r, positionPointers );
4334 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
4335 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
4346 mLabelSearchTree->setMapSettings( settings );