35 #include <QApplication>
38 #include <QFontMetrics>
41 #include <QDesktopWidget>
42 #include <QTextBoundaryFinder>
73 #include <QMessageBox>
109 if ( !sPropertyDefinitions()->isEmpty() )
112 const QString origin = QStringLiteral(
"labeling" );
124 "e.g. Helvetica or Helvetica [Cronyx]" ), origin )
128 "e.g. Bold Condensed or Light Italic" ), origin )
168 "<b>Ellipse</b>|<b>Circle</b>|<b>SVG</b>]" ), origin )
192 "<b>Buffer</b>|<b>Background</b>]" ), origin )
208 "<b>3</b>=Left|<b>4</b>=Over|<b>5</b>=Right|<br>"
209 "<b>6</b>=Below Left|<b>7</b>=Below|<b>8</b>=Below Right]" ), origin )
226 + QStringLiteral(
"[<b>TL</b>=Top left|<b>TSL</b>=Top, slightly left|<b>T</b>=Top middle|<br>"
227 "<b>TSR</b>=Top, slightly right|<b>TR</b>=Top right|<br>"
228 "<b>L</b>=Left|<b>R</b>=Right|<br>"
229 "<b>BL</b>=Bottom left|<b>BSL</b>=Bottom, slightly left|<b>B</b>=Bottom middle|<br>"
230 "<b>BSR</b>=Bottom, slightly right|<b>BR</b>=Bottom right]" ), origin )
234 + QStringLiteral(
"[<b>OL</b>=On line|<b>AL</b>=Above line|<b>BL</b>=Below line|<br>"
235 "<b>LO</b>=Respect line orientation]" ), origin )
243 "<b>Half</b>|<b>Cap</b>|<b>Top</b>]" ), origin )
266 : predefinedPositionOrder( *DEFAULT_PLACEMENT_ORDER() )
269 initPropertyDefinitions();
276 , mDataDefinedProperties( s.mDataDefinedProperties )
311 mPolygonPlacementFlags = s.mPolygonPlacementFlags;
348 mDataDefinedProperties = s.mDataDefinedProperties;
350 mCallout.reset( s.mCallout ? s.mCallout->clone() :
nullptr );
352 mLineSettings = s.mLineSettings;
353 mObstacleSettings = s.mObstacleSettings;
354 mThinningSettings = s.mThinningSettings;
409 for (
const QString &name : referencedColumns )
411 attributeNames.insert( name );
467 for (
const QString &name : referencedColumns )
469 attributeNames.insert( name );
476 const auto referencedColumns = mCallout->referencedFields( context );
477 for (
const QString &name : referencedColumns )
479 attributeNames.insert( name );
488 QSet<QString> referenced;
516 referenced.unite( mCallout->referencedFields( context ) );
524 if ( mRenderStarted )
526 qWarning(
"Start render called for when a previous render was already underway!!" );
539 mCallout->startRender( context );
542 mRenderStarted =
true;
547 if ( !mRenderStarted )
549 qWarning(
"Stop render called for QgsPalLayerSettings without a startRender call!" );
555 mCallout->stopRender( context );
558 mRenderStarted =
false;
563 if ( mRenderStarted )
565 qWarning(
"stopRender was not called on QgsPalLayerSettings object!" );
576 initPropertyDefinitions();
577 return *sPropertyDefinitions();
592 QString newValue = value;
593 if ( !value.isEmpty() && !value.contains( QLatin1String(
"~~" ) ) )
596 values << QStringLiteral(
"1" );
597 values << QStringLiteral(
"0" );
600 newValue = values.join( QLatin1String(
"~~" ) );
608 QString newPropertyName =
"labeling/dataDefined/" + sPropertyDefinitions()->value( p ).name();
609 QVariant newPropertyField = layer->
customProperty( newPropertyName, QVariant() );
611 if ( !newPropertyField.isValid() )
614 QString ddString = newPropertyField.toString();
616 if ( !ddString.isEmpty() && ddString != QLatin1String(
"0~~0~~~~" ) )
620 QStringList ddv = newStyleString.split( QStringLiteral(
"~~" ) );
622 bool active = ddv.at( 0 ).toInt();
623 if ( ddv.at( 1 ).toInt() )
639 void QgsPalLayerSettings::readOldDataDefinedPropertyMap(
QgsVectorLayer *layer, QDomElement *parentElem )
641 if ( !layer && !parentElem )
646 QgsPropertiesDefinition::const_iterator i = sPropertyDefinitions()->constBegin();
647 for ( ; i != sPropertyDefinitions()->constEnd(); ++i )
652 readOldDataDefinedProperty( layer,
static_cast< Property >( i.key() ) );
654 else if ( parentElem )
657 QDomElement e = parentElem->firstChildElement( i.value().name() );
660 bool active = e.attribute( QStringLiteral(
"active" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
661 bool isExpression = e.attribute( QStringLiteral(
"useExpr" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
675 void QgsPalLayerSettings::readFromLayerCustomProperties(
QgsVectorLayer *layer )
677 if ( layer->
customProperty( QStringLiteral(
"labeling" ) ).toString() != QLatin1String(
"pal" ) )
702 QDomDocument doc( QStringLiteral(
"substitutions" ) );
703 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/substitutions" ) ).toString() );
704 QDomElement replacementElem = doc.firstChildElement( QStringLiteral(
"substitutions" ) );
725 mLineSettings.
setPlacementFlags(
static_cast< QgsLabeling::LinePlacementFlags
>( layer->
customProperty( QStringLiteral(
"labeling/placementFlags" ) ).toUInt() ) );
734 if ( layer->
customProperty( QStringLiteral(
"labeling/distMapUnitScale" ) ).toString().isEmpty() )
737 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMinScale" ), 0.0 ).toDouble();
739 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMaxScale" ), 0.0 ).toDouble();
750 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetInMapUnits" ), QVariant(
true ) ).toBool() )
755 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitScale" ) ).toString().isEmpty() )
758 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMinScale" ), 0.0 ).toDouble();
760 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
768 QVariant tempAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant() );
769 if ( tempAngle.isValid() )
771 double oldAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant( 0.0 ) ).toDouble();
784 switch ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceUnit" ), QVariant( 1 ) ).toUInt() )
799 if ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitScale" ) ).toString().isEmpty() )
802 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMinScale" ), 0.0 ).toDouble();
804 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMaxScale" ), 0.0 ).toDouble();
813 double scalemn = layer->
customProperty( QStringLiteral(
"labeling/scaleMin" ), QVariant( 0 ) ).toDouble();
814 double scalemx = layer->
customProperty( QStringLiteral(
"labeling/scaleMax" ), QVariant( 0 ) ).toDouble();
817 QVariant scalevis = layer->
customProperty( QStringLiteral(
"labeling/scaleVisibility" ), QVariant() );
818 if ( scalevis.isValid() )
824 else if ( scalemn > 0 || scalemx > 0 )
849 mObstacleSettings.
setFactor( layer->
customProperty( QStringLiteral(
"labeling/obstacleFactor" ), QVariant( 1.0 ) ).toDouble() );
851 zIndex = layer->
customProperty( QStringLiteral(
"labeling/zIndex" ), QVariant( 0.0 ) ).toDouble();
853 mDataDefinedProperties.
clear();
854 if ( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).isValid() )
856 QDomDocument doc( QStringLiteral(
"dd" ) );
857 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).toString() );
858 QDomElement elem = doc.firstChildElement( QStringLiteral(
"properties" ) );
859 mDataDefinedProperties.
readXml( elem, *sPropertyDefinitions() );
864 readOldDataDefinedPropertyMap( layer,
nullptr );
908 QDomElement textStyleElem = elem.firstChildElement( QStringLiteral(
"text-style" ) );
909 fieldName = textStyleElem.attribute( QStringLiteral(
"fieldName" ) );
910 isExpression = textStyleElem.attribute( QStringLiteral(
"isExpression" ) ).toInt();
912 mFormat.
readXml( elem, context );
914 previewBkgrdColor = QColor( textStyleElem.attribute( QStringLiteral(
"previewBkgrdColor" ), QStringLiteral(
"#ffffff" ) ) );
917 useSubstitutions = textStyleElem.attribute( QStringLiteral(
"useSubstitutions" ) ).toInt();
920 QDomElement textFormatElem = elem.firstChildElement( QStringLiteral(
"text-format" ) );
921 wrapChar = textFormatElem.attribute( QStringLiteral(
"wrapChar" ) );
922 autoWrapLength = textFormatElem.attribute( QStringLiteral(
"autoWrapLength" ), QStringLiteral(
"0" ) ).toInt();
923 useMaxLineLengthForAutoWrap = textFormatElem.attribute( QStringLiteral(
"useMaxLineLengthForAutoWrap" ), QStringLiteral(
"1" ) ).toInt();
925 mLineSettings.
setAddDirectionSymbol( textFormatElem.attribute( QStringLiteral(
"addDirectionSymbol" ) ).toInt() );
926 mLineSettings.
setLeftDirectionSymbol( textFormatElem.attribute( QStringLiteral(
"leftDirectionSymbol" ), QStringLiteral(
"<" ) ) );
927 mLineSettings.
setRightDirectionSymbol( textFormatElem.attribute( QStringLiteral(
"rightDirectionSymbol" ), QStringLiteral(
">" ) ) );
928 mLineSettings.
setReverseDirectionSymbol( textFormatElem.attribute( QStringLiteral(
"reverseDirectionSymbol" ) ).toInt() );
930 formatNumbers = textFormatElem.attribute( QStringLiteral(
"formatNumbers" ) ).toInt();
931 decimals = textFormatElem.attribute( QStringLiteral(
"decimals" ) ).toInt();
932 plusSign = textFormatElem.attribute( QStringLiteral(
"plussign" ) ).toInt();
935 QDomElement placementElem = elem.firstChildElement( QStringLiteral(
"placement" ) );
936 placement =
static_cast< Placement >( placementElem.attribute( QStringLiteral(
"placement" ) ).toInt() );
937 mLineSettings.
setPlacementFlags(
static_cast< QgsLabeling::LinePlacementFlags
>( placementElem.attribute( QStringLiteral(
"placementFlags" ) ).toUInt() ) );
938 mPolygonPlacementFlags =
static_cast< QgsLabeling::PolygonPlacementFlags
>( placementElem.attribute( QStringLiteral(
"polygonPlacementFlags" ), QString::number(
static_cast< int >( QgsLabeling::PolygonPlacementFlag::AllowPlacementInsideOfPolygon ) ) ).toInt() );
940 centroidWhole = placementElem.attribute( QStringLiteral(
"centroidWhole" ), QStringLiteral(
"0" ) ).toInt();
941 centroidInside = placementElem.attribute( QStringLiteral(
"centroidInside" ), QStringLiteral(
"0" ) ).toInt();
945 fitInPolygonOnly = placementElem.attribute( QStringLiteral(
"fitInPolygonOnly" ), QStringLiteral(
"0" ) ).toInt();
946 dist = placementElem.attribute( QStringLiteral(
"dist" ) ).toDouble();
947 if ( !placementElem.hasAttribute( QStringLiteral(
"distUnits" ) ) )
949 if ( placementElem.attribute( QStringLiteral(
"distInMapUnits" ) ).toInt() )
958 if ( !placementElem.hasAttribute( QStringLiteral(
"distMapUnitScale" ) ) )
961 double oldMin = placementElem.attribute( QStringLiteral(
"distMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
963 double oldMax = placementElem.attribute( QStringLiteral(
"distMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
972 xOffset = placementElem.attribute( QStringLiteral(
"xOffset" ), QStringLiteral(
"0" ) ).toDouble();
973 yOffset = placementElem.attribute( QStringLiteral(
"yOffset" ), QStringLiteral(
"0" ) ).toDouble();
974 if ( !placementElem.hasAttribute( QStringLiteral(
"offsetUnits" ) ) )
982 if ( !placementElem.hasAttribute( QStringLiteral(
"labelOffsetMapUnitScale" ) ) )
985 double oldMin = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
987 double oldMax = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
995 if ( placementElem.hasAttribute( QStringLiteral(
"angleOffset" ) ) )
997 double oldAngle = placementElem.attribute( QStringLiteral(
"angleOffset" ), QStringLiteral(
"0" ) ).toDouble();
1002 angleOffset = placementElem.attribute( QStringLiteral(
"rotationAngle" ), QStringLiteral(
"0" ) ).toDouble();
1005 preserveRotation = placementElem.attribute( QStringLiteral(
"preserveRotation" ), QStringLiteral(
"1" ) ).toInt();
1006 maxCurvedCharAngleIn = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleIn" ), QStringLiteral(
"25" ) ).toDouble();
1007 maxCurvedCharAngleOut = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleOut" ), QStringLiteral(
"-25" ) ).toDouble();
1008 priority = placementElem.attribute( QStringLiteral(
"priority" ) ).toInt();
1009 repeatDistance = placementElem.attribute( QStringLiteral(
"repeatDistance" ), QStringLiteral(
"0" ) ).toDouble();
1010 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceUnits" ) ) )
1013 switch ( placementElem.attribute( QStringLiteral(
"repeatDistanceUnit" ), QString::number( 1 ) ).toUInt() )
1033 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceMapUnitScale" ) ) )
1036 double oldMin = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1038 double oldMax = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1046 mLineSettings.
setOverrunDistance( placementElem.attribute( QStringLiteral(
"overrunDistance" ), QStringLiteral(
"0" ) ).toDouble() );
1049 mLineSettings.
setLineAnchorPercent( placementElem.attribute( QStringLiteral(
"lineAnchorPercent" ), QStringLiteral(
"0.5" ) ).toDouble() );
1052 geometryGenerator = placementElem.attribute( QStringLiteral(
"geometryGenerator" ) );
1059 QDomElement renderingElem = elem.firstChildElement( QStringLiteral(
"rendering" ) );
1061 drawLabels = renderingElem.attribute( QStringLiteral(
"drawLabels" ), QStringLiteral(
"1" ) ).toInt();
1063 maximumScale = renderingElem.attribute( QStringLiteral(
"scaleMin" ), QStringLiteral(
"0" ) ).toDouble();
1064 minimumScale = renderingElem.attribute( QStringLiteral(
"scaleMax" ), QStringLiteral(
"0" ) ).toDouble();
1065 scaleVisibility = renderingElem.attribute( QStringLiteral(
"scaleVisibility" ) ).toInt();
1067 fontLimitPixelSize = renderingElem.attribute( QStringLiteral(
"fontLimitPixelSize" ), QStringLiteral(
"0" ) ).toInt();
1068 fontMinPixelSize = renderingElem.attribute( QStringLiteral(
"fontMinPixelSize" ), QStringLiteral(
"0" ) ).toInt();
1069 fontMaxPixelSize = renderingElem.attribute( QStringLiteral(
"fontMaxPixelSize" ), QStringLiteral(
"10000" ) ).toInt();
1070 displayAll = renderingElem.attribute( QStringLiteral(
"displayAll" ), QStringLiteral(
"0" ) ).toInt();
1073 labelPerPart = renderingElem.attribute( QStringLiteral(
"labelPerPart" ) ).toInt();
1074 mLineSettings.
setMergeLines( renderingElem.attribute( QStringLiteral(
"mergeLines" ) ).toInt() );
1075 mThinningSettings.
setMinimumFeatureSize( renderingElem.attribute( QStringLiteral(
"minFeatureSize" ) ).toDouble() );
1076 mThinningSettings.
setLimitNumberLabelsEnabled( renderingElem.attribute( QStringLiteral(
"limitNumLabels" ), QStringLiteral(
"0" ) ).toInt() );
1077 mThinningSettings.
setMaximumNumberLabels( renderingElem.attribute( QStringLiteral(
"maxNumLabels" ), QStringLiteral(
"2000" ) ).toInt() );
1078 mObstacleSettings.
setIsObstacle( renderingElem.attribute( QStringLiteral(
"obstacle" ), QStringLiteral(
"1" ) ).toInt() );
1079 mObstacleSettings.
setFactor( renderingElem.attribute( QStringLiteral(
"obstacleFactor" ), QStringLiteral(
"1" ) ).toDouble() );
1081 zIndex = renderingElem.attribute( QStringLiteral(
"zIndex" ), QStringLiteral(
"0.0" ) ).toDouble();
1083 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"dd_properties" ) );
1084 if ( !ddElem.isNull() )
1086 mDataDefinedProperties.
readXml( ddElem, *sPropertyDefinitions() );
1091 mDataDefinedProperties.
clear();
1092 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"data-defined" ) );
1093 readOldDataDefinedPropertyMap(
nullptr, &ddElem );
1134 const QString calloutType = elem.attribute( QStringLiteral(
"calloutType" ) );
1135 if ( calloutType.isEmpty() )
1147 QDomElement textStyleElem = mFormat.
writeXml( doc, context );
1150 textStyleElem.setAttribute( QStringLiteral(
"fieldName" ),
fieldName );
1151 textStyleElem.setAttribute( QStringLiteral(
"isExpression" ),
isExpression );
1152 QDomElement replacementElem = doc.createElement( QStringLiteral(
"substitutions" ) );
1154 textStyleElem.appendChild( replacementElem );
1155 textStyleElem.setAttribute( QStringLiteral(
"useSubstitutions" ),
useSubstitutions );
1158 QDomElement textFormatElem = doc.createElement( QStringLiteral(
"text-format" ) );
1159 textFormatElem.setAttribute( QStringLiteral(
"wrapChar" ),
wrapChar );
1160 textFormatElem.setAttribute( QStringLiteral(
"autoWrapLength" ),
autoWrapLength );
1162 textFormatElem.setAttribute( QStringLiteral(
"multilineAlign" ),
static_cast< unsigned int >(
multilineAlign ) );
1163 textFormatElem.setAttribute( QStringLiteral(
"addDirectionSymbol" ), mLineSettings.
addDirectionSymbol() );
1164 textFormatElem.setAttribute( QStringLiteral(
"leftDirectionSymbol" ), mLineSettings.
leftDirectionSymbol() );
1165 textFormatElem.setAttribute( QStringLiteral(
"rightDirectionSymbol" ), mLineSettings.
rightDirectionSymbol() );
1166 textFormatElem.setAttribute( QStringLiteral(
"reverseDirectionSymbol" ), mLineSettings.
reverseDirectionSymbol() );
1167 textFormatElem.setAttribute( QStringLiteral(
"placeDirectionSymbol" ),
static_cast< unsigned int >( mLineSettings.
directionSymbolPlacement() ) );
1168 textFormatElem.setAttribute( QStringLiteral(
"formatNumbers" ),
formatNumbers );
1169 textFormatElem.setAttribute( QStringLiteral(
"decimals" ),
decimals );
1170 textFormatElem.setAttribute( QStringLiteral(
"plussign" ),
plusSign );
1173 QDomElement placementElem = doc.createElement( QStringLiteral(
"placement" ) );
1174 placementElem.setAttribute( QStringLiteral(
"placement" ),
placement );
1175 placementElem.setAttribute( QStringLiteral(
"polygonPlacementFlags" ),
static_cast< int >( mPolygonPlacementFlags ) );
1176 placementElem.setAttribute( QStringLiteral(
"placementFlags" ),
static_cast< unsigned int >( mLineSettings.
placementFlags() ) );
1177 placementElem.setAttribute( QStringLiteral(
"centroidWhole" ),
centroidWhole );
1178 placementElem.setAttribute( QStringLiteral(
"centroidInside" ),
centroidInside );
1180 placementElem.setAttribute( QStringLiteral(
"fitInPolygonOnly" ),
fitInPolygonOnly );
1181 placementElem.setAttribute( QStringLiteral(
"dist" ),
dist );
1184 placementElem.setAttribute( QStringLiteral(
"offsetType" ),
static_cast< unsigned int >(
offsetType ) );
1185 placementElem.setAttribute( QStringLiteral(
"quadOffset" ),
static_cast< unsigned int >(
quadOffset ) );
1186 placementElem.setAttribute( QStringLiteral(
"xOffset" ),
xOffset );
1187 placementElem.setAttribute( QStringLiteral(
"yOffset" ),
yOffset );
1190 placementElem.setAttribute( QStringLiteral(
"rotationAngle" ),
angleOffset );
1191 placementElem.setAttribute( QStringLiteral(
"preserveRotation" ),
preserveRotation );
1194 placementElem.setAttribute( QStringLiteral(
"priority" ),
priority );
1195 placementElem.setAttribute( QStringLiteral(
"repeatDistance" ),
repeatDistance );
1198 placementElem.setAttribute( QStringLiteral(
"overrunDistance" ), mLineSettings.
overrunDistance() );
1201 placementElem.setAttribute( QStringLiteral(
"lineAnchorPercent" ), mLineSettings.
lineAnchorPercent() );
1202 placementElem.setAttribute( QStringLiteral(
"lineAnchorType" ),
static_cast< int >( mLineSettings.
anchorType() ) );
1204 placementElem.setAttribute( QStringLiteral(
"geometryGenerator" ),
geometryGenerator );
1206 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWkbTypes::GeometryType>() );
1207 placementElem.setAttribute( QStringLiteral(
"geometryGeneratorType" ), metaEnum.valueToKey(
geometryGeneratorType ) );
1209 placementElem.setAttribute( QStringLiteral(
"layerType" ), metaEnum.valueToKey(
layerType ) );
1212 QDomElement renderingElem = doc.createElement( QStringLiteral(
"rendering" ) );
1213 renderingElem.setAttribute( QStringLiteral(
"drawLabels" ),
drawLabels );
1214 renderingElem.setAttribute( QStringLiteral(
"scaleVisibility" ),
scaleVisibility );
1215 renderingElem.setAttribute( QStringLiteral(
"scaleMin" ),
maximumScale );
1216 renderingElem.setAttribute( QStringLiteral(
"scaleMax" ),
minimumScale );
1217 renderingElem.setAttribute( QStringLiteral(
"fontLimitPixelSize" ),
fontLimitPixelSize );
1218 renderingElem.setAttribute( QStringLiteral(
"fontMinPixelSize" ),
fontMinPixelSize );
1219 renderingElem.setAttribute( QStringLiteral(
"fontMaxPixelSize" ),
fontMaxPixelSize );
1220 renderingElem.setAttribute( QStringLiteral(
"displayAll" ),
displayAll );
1221 renderingElem.setAttribute( QStringLiteral(
"upsidedownLabels" ),
static_cast< unsigned int >(
upsidedownLabels ) );
1223 renderingElem.setAttribute( QStringLiteral(
"labelPerPart" ),
labelPerPart );
1224 renderingElem.setAttribute( QStringLiteral(
"mergeLines" ), mLineSettings.
mergeLines() );
1225 renderingElem.setAttribute( QStringLiteral(
"minFeatureSize" ), mThinningSettings.
minimumFeatureSize() );
1227 renderingElem.setAttribute( QStringLiteral(
"maxNumLabels" ), mThinningSettings.
maximumNumberLabels() );
1228 renderingElem.setAttribute( QStringLiteral(
"obstacle" ), mObstacleSettings.
isObstacle() );
1229 renderingElem.setAttribute( QStringLiteral(
"obstacleFactor" ), mObstacleSettings.
factor() );
1230 renderingElem.setAttribute( QStringLiteral(
"obstacleType" ),
static_cast< unsigned int >( mObstacleSettings.
type() ) );
1231 renderingElem.setAttribute( QStringLiteral(
"zIndex" ),
zIndex );
1233 QDomElement ddElem = doc.createElement( QStringLiteral(
"dd_properties" ) );
1234 mDataDefinedProperties.
writeXml( ddElem, *sPropertyDefinitions() );
1236 QDomElement elem = doc.createElement( QStringLiteral(
"settings" ) );
1237 elem.appendChild( textStyleElem );
1238 elem.appendChild( textFormatElem );
1239 elem.appendChild( placementElem );
1240 elem.appendChild( renderingElem );
1241 elem.appendChild( ddElem );
1245 elem.setAttribute( QStringLiteral(
"calloutType" ), mCallout->type() );
1246 mCallout->saveProperties( doc, elem, context );
1261 QPixmap pixmap( size );
1262 pixmap.fill( Qt::transparent );
1264 painter.begin( &pixmap );
1266 painter.setRenderHint( QPainter::Antialiasing );
1268 QRect rect( 0, 0, size.width(), size.height() );
1271 painter.setPen( Qt::NoPen );
1273 if ( ( background1.lightnessF() < 0.7 ) )
1275 background1 = background1.darker( 125 );
1279 background1 = background1.lighter( 125 );
1282 QLinearGradient linearGrad( QPointF( 0, 0 ), QPointF( 0, rect.height() ) );
1283 linearGrad.setColorAt( 0, background1 );
1284 linearGrad.setColorAt( 1, background2 );
1285 painter.setBrush( QBrush( linearGrad ) );
1286 if ( size.width() > 30 )
1288 painter.drawRoundedRect( rect, 6, 6 );
1293 painter.drawRect( rect );
1295 painter.setBrush( Qt::NoBrush );
1296 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 );
1335 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
1348 QRectF labelRect( textRect.left() + ( textRect.width() - textWidth ) / 2.0, textRect.top(), textWidth, textRect.height() );
1355 if ( size.width() > 30 )
1360 rect.width() - iconWidth * 3, rect.height() - iconWidth * 3,
1361 iconWidth * 2, iconWidth * 2 ), Qt::AlignRight | Qt::AlignBottom );
1365 painter.setBrush( Qt::NoBrush );
1367 if ( size.width() > 30 )
1369 painter.drawRoundedRect( rect, 6, 6 );
1374 painter.drawRect( rect );
1383 return QgsPalLabeling::checkMinimumSizeMM(
ct, geom, minSize );
1393 QString textCopy( text );
1396 std::unique_ptr< QgsRenderContext > scopedRc;
1401 scopedRc->expressionContext().setFeature( *f );
1517 if ( wrapchr.isEmpty() )
1519 wrapchr = QStringLiteral(
"\n" );
1524 && ( !leftDirSymb.isEmpty() || !rightDirSymb.isEmpty() ) )
1526 QString dirSym = leftDirSymb;
1528 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
1529 if ( fm->width( rightDirSymb ) > fm->width( dirSym ) )
1531 if ( fm->horizontalAdvance( rightDirSymb ) > fm->horizontalAdvance( dirSym ) )
1533 dirSym = rightDirSymb;
1535 switch ( placeDirSymb )
1538 textCopy.append( dirSym );
1543 textCopy.prepend( dirSym + QStringLiteral(
"\n" ) );
1548 double w = 0.0, h = 0.0, rw = 0.0, rh = 0.0;
1549 double labelHeight = fm->ascent() + fm->descent();
1551 QStringList multiLineSplit;
1563 int lines = multiLineSplit.size();
1565 switch ( orientation )
1569 h += fm->height() +
static_cast< double >( ( lines - 1 ) * labelHeight * multilineH );
1571 for (
const auto &line : multiLineSplit )
1573 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
1574 w = std::max( w, fm->width( line ) );
1576 w = std::max( w, fm->horizontalAdvance( line ) );
1584 double letterSpacing = mFormat.
scaledFont( *context ).letterSpacing();
1585 double labelWidth = fm->maxWidth();
1586 w = labelWidth + ( lines - 1 ) * labelWidth * multilineH;
1588 int maxLineLength = 0;
1589 for (
const auto &line : multiLineSplit )
1591 maxLineLength = std::max( maxLineLength, line.length() );
1593 h = fm->ascent() * maxLineLength + ( maxLineLength - 1 ) * letterSpacing;
1599 double widthHorizontal = 0.0;
1600 for (
const auto &line : multiLineSplit )
1602 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
1603 widthHorizontal = std::max( w, fm->width( line ) );
1605 widthHorizontal = std::max( w, fm->horizontalAdvance( line ) );
1609 double widthVertical = 0.0;
1610 double letterSpacing = mFormat.
scaledFont( *context ).letterSpacing();
1611 double labelWidth = fm->maxWidth();
1612 widthVertical = labelWidth + ( lines - 1 ) * labelWidth * multilineH;
1614 double heightHorizontal = 0.0;
1615 heightHorizontal += fm->height() +
static_cast< double >( ( lines - 1 ) * labelHeight * multilineH );
1617 double heightVertical = 0.0;
1618 int maxLineLength = 0;
1619 for (
const auto &line : multiLineSplit )
1621 maxLineLength = std::max( maxLineLength, line.length() );
1623 heightVertical = fm->ascent() * maxLineLength + ( maxLineLength - 1 ) * letterSpacing;
1625 w = widthHorizontal;
1626 rw = heightVertical;
1627 h = heightHorizontal;
1635 labelX = std::fabs( ptSize.
x() -
ptZero.
x() );
1636 labelY = std::fabs( ptSize.
y() -
ptZero.
y() );
1641 if ( rotatedLabelX && rotatedLabelY )
1643 *rotatedLabelX = rw * uPP;
1644 *rotatedLabelY = rh * uPP;
1652 Q_ASSERT( labelFeature );
1658 bool isObstacle = mObstacleSettings.
isObstacle();
1666 registerObstacleFeature( f, context, labelFeature, obstacleGeometry );
1678 if ( obstacleGeometry.
isNull() )
1691 dataDefinedValues.clear();
1708 if ( useScaleVisibility )
1721 maxScale = 1 / std::fabs( maxScale );
1740 minScale = 1 / std::fabs( minScale );
1749 QFont labelFont = mFormat.
font();
1755 if ( exprVal.isValid() )
1757 QString units = exprVal.toString();
1758 if ( !units.isEmpty() )
1768 double fontSize = mFormat.
size();
1774 if ( fontSize <= 0.0 )
1781 if ( fontPixelSize < 1 )
1785 labelFont.setPixelSize( fontPixelSize );
1797 if ( fontMinPixel > labelFont.pixelSize() || labelFont.pixelSize() > fontMaxPixel )
1809 labelFont.setCapitalization( QFont::MixedCase );
1811 parseTextStyle( labelFont, fontunits, context );
1814 parseTextFormatting( context );
1815 parseTextBuffer( context );
1816 parseTextMask( context );
1817 parseShapeBackground( context );
1818 parseDropShadow( context );
1839 labelText = result.isNull() ? QString() : result.toString();
1844 labelText = v.isNull() ? QString() : v.toString();
1864 if ( exprVal.isValid() )
1866 QString fcase = exprVal.toString().trimmed();
1867 QgsDebugMsgLevel( QStringLiteral(
"exprVal FontCase:%1" ).arg( fcase ), 4 );
1869 if ( !fcase.isEmpty() )
1871 if ( fcase.compare( QLatin1String(
"NoChange" ), Qt::CaseInsensitive ) == 0 )
1875 else if ( fcase.compare( QLatin1String(
"Upper" ), Qt::CaseInsensitive ) == 0 )
1879 else if ( fcase.compare( QLatin1String(
"Lower" ), Qt::CaseInsensitive ) == 0 )
1883 else if ( fcase.compare( QLatin1String(
"Capitalize" ), Qt::CaseInsensitive ) == 0 )
1887 else if ( fcase.compare( QLatin1String(
"Title" ), Qt::CaseInsensitive ) == 0 )
1902 if ( evalFormatNumbers )
1906 if ( decimalPlaces <= 0 )
1912 QVariant textV( labelText );
1914 double d = textV.toDouble( &ok );
1917 QString numberFormat;
1918 if ( d > 0 && signPlus )
1920 numberFormat.append(
'+' );
1922 numberFormat.append(
"%1" );
1923 labelText = numberFormat.arg( d, 0,
'f', decimalPlaces );
1928 std::unique_ptr<QFontMetricsF> labelFontMetrics(
new QFontMetricsF( labelFont ) );
1929 double labelX, labelY, rotatedLabelX, rotatedLabelY;
1932 if (
format().allowHtmlFormatting() )
1936 calculateLabelSize( labelFontMetrics.get(), labelText, labelX, labelY,
mCurFeat, &context, &rotatedLabelX, &rotatedLabelY,
format().allowHtmlFormatting() ? &doc :
nullptr );
1940 double maxcharanglein = 20.0;
1941 double maxcharangleout = -20.0;
1956 maxcharanglein = qBound( 20.0,
static_cast< double >( maxcharanglePt.x() ), 60.0 );
1957 maxcharangleout = qBound( 20.0,
static_cast< double >( maxcharanglePt.y() ), 95.0 );
1961 maxcharangleout = -( std::fabs( maxcharangleout ) );
1969 if ( exprVal.isValid() )
1971 QString str = exprVal.toString().trimmed();
1972 QgsDebugMsgLevel( QStringLiteral(
"exprVal CentroidWhole:%1" ).arg( str ), 4 );
1974 if ( !str.isEmpty() )
1976 if ( str.compare( QLatin1String(
"Visible" ), Qt::CaseInsensitive ) == 0 )
1978 wholeCentroid =
false;
1980 else if ( str.compare( QLatin1String(
"Whole" ), Qt::CaseInsensitive ) == 0 )
1982 wholeCentroid =
true;
1996 std::unique_ptr<QgsGeometry> scopedClonedGeom;
2002 geom = simplifier.
simplify( geom );
2019 bool doClip =
false;
2020 if ( !centroidPoly || !wholeCentroid )
2026 QgsLabeling::PolygonPlacementFlags polygonPlacement = mPolygonPlacementFlags;
2030 if ( dataDefinedOutside.isValid() )
2032 if ( dataDefinedOutside.type() == QVariant::String )
2034 const QString value = dataDefinedOutside.toString().trimmed();
2035 if ( value.compare( QLatin1String(
"force" ), Qt::CaseInsensitive ) == 0 )
2038 polygonPlacement &= ~static_cast< int >( QgsLabeling::PolygonPlacementFlag::AllowPlacementInsideOfPolygon );
2039 polygonPlacement |= QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon;
2041 else if ( value.compare( QLatin1String(
"yes" ), Qt::CaseInsensitive ) == 0 )
2044 polygonPlacement |= QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon;
2046 else if ( value.compare( QLatin1String(
"no" ), Qt::CaseInsensitive ) == 0 )
2049 polygonPlacement &= ~static_cast< int >( QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon );
2054 if ( dataDefinedOutside.toBool() )
2057 polygonPlacement |= QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon;
2062 polygonPlacement &= ~static_cast< int >( QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon );
2077 permissibleZone = geom;
2116 if ( !geos_geom_clone )
2145 bool dataDefinedPosition =
false;
2146 bool layerDefinedRotation =
false;
2147 bool dataDefinedRotation =
false;
2148 double xPos = 0.0, yPos = 0.0,
angle = 0.0;
2149 bool ddXPos =
false, ddYPos =
false;
2150 double quadOffsetX = 0.0, quadOffsetY = 0.0;
2151 double offsetX = 0.0, offsetY = 0.0;
2163 bool ddFixedQuad =
false;
2169 if ( exprVal.isValid() )
2172 int quadInt = exprVal.toInt( &ok );
2173 if ( ok && 0 <= quadInt && quadInt <= 8 )
2241 if ( exprVal.isValid() )
2243 QString units = exprVal.toString().trimmed();
2244 if ( !units.isEmpty() )
2250 offUnit = decodedUnits;
2266 layerDefinedRotation =
true;
2276 if ( exprVal.isValid() )
2279 double rotD = exprVal.toDouble( &ok );
2282 dataDefinedRotation =
true;
2286 angle = ( 360 - rotD ) * M_PI / 180.0;
2294 if ( exprVal.isValid() )
2296 if ( !exprVal.isNull() )
2297 xPos = exprVal.toDouble( &ddXPos );
2302 if ( exprVal.isValid() )
2305 if ( !exprVal.isNull() )
2306 yPos = exprVal.toDouble( &ddYPos );
2308 if ( ddXPos && ddYPos )
2310 dataDefinedPosition =
true;
2312 if ( layerDefinedRotation && !dataDefinedRotation )
2321 if ( exprVal.isValid() )
2323 QString haliString = exprVal.toString();
2324 if ( haliString.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
2326 xdiff -= labelX / 2.0;
2328 else if ( haliString.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
2339 if ( exprVal.isValid() )
2341 QString valiString = exprVal.toString();
2342 if ( valiString.compare( QLatin1String(
"Bottom" ), Qt::CaseInsensitive ) != 0 )
2344 if ( valiString.compare( QLatin1String(
"Top" ), Qt::CaseInsensitive ) == 0 )
2350 double descentRatio = labelFontMetrics->descent() / labelFontMetrics->height();
2351 if ( valiString.compare( QLatin1String(
"Base" ), Qt::CaseInsensitive ) == 0 )
2353 ydiff -= labelY * descentRatio;
2357 double capHeightRatio = ( labelFontMetrics->boundingRect(
'H' ).height() + 1 + labelFontMetrics->descent() ) / labelFontMetrics->height();
2358 ydiff -= labelY * capHeightRatio;
2359 if ( valiString.compare( QLatin1String(
"Half" ), Qt::CaseInsensitive ) == 0 )
2361 ydiff += labelY * ( capHeightRatio - descentRatio ) / 2.0;
2369 if ( dataDefinedRotation )
2372 double xd = xdiff * std::cos(
angle ) - ydiff * std::sin(
angle );
2373 double yd = xdiff * std::sin(
angle ) + ydiff * std::cos(
angle );
2408 bool alwaysShow =
false;
2428 if ( exprVal.isValid() )
2430 QString units = exprVal.toString().trimmed();
2431 if ( !units.isEmpty() )
2437 repeatUnits = decodedUnits;
2464 if ( !dataDefinedPosition )
2485 ( *labelFeature )->setFixedPosition(
QgsPointXY( xPos, yPos ) );
2487 ( *labelFeature )->setHasFixedAngle( dataDefinedRotation || ( !dataDefinedPosition && !
qgsDoubleNear(
angle, 0.0 ) ) );
2488 ( *labelFeature )->setFixedAngle(
angle );
2489 ( *labelFeature )->setQuadOffset( QPointF( quadOffsetX, quadOffsetY ) );
2490 ( *labelFeature )->setPositionOffset(
QgsPointXY( offsetX, offsetY ) );
2491 ( *labelFeature )->setOffsetType(
offsetType );
2492 ( *labelFeature )->setAlwaysShow( alwaysShow );
2493 ( *labelFeature )->setRepeatDistance( repeatDist );
2494 ( *labelFeature )->setLabelText( labelText );
2495 ( *labelFeature )->setPermissibleZone( permissibleZone );
2496 ( *labelFeature )->setOverrunDistance( overrunDistanceEval );
2497 ( *labelFeature )->setOverrunSmoothDistance( overrunSmoothDist );
2500 ( *labelFeature )->setLabelAllParts( labelAll );
2504 ( *labelFeature )->setSymbolSize( QSizeF( obstacleGeometry.
boundingBox().
width(),
2510 double topMargin = std::max( 0.25 * labelFontMetrics->ascent(), 0.0 );
2511 double bottomMargin = 1.0 + labelFontMetrics->descent();
2512 QgsMargins vm( 0.0, topMargin, 0.0, bottomMargin );
2514 ( *labelFeature )->setVisualMargin( vm );
2517 QgsDebugMsgLevel( QStringLiteral(
"PAL font stored definedFont: %1, Style: %2" ).arg( labelFont.toString(), labelFont.styleName() ), 4 );
2523 labelFontMetrics.get(),
xform, maxcharanglein, maxcharangleout,
format().allowHtmlFormatting() ? &doc :
nullptr );
2529 double distance =
dist;
2541 if ( exprVal.isValid() )
2543 QString units = exprVal.toString().trimmed();
2544 QgsDebugMsgLevel( QStringLiteral(
"exprVal DistanceUnits:%1" ).arg( units ), 4 );
2545 if ( !units.isEmpty() )
2551 distUnit = decodedUnits;
2564 distance = ( distance < 0 ? -1 : 1 ) * std::max( std::fabs( distance ), 1.0 );
2572 distance = std::max( distance, 2.0 );
2578 ( *labelFeature )->setDistLabel( d );
2583 ( *labelFeature )->setHasFixedQuadrant(
true );
2588 ( *labelFeature )->setPolygonPlacementFlags( polygonPlacement );
2597 ( *labelFeature )->setZIndex( z );
2604 if ( exprVal.isValid() )
2607 double priorityD = exprVal.toDouble( &ok );
2610 priorityD = qBound( 0.0, priorityD, 10.0 );
2611 priorityD = 1 - priorityD / 10.0;
2612 ( *labelFeature )->setPriority( priorityD );
2624 if ( positionOrder.isEmpty() )
2625 positionOrder = *DEFAULT_PLACEMENT_ORDER();
2631 if ( !dataDefinedOrder.isEmpty() )
2636 ( *labelFeature )->setPredefinedPositionOrder( positionOrder );
2647 if ( !obstacleGeometry.
isNull() )
2649 geom = obstacleGeometry;
2664 if ( ls->numPoints() < 2 )
2670 std::unique_ptr<QgsGeometry> scopedClonedGeom;
2676 geom = simplifier.
simplify( geom );
2680 std::unique_ptr<QgsGeometry> scopedPreparedGeom;
2688 if ( !geos_geom_clone )
2692 *obstacleFeature =
new QgsLabelFeature( f.
id(), std::move( geos_geom_clone ), QSizeF( 0, 0 ) );
2693 ( *obstacleFeature )->setFeature( f );
2698 ( *obstacleFeature )->setObstacleSettings( os );
2703 bool QgsPalLayerSettings::dataDefinedValEval( DataDefinedValueType valType,
2707 if ( !mDataDefinedProperties.
isActive( p ) )
2711 exprVal = mDataDefinedProperties.
value( p, context );
2712 if ( exprVal.isValid() )
2718 bool bol = exprVal.toBool();
2719 dataDefinedValues.insert( p, QVariant( bol ) );
2725 int size = exprVal.toInt( &ok );
2729 dataDefinedValues.insert( p, QVariant( size ) );
2737 int size = exprVal.toInt( &ok );
2739 if ( ok && size > 0 )
2741 dataDefinedValues.insert( p, QVariant( size ) );
2749 double size = exprVal.toDouble( &ok );
2753 dataDefinedValues.insert( p, QVariant( size ) );
2761 double size = exprVal.toDouble( &ok );
2763 if ( ok && size > 0.0 )
2765 dataDefinedValues.insert( p, QVariant( size ) );
2773 double rot = exprVal.toDouble( &ok );
2776 if ( rot < -180.0 && rot >= -360 )
2780 if ( rot > 180.0 && rot <= 360 )
2784 if ( rot >= -180 && rot <= 180 )
2786 dataDefinedValues.insert( p, QVariant( rot ) );
2795 int size = exprVal.toInt( &ok );
2796 if ( ok && size >= 0 && size <= 100 )
2798 dataDefinedValues.insert( p, QVariant( size ) );
2805 QString str = exprVal.toString();
2807 dataDefinedValues.insert( p, QVariant( str ) );
2812 QString unitstr = exprVal.toString().trimmed();
2814 if ( !unitstr.isEmpty() )
2823 QString colorstr = exprVal.toString().trimmed();
2826 if ( color.isValid() )
2828 dataDefinedValues.insert( p, QVariant( color ) );
2835 QString joinstr = exprVal.toString().trimmed();
2837 if ( !joinstr.isEmpty() )
2846 QString blendstr = exprVal.toString().trimmed();
2848 if ( !blendstr.isEmpty() )
2861 dataDefinedValues.insert( p, res );
2872 dataDefinedValues.insert( p, res );
2882 void QgsPalLayerSettings::parseTextStyle( QFont &labelFont,
2895 QString ddFontFamily;
2900 if ( exprVal.isValid() )
2902 QString family = exprVal.toString().trimmed();
2903 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font family:%1" ).arg( family ), 4 );
2905 if ( labelFont.family() != family )
2911 ddFontFamily = family;
2918 QString ddFontStyle;
2922 if ( exprVal.isValid() )
2924 QString fontstyle = exprVal.toString().trimmed();
2925 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font style:%1" ).arg( fontstyle ), 4 );
2926 ddFontStyle = fontstyle;
2931 bool ddBold =
false;
2939 bool ddItalic =
false;
2949 QFont appFont = QApplication::font();
2950 bool newFontBuilt =
false;
2951 if ( ddBold || ddItalic )
2954 newFont = QFont( !ddFontFamily.isEmpty() ? ddFontFamily : labelFont.family() );
2955 newFontBuilt =
true;
2956 newFont.setBold( ddBold );
2957 newFont.setItalic( ddItalic );
2959 else if ( !ddFontStyle.isEmpty()
2960 && ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2962 if ( !ddFontFamily.isEmpty() )
2965 QFont styledfont = mFontDB.font( ddFontFamily, ddFontStyle, appFont.pointSize() );
2966 if ( appFont != styledfont )
2968 newFont = styledfont;
2969 newFontBuilt =
true;
2976 else if ( !ddFontFamily.isEmpty() )
2978 if ( ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2981 QFont styledfont = mFontDB.font( ddFontFamily, mFormat.
namedStyle(), appFont.pointSize() );
2982 if ( appFont != styledfont )
2984 newFont = styledfont;
2985 newFontBuilt =
true;
2990 newFont = QFont( ddFontFamily );
2991 newFontBuilt =
true;
2999 newFont.setPixelSize( labelFont.pixelSize() );
3000 newFont.setUnderline( labelFont.underline() );
3001 newFont.setStrikeOut( labelFont.strikeOut() );
3002 newFont.setWordSpacing( labelFont.wordSpacing() );
3003 newFont.setLetterSpacing( QFont::AbsoluteSpacing, labelFont.letterSpacing() );
3005 labelFont = newFont;
3009 double wordspace = labelFont.wordSpacing();
3018 double letterspace = labelFont.letterSpacing();
3031 labelFont.setStrikeOut( strikeout );
3039 labelFont.setUnderline( underline );
3065 drawBuffer = exprVal.toBool();
3079 double bufrSize = buffer.
size();
3082 bufrSize = exprVal.toDouble();
3086 double bufferOpacity = buffer.
opacity() * 100;
3089 bufferOpacity = exprVal.toDouble();
3092 drawBuffer = ( drawBuffer && bufrSize > 0.0 && bufferOpacity > 0 );
3122 bool maskEnabled = mask.
enabled();
3125 maskEnabled = exprVal.toBool();
3134 double bufrSize = mask.
size();
3137 bufrSize = exprVal.toDouble();
3141 double opacity = mask.
opacity() * 100;
3144 opacity = exprVal.toDouble();
3147 maskEnabled = ( maskEnabled && bufrSize > 0.0 && opacity > 0 );
3172 wrapchr = exprVal.toString();
3178 evalAutoWrapLength = exprVal.toInt();
3189 if ( exprVal.isValid() )
3191 QString str = exprVal.toString().trimmed();
3192 QgsDebugMsgLevel( QStringLiteral(
"exprVal MultiLineAlignment:%1" ).arg( str ), 4 );
3194 if ( !str.isEmpty() )
3199 if ( str.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
3203 else if ( str.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
3207 else if ( str.compare( QLatin1String(
"Follow" ), Qt::CaseInsensitive ) == 0 )
3211 else if ( str.compare( QLatin1String(
"Justify" ), Qt::CaseInsensitive ) == 0 )
3226 if ( exprVal.isValid() )
3228 QString str = exprVal.toString().trimmed();
3229 if ( !str.isEmpty() )
3238 drawDirSymb = exprVal.toBool();
3251 if ( exprVal.isValid() )
3253 QString str = exprVal.toString().trimmed();
3254 QgsDebugMsgLevel( QStringLiteral(
"exprVal DirSymbPlacement:%1" ).arg( str ), 4 );
3256 if ( !str.isEmpty() )
3261 if ( str.compare( QLatin1String(
"Above" ), Qt::CaseInsensitive ) == 0 )
3265 else if ( str.compare( QLatin1String(
"Below" ), Qt::CaseInsensitive ) == 0 )
3280 void QgsPalLayerSettings::parseShapeBackground(
QgsRenderContext &context )
3287 bool drawShape = background.
enabled();
3290 drawShape = exprVal.toBool();
3299 double shapeOpacity = background.
opacity() * 100;
3302 shapeOpacity = 100.0 * exprVal.toDouble();
3305 drawShape = ( drawShape && shapeOpacity > 0 );
3319 if ( exprVal.isValid() )
3321 QString skind = exprVal.toString().trimmed();
3322 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeKind:%1" ).arg( skind ), 4 );
3324 if ( !skind.isEmpty() )
3333 QString svgPath = background.
svgFile();
3338 if ( exprVal.isValid() )
3340 QString svgfile = exprVal.toString().trimmed();
3341 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSVGFile:%1" ).arg( svgfile ), 4 );
3354 if ( exprVal.isValid() )
3356 QString stype = exprVal.toString().trimmed();
3357 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSizeType:%1" ).arg( stype ), 4 );
3359 if ( !stype.isEmpty() )
3368 double ddShpSizeX = background.
size().width();
3371 ddShpSizeX = exprVal.toDouble();
3375 double ddShpSizeY = background.
size().height();
3378 ddShpSizeY = exprVal.toDouble();
3384 && ( svgPath.isEmpty()
3385 || ( !svgPath.isEmpty()
3387 && ddShpSizeX == 0.0 ) ) )
3395 && ddShpSizeX == 0.0 ) ) )
3402 && ( ddShpSizeX == 0.0 || ddShpSizeY == 0.0 ) )
3425 if ( exprVal.isValid() )
3427 QString rotstr = exprVal.toString().trimmed();
3428 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeRotationType:%1" ).arg( rotstr ), 4 );
3430 if ( !rotstr.isEmpty() )
3481 bool drawShadow = shadow.
enabled();
3484 drawShadow = exprVal.toBool();
3493 double shadowOpacity = shadow.
opacity() * 100;
3496 shadowOpacity = exprVal.toDouble();
3503 shadowOffDist = exprVal.toDouble();
3510 shadowRad = exprVal.toDouble();
3513 drawShadow = ( drawShadow && shadowOpacity > 0 && !( shadowOffDist == 0.0 && shadowRad == 0.0 ) );
3528 if ( exprVal.isValid() )
3530 QString str = exprVal.toString().trimmed();
3531 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShadowUnder:%1" ).arg( str ), 4 );
3533 if ( !str.isEmpty() )
3568 switch ( layer->
type() )
3572 const QgsVectorLayer *vl = qobject_cast< const QgsVectorLayer * >( layer );
3583 return !labeling->styles().empty();
3631 QStringList
QgsPalLabeling::splitToLines(
const QString &text,
const QString &wrapCharacter,
const int autoWrapLength,
const bool useMaxLineLengthWhenAutoWrapping )
3633 QStringList multiLineSplit;
3634 if ( !wrapCharacter.isEmpty() && wrapCharacter != QLatin1String(
"\n" ) )
3637 const QStringList lines = text.split( wrapCharacter );
3638 for (
const QString &line : lines )
3640 multiLineSplit.append( line.split(
'\n' ) );
3645 multiLineSplit = text.split(
'\n' );
3649 if ( autoWrapLength != 0 )
3651 QStringList autoWrappedLines;
3652 autoWrappedLines.reserve( multiLineSplit.count() );
3653 for (
const QString &line : qgis::as_const( multiLineSplit ) )
3655 autoWrappedLines.append(
QgsStringUtils::wordWrap( line, autoWrapLength, useMaxLineLengthWhenAutoWrapping ).split(
'\n' ) );
3657 multiLineSplit = autoWrappedLines;
3659 return multiLineSplit;
3664 QStringList graphemes;
3665 QTextBoundaryFinder boundaryFinder( QTextBoundaryFinder::Grapheme, text );
3666 int currentBoundary = -1;
3667 int previousBoundary = 0;
3668 while ( ( currentBoundary = boundaryFinder.toNextBoundary() ) > 0 )
3670 graphemes << text.mid( previousBoundary, currentBoundary - previousBoundary );
3671 previousBoundary = currentBoundary;
3701 QgsDebugMsgLevel( QStringLiteral(
"Ignoring feature due to transformation exception" ), 4 );
3707 return std::isfinite( point.
x() ) && std::isfinite( point.
y() );
3710 cp->removeInvalidRings();
3720 QgsDebugMsg( QStringLiteral(
"Error rotating geometry" ).arg( geom.
asWkt() ) );
3734 QVector< QgsGeometry> parts;
3735 parts.reserve( qgsgeometry_cast< const QgsGeometryCollection * >( geom.
constGet() )->numGeometries() );
3741 partGeom = partGeom.
buffer( 0, 0 );
3743 parts.append( partGeom );
3750 if ( bufferGeom.
isNull() )
3752 QgsDebugMsg( QStringLiteral(
"Could not repair geometry: %1" ).arg( bufferGeom.
lastError() ) );
3759 if ( !clipGeometry.
isNull() &&
3795 double length = geom.
length();
3796 if ( length >= 0.0 )
3798 return ( length >= ( minSize * mapUnitsPerMM ) );
3803 double area = geom.
area();
3806 return ( std::sqrt( area ) >= ( minSize * mapUnitsPerMM ) );
3814 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3817 bool changed =
false;
3823 format.
setColor( ddColor.value<QColor>() );
3848 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3910 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3913 bool changed =
false;
3961 buffer.
setColor( ddColor.value<QColor>() );
3988 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3990 if ( ddValues.isEmpty() )
3994 bool changed =
false;
4054 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4057 bool changed =
false;
4097 QSizeF size = background.
size();
4104 QSizeF size = background.
size();
4205 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
4208 bool changed =
false;
4267 shadow.
setColor( ddColor.value<QColor>() );
4308 double cx = lp->
getX() + w / 2.0;
4309 double cy = lp->
getY() + h / 2.0;
4312 double sw = w * scale;
4313 double sh = h * scale;
4314 QRectF rect( -sw / 2, -sh / 2, sw, sh );
4316 painter->translate( xform->
transform( QPointF( cx, cy ) ).toQPointF() );
4320 if ( lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT &&
4321 lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT_OVER &&
4324 painter->rotate( rotation );
4327 painter->translate( rect.bottomLeft() );
4328 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
4329 painter->translate( -rect.bottomLeft() );
4332 QRectF rect( 0, 0, outPt2.
x() - outPt.
x(), outPt2.
y() - outPt.
y() );
4333 painter->translate( QPointF( outPt.
x(), outPt.
y() ) );
4334 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
4339 painter->setPen( QColor( 255, 0, 0, 64 ) );
4343 painter->setPen( QColor( 0, 0, 0, 64 ) );
4345 painter->drawRect( rect );
4349 rect.moveTo( outPt.
x(), outPt.
y() );
4367 QList<QgsLabelPosition> positions;
4369 QList<QgsLabelPosition *> positionPointers;
4370 if ( mLabelSearchTree )
4372 mLabelSearchTree->label( p, positionPointers );
4373 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
4374 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
4385 QList<QgsLabelPosition> positions;
4387 QList<QgsLabelPosition *> positionPointers;
4388 if ( mLabelSearchTree )
4390 mLabelSearchTree->labelsInRect( r, positionPointers );
4391 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
4392 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
4403 mLabelSearchTree->setMapSettings( settings );
static const double UI_SCALE_FACTOR
UI scaling factor.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
int valueAsInt(int key, const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an integer.
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a string.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
Extends QApplication to provide access to QGIS specific resources such as theme paths,...
static QgsCalloutRegistry * calloutRegistry()
Returns the application's callout registry, used for managing callout types.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Abstract base class for callout renderers.
void render(QgsRenderContext &context, QRectF rect, const double angle, const QgsGeometry &anchor, QgsCalloutContext &calloutContext)
Renders the callout onto the specified render context.
virtual void stopRender(QgsRenderContext &context)
Finalises the callout after a set of rendering operations on the specified render context.
virtual void startRender(QgsRenderContext &context)
Prepares the callout for rendering on the specified render context.
bool enabled() const
Returns true if the the callout is enabled.
This class represents a coordinate reference system (CRS).
Custom exception class for Coordinate Reference System related exceptions.
Curve polygon geometry type.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
QString evalErrorString() const
Returns evaluation error.
QString parserErrorString() const
Returns parser error.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
QVariant evaluate()
Evaluate the feature and return the result.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Container of fields for a vector layer.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
static bool fontFamilyOnSystem(const QString &family)
Check whether font family is on system in a quick manner, which does not compare [foundry].
static bool updateFontViaStyle(QFont &f, const QString &fontstyle, bool fallback=false)
Updates font with named style and retain all font properties.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
double length() const
Returns the planar, 2-dimensional length of geometry.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
OperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
bool isMultipart() const SIP_HOLDGIL
Returns true if WKB of the geometry is of WKBMulti* type.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
bool contains(const QgsPointXY *p) const
Returns true if the geometry contains the point p.
bool isGeosValid(QgsGeometry::ValidityFlags flags=QgsGeometry::ValidityFlags()) const
Checks validity of the geometry using GEOS.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
void filterVertices(const std::function< bool(const QgsPoint &) > &filter)
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
static QgsGeometry fromPointXY(const QgsPointXY &point) SIP_HOLDGIL
Creates a new geometry from a QgsPointXY object.
QgsWkbTypes::GeometryType type
double area() const
Returns the planar, 2-dimensional area of the geometry.
QgsGeometry centroid() const
Returns the center of mass of a geometry.
QString lastError() const SIP_HOLDGIL
Returns an error string referring to the last error encountered either when this geometry was created...
QgsGeometry mergeLines() const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
QgsGeometry buffer(double distance, int segments) const
Returns a buffer region around this geometry having the given width and with a specified number of se...
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
QgsGeometry simplify(double tolerance) const
Returns a simplified version of this geometry using a specified tolerance value.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
bool convertGeometryCollectionToSubclass(QgsWkbTypes::GeometryType geomType)
Converts geometry collection to a the desired geometry type subclass (multi-point,...
QString asWkt(int precision=17) const
Exports the geometry to WKT.
static geos::unique_ptr asGeos(const QgsGeometry &geometry, double precision=0)
Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destr...
Represents a label candidate.
The QgsLabelFeature class describes a feature that should be used within the labeling engine.
void setFeature(const QgsFeature &feature)
Sets the original feature associated with this label.
void setSymbol(const QgsSymbol *symbol)
Sets the feature symbol associated with this label.
void setObstacleSettings(const QgsLabelObstacleSettings &settings)
Sets the label's obstacle settings.
void setAnchorPosition(const QgsPointXY &anchorPosition)
In case of quadrand or aligned positioning, this is set to the anchor point.
void setHasFixedPosition(bool enabled)
Sets whether the label should use a fixed position instead of being automatically placed.
void setRotatedSize(QSizeF size)
Sets an alternate label size to be used when a label rotation angle is between 45 to 135 and 235 to 3...
Contains settings related to how the label engine places and formats labels for line features (or pol...
AnchorType
Line anchor types.
void setPlacementFlags(QgsLabeling::LinePlacementFlags flags)
Returns the line placement flags, which dictate how line labels can be placed above or below the line...
QgsLabeling::LinePlacementFlags placementFlags() const
Returns the line placement flags, which dictate how line labels can be placed above or below the line...
bool reverseDirectionSymbol() const
Returns true if direction symbols should be reversed.
void setLineAnchorPercent(double percent)
Sets the percent along the line at which labels should be placed.
DirectionSymbolPlacement directionSymbolPlacement() const
Returns the placement for direction symbols.
void setDirectionSymbolPlacement(DirectionSymbolPlacement placement)
Sets the placement for direction symbols.
AnchorType anchorType() const
Returns the line anchor type, which dictates how the lineAnchorPercent() setting is handled.
QString leftDirectionSymbol() const
Returns the string to use for left direction arrows.
void setLeftDirectionSymbol(const QString &symbol)
Sets the string to use for left direction arrows.
QgsMapUnitScale overrunDistanceMapUnitScale() const
Returns the map unit scale for label overrun distance.
double overrunDistance() const
Returns the distance which labels are allowed to overrun past the start or end of line features.
QgsUnitTypes::RenderUnit overrunDistanceUnit() const
Returns the units for label overrun distance.
void setMergeLines(bool merge)
Sets whether connected line features with identical label text should be merged prior to generating l...
DirectionSymbolPlacement
Placement options for direction symbols.
@ SymbolLeftRight
Place direction symbols on left/right of label.
@ SymbolAbove
Place direction symbols on above label.
@ SymbolBelow
Place direction symbols on below label.
void setRightDirectionSymbol(const QString &symbol)
Sets the string to use for right direction arrows.
QString rightDirectionSymbol() const
Returns the string to use for right direction arrows.
void setOverrunDistanceMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for label overrun distance.
bool addDirectionSymbol() const
Returns true if '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) w...
double lineAnchorPercent() const
Returns the percent along the line at which labels should be placed.
bool mergeLines() const
Returns true if connected line features with identical label text should be merged prior to generatin...
void setAnchorType(AnchorType type)
Sets the line anchor type, which dictates how the lineAnchorPercent() setting is handled.
void setOverrunDistance(double distance)
Sets the distance which labels are allowed to overrun past the start or end of line features.
void setOverrunDistanceUnit(const QgsUnitTypes::RenderUnit &unit)
Sets the unit for label overrun distance.
void setReverseDirectionSymbol(bool reversed)
Sets whether the direction symbols should be reversed.
void setAddDirectionSymbol(bool enabled)
Sets whether '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) will...
void updateDataDefinedProperties(const QgsPropertyCollection &properties, QgsExpressionContext &context)
Updates the thinning settings to respect any data defined properties set within the specified propert...
Contains settings related to how the label engine treats features as obstacles.
double factor() const
Returns the obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels,...
void setType(ObstacleType type)
Controls how features act as obstacles for labels.
ObstacleType type() const
Returns how features act as obstacles for labels.
void setIsObstacle(bool isObstacle)
Sets whether features are obstacles to labels of other layers.
void setFactor(double factor)
Sets the obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels,...
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels.
void updateDataDefinedProperties(const QgsPropertyCollection &properties, QgsExpressionContext &context)
Updates the obstacle settings to respect any data defined properties set within the specified propert...
void setObstacleGeometry(const QgsGeometry &obstacleGeom)
Sets the label's obstacle geometry, if different to the feature geometry.
bool isObstacle() const
Returns true if the features are obstacles to labels of other layers.
Represents the calculated placement of a map label.
A class to query the labeling structure at a given point (small wrapper around pal RTree class)
Contains settings related to how the label engine removes candidate label positions and reduces the n...
void setMaximumNumberLabels(int number)
Sets the maximum number of labels which should be drawn for this layer.
double minimumFeatureSize() const
Returns the minimum feature size (in millimeters) for a feature to be labelled.
int maximumNumberLabels() const
Returns the maximum number of labels which should be drawn for this layer.
void updateDataDefinedProperties(const QgsPropertyCollection &properties, QgsExpressionContext &context)
Updates the thinning settings to respect any data defined properties set within the specified propert...
void setLimitNumberLabelsEnabled(bool enabled)
Sets whether the the number of labels drawn for the layer should be limited.
bool limitNumberOfLabelsEnabled() const
Returns true if the number of labels drawn for the layer should be limited.
void setMinimumFeatureSize(double size)
Sets the minimum feature size (in millimeters) for a feature to be labelled.
void setMapSettings(const QgsMapSettings &settings)
Sets the map settings associated with the labeling run.
QList< QgsLabelPosition > labelsAtPosition(const QgsPointXY &p) const
Returns infos about labels at a given (map) position.
QList< QgsLabelPosition > labelsWithinRect(const QgsRectangle &r) const
Returns infos about labels within a given (map) rectangle.
static QVector< QgsPalLayerSettings::PredefinedPointPosition > decodePredefinedPositionOrder(const QString &positionString)
Decodes a string to an ordered list of predefined point label positions.
static QString encodePredefinedPositionOrder(const QVector< QgsPalLayerSettings::PredefinedPointPosition > &positions)
Encodes an ordered list of predefined point label positions to a string.
Line string geometry type, with support for z-dimension and m-values.
Base class for all map layer types.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
The QgsMapSettings class contains configuration for rendering of the map.
const QgsMapToPixel & mapToPixel() const
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
Implementation of GeometrySimplifier using the "MapToPixel" algorithm.
SimplifyAlgorithm
Types of simplification algorithms that can be used.
@ SimplifyEnvelope
The geometries can be fully simplified by its BoundingBox.
QgsGeometry simplify(const QgsGeometry &geometry) const override
Returns a simplified version the specified geometry.
Perform transforms between map coordinates and device coordinates.
double mapUnitsPerPixel() const
Returns current map units per pixel.
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point p from map (world) coordinates to device coordinates.
double mapRotation() const
Returns current map rotation in degrees (clockwise)
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
double maxScale
The maximum scale, or 0.0 if unset.
double minScale
The minimum scale, or 0.0 if unset.
The QgsMargins class defines the four margins of a rectangle.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
static void drawLabelCandidateRect(pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform, QList< QgsLabelCandidate > *candidates=nullptr)
static QStringList splitToLines(const QString &text, const QString &wrapCharacter, int autoWrapLength=0, bool useMaxLineLengthWhenAutoWrapping=true)
Splits a text string to a list of separate lines, using a specified wrap character (wrapCharacter).
static QgsGeometry prepareGeometry(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry(), bool mergeLines=false)
Prepares a geometry for registration with PAL.
static bool geometryRequiresPreparation(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry(), bool mergeLines=false)
Checks whether a geometry requires preparation before registration with PAL.
static bool staticWillUseLayer(const QgsMapLayer *layer)
Called to find out whether a specified layer is used for labeling.
static QStringList splitToGraphemes(const QString &text)
Splits a text string to a list of graphemes, which are the smallest allowable character divisions in ...
Contains settings for how a map layer will be labeled.
bool fitInPolygonOnly
true if only labels which completely fit within a polygon are allowed.
double yOffset
Vertical offset of label.
QgsMapUnitScale labelOffsetMapUnitScale
Map unit scale for label offset.
int fontMaxPixelSize
Maximum pixel size for showing rendered map unit labels (1 - 10000).
double maxCurvedCharAngleIn
Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
double zIndex
Z-Index of label, where labels with a higher z-index are rendered on top of labels with a lower z-ind...
const QgsMapToPixel * xform
void startRender(QgsRenderContext &context)
Prepares the label settings for rendering.
bool displayAll
If true, all features will be labelled even when overlaps occur.
QString wrapChar
Wrapping character string.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
double xOffset
Horizontal offset of label.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the label's property collection, used for data defined overrides.
QgsCoordinateTransform ct
bool drawLabels
Whether to draw labels for this layer.
bool fontLimitPixelSize
true if label sizes should be limited by pixel size.
QgsExpression * getLabelExpression()
Returns the QgsExpression for this label settings.
QuadrantPosition quadOffset
Sets the quadrant in which to offset labels from feature.
double minimumScale
The minimum map scale (i.e.
void calculateLabelSize(const QFontMetricsF *fm, const QString &text, double &labelX, double &labelY, const QgsFeature *f=nullptr, QgsRenderContext *context=nullptr, double *rotatedLabelX=nullptr, double *rotatedLabelY=nullptr, QgsTextDocument *document=nullptr)
Calculates the space required to render the provided text in map units.
@ Upright
Upside-down labels (90 <= angle < 270) are shown upright.
QgsPalLayerSettings & operator=(const QgsPalLayerSettings &s)
copy operator - only copies the permanent members
QgsWkbTypes::GeometryType geometryGeneratorType
The type of the result geometry of the geometry generator.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QgsUnitTypes::RenderUnit offsetUnits
Units for offsets of label.
bool scaleVisibility
Set to true to limit label visibility to a range of scales.
QgsCallout * callout() const
Returns the label callout renderer, responsible for drawing label callouts.
double repeatDistance
Distance for repeating labels for a single feature.
void registerFeature(const QgsFeature &f, QgsRenderContext &context, QgsLabelFeature **labelFeature=nullptr, QgsGeometry obstacleGeometry=QgsGeometry(), const QgsSymbol *symbol=nullptr)
Register a feature for labeling.
bool geometryGeneratorEnabled
Defines if the geometry generator is enabled or not. If disabled, the standard geometry will be taken...
Placement
Placement modes which determine how label candidates are generated for a feature.
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only....
QVector< PredefinedPointPosition > predefinedPositionOrder
Ordered list of predefined label positions for points.
bool centroidInside
true if centroid positioned labels must be placed inside their corresponding feature polygon,...
int priority
Label priority.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
bool labelPerPart
true if every part of a multi-part feature should be labeled.
QgsUnitTypes::RenderUnit distUnits
Units the distance from feature to the label.
@ BottomSlightlyRight
Label below point, slightly right of center.
@ MiddleLeft
Label on left of point.
@ TopSlightlyRight
Label on top of point, slightly right of center.
@ MiddleRight
Label on right of point.
@ BottomRight
Label on bottom right of point.
@ BottomLeft
Label on bottom-left of point.
@ TopRight
Label on top-right of point.
@ TopLeft
Label on top-left of point.
QgsUnitTypes::RenderUnit repeatDistanceUnit
Units for repeating labels for a single feature.
OffsetType offsetType
Offset type for layer (only applies in certain placement modes)
MultiLineAlign multilineAlign
Horizontal alignment of multi-line labels.
int fontMinPixelSize
Minimum pixel size for showing rendered map unit labels (1 - 1000).
double angleOffset
Label rotation, in degrees clockwise.
double maxCurvedCharAngleOut
Maximum angle between outside curved label characters (valid range -20.0 to -95.0)
Property
Data definable properties.
@ MaskEnabled
Whether the mask is enabled.
@ LabelRotation
Label rotation.
@ PositionY
Y-coordinate data defined label position.
@ OverrunDistance
Distance which labels can extend past either end of linear features.
@ Strikeout
Use strikeout.
@ FontStyle
Font style name.
@ PositionX
X-coordinate data defined label position.
@ CalloutDraw
Show callout.
@ Underline
Use underline.
@ FontLetterSpacing
Letter spacing.
@ MaskJoinStyle
Mask join style.
@ MaxScale
Max scale (deprecated, for old project compatibility only)
@ Hali
Horizontal alignment for data defined label position (Left, Center, Right)
@ FontTransp
Text transparency (deprecated)
@ MaskBufferUnit
Mask buffer size unit.
@ LabelAllParts
Whether all parts of multi-part features should be labeled.
@ ShadowOpacity
Shadow opacity.
@ BufferOpacity
Buffer opacity.
@ LineAnchorPercent
Portion along line at which labels should be anchored (since QGIS 3.16)
@ ShapeOpacity
Shape opacity.
@ FontSizeUnit
Font size units.
@ Rotation
Label rotation (deprecated, for old project compatibility only)
@ Italic
Use italic style.
@ ShapeTransparency
Shape transparency (deprecated)
@ PredefinedPositionOrder
@ ShadowTransparency
Shadow transparency (deprecated)
@ MinScale
Min scale (deprecated, for old project compatibility only)
@ FontWordSpacing
Word spacing.
@ MaskBufferSize
Mask buffer size.
@ MinimumScale
Minimum map scale (ie most "zoomed out")
@ FontBlendMode
Text blend mode.
@ MaximumScale
Maximum map scale (ie most "zoomed in")
@ MaskOpacity
Mask opacity.
@ BufferTransp
Buffer transparency (deprecated)
@ PolygonLabelOutside
Whether labels outside a polygon feature are permitted, or should be forced (since QGIS 3....
@ FontCase
Label text case.
@ LinePlacementOptions
Line placement flags.
@ Vali
Vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top)
@ FontOpacity
Text opacity.
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
OffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes.
@ FromPoint
Offset distance applies from point geometry.
@ FromSymbolBounds
Offset distance applies from rendered symbol bounds.
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
bool preserveRotation
True if label rotation should be preserved during label pin/unpin operations.
static QPixmap labelSettingsPreviewPixmap(const QgsPalLayerSettings &settings, QSize size, const QString &previewText=QString(), int padding=0)
Returns a pixmap preview for label settings.
bool plusSign
Whether '+' signs should be prepended to positive numeric labels.
bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames, const QgsFields &fields, const QgsMapSettings &mapSettings, const QgsCoordinateReferenceSystem &crs)
Prepare for registration of features.
QString geometryGenerator
The geometry generator expression. Null if disabled.
QgsMapUnitScale distMapUnitScale
Map unit scale for label feature distance.
QgsStringReplacementCollection substitutions
Substitution collection for automatic text substitution with labels.
Q_DECL_DEPRECATED QColor previewBkgrdColor
const QgsFeature * mCurFeat
int decimals
Number of decimal places to show for numeric labels.
double dist
Distance from feature to the label.
QgsMapUnitScale repeatDistanceMapUnitScale
Map unit scale for repeating labels for a single feature.
bool centroidWhole
true if feature centroid should be calculated from the whole feature, or false if only the visible pa...
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc.
UpsideDownLabels upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
QString fieldName
Name of field (or an expression) to use for label text.
bool formatNumbers
Set to true to format numeric label text as numbers (e.g.
QgsWkbTypes::GeometryType layerType
Geometry type of layers associated with these settings.
void setCallout(QgsCallout *callout)
Sets the label callout renderer, responsible for drawing label callouts.
double maximumScale
The maximum map scale (i.e.
int autoWrapLength
If non-zero, indicates that label text should be automatically wrapped to (ideally) the specified num...
bool useMaxLineLengthForAutoWrap
If true, indicates that when auto wrapping label text the autoWrapLength length indicates the maximum...
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the labeling property definitions.
void stopRender(QgsRenderContext &context)
Finalises the label settings after use.
bool useSubstitutions
True if substitutions should be applied.
A class to represent a 2D point.
double distance(double x, double y) const SIP_HOLDGIL
Returns the distance between this point and a specified x, y coordinate.
Point geometry type, with support for z-dimension and m-values.
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the property with the specified key from within the collection.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), bool ignoreContext=false) const override
Returns the set of any fields referenced by the active properties from the collection.
void clear() override
Removes all properties from the collection.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
Definition for a property.
@ Double
Double value (including negative values)
@ Double0To1
Double value between 0-1 (inclusive)
@ StrokeWidth
Line stroke width.
@ String
Any string value.
@ RenderUnits
Render units (eg mm/pixels/map units)
@ PenJoinStyle
Pen join style.
@ SvgPath
Path to an SVG file.
@ IntegerPositive
Positive integer values (including 0)
@ ColorNoAlpha
Color with no alpha channel.
@ Rotation
Rotation (value between 0-360 degrees)
@ ColorWithAlpha
Color with alpha channel.
@ DoublePositive
Positive double value (including 0)
@ Size2D
2D size (width/height different)
@ DataTypeString
Property requires a string value.
@ DataTypeNumeric
Property requires a numeric value.
A store for object properties.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
void setActive(bool active)
Sets whether the property is currently active.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Contains information about the context of a rendering operation.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
double rendererScale() const
Returns the renderer map scale.
QgsExpressionContext & expressionContext()
Gets the expression context.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
QgsGeometry featureClipGeometry() const
Returns the geometry to use to clip features at render time.
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
@ Antialiasing
Use antialiasing while drawing.
double convertToMapUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
void readXml(const QDomElement &elem)
Reads the collection state from an XML element.
QString process(const QString &input) const
Processes a given input string, applying any valid replacements which should be made using QgsStringR...
void writeXml(QDomElement &elem, QDomDocument &doc) const
Writes the collection state to an XML element.
static QString capitalize(const QString &string, Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
Capitalization
Capitalization options.
@ MixedCase
Mixed case, ie no change.
@ AllLowercase
Convert all characters to lowercase.
@ TitleCase
Simple title case conversion - does not fully grammatically parse the text and uses simple rules only...
@ AllUppercase
Convert all characters to uppercase.
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
static QString wordWrap(const QString &string, int length, bool useMaxLineLength=true, const QString &customDelimiter=QString())
Automatically wraps a string by inserting new line characters at appropriate locations in the string.
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QColor decodeColor(const QString &str)
static QPointF toPoint(const QVariant &value, bool *ok=nullptr)
Converts a value to a point.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static QSizeF toSize(const QVariant &value, bool *ok=nullptr)
Converts a value to a size.
static QPainter::CompositionMode decodeBlendMode(const QString &s)
static QString encodeSize(QSizeF size)
Encodes a QSizeF to a string.
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
static QString encodeColor(const QColor &color)
static QString encodePoint(QPointF point)
Encodes a QPointF to a string.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
Abstract base class for all rendered symbols.
Container for settings relating to a text background object.
QString svgFile() const
Returns the absolute path to the background SVG file, if set.
QSizeF size() const
Returns the size of the background shape.
QSizeF radii() const
Returns the radii used for rounding the corners of shapes.
void setOpacity(double opacity)
Sets the background shape's opacity.
void setStrokeColor(const QColor &color)
Sets the color used for outlining the background shape.
Qt::PenJoinStyle joinStyle() const
Returns the join style used for drawing the background shape.
SizeType
Methods for determining the background shape size.
bool enabled() const
Returns whether the background is enabled.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the background shape.
void setRadiiUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's radii.
double opacity() const
Returns the background shape's opacity.
double rotation() const
Returns the rotation for the background shape, in degrees clockwise.
QColor fillColor() const
Returns the color used for filing the background shape.
void setRadii(QSizeF radii)
Sets the radii used for rounding the corners of shapes.
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
ShapeType type() const
Returns the type of background shape (e.g., square, ellipse, SVG).
double strokeWidth() const
Returns the width of the shape's stroke (stroke).
void setSizeType(SizeType type)
Sets the method used to determine the size of the background shape (e.g., fixed size or buffer around...
ShapeType
Background shape types.
@ ShapeMarkerSymbol
Marker symbol.
void setFillColor(const QColor &color)
Sets the color used for filing the background shape.
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's stroke width.
QColor strokeColor() const
Returns the color used for outlining the background shape.
void setRotationType(RotationType type)
Sets the method used for rotating the background shape.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the background shape.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the shape size.
void setType(ShapeType type)
Sets the type of background shape to draw (e.g., square, ellipse, SVG).
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units used for the shape's size.
RotationType
Methods for determining the rotation of the background shape.
void setEnabled(bool enabled)
Sets whether the text background will be drawn.
QgsMarkerSymbol * markerSymbol() const
Returns the marker symbol to be rendered in the background.
void setRotation(double rotation)
Sets the rotation for the background shape, in degrees clockwise.
void setOffset(QPointF offset)
Sets the offset used for drawing the background shape.
void setSize(QSizeF size)
Sets the size of the background shape.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the shape's size.
void setSvgFile(const QString &file)
Sets the path to the background SVG file.
void setStrokeWidth(double width)
Sets the width of the shape's stroke (stroke).
QPointF offset() const
Returns the offset used for drawing the background shape.
void setOffsetUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's offset.
Container for settings relating to a text buffer.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the buffer.
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
double size() const
Returns the size of the buffer.
void setColor(const QColor &color)
Sets the color for the buffer.
void setOpacity(double opacity)
Sets the buffer opacity.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the buffer size.
bool enabled() const
Returns whether the buffer is enabled.
double opacity() const
Returns the buffer opacity.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the buffer size.
QColor color() const
Returns the color of the buffer.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the buffer size.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the buffer.
void setSize(double size)
Sets the size of the buffer.
Represents a document consisting of one or more QgsTextBlock objects.
void splitLines(const QString &wrapCharacter, int autoWrapLength=0, bool useMaxLineLengthWhenAutoWrapping=true)
Splits lines of text in the document to separate lines, using a specified wrap character (wrapCharact...
QStringList toPlainText() const
Returns a list of plain text lines of text representing the document.
static QgsTextDocument fromHtml(const QStringList &lines)
Constructor for QgsTextDocument consisting of a set of HTML formatted lines.
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the text.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the size.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
double lineHeight() const
Returns the line height for text.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
void setOrientation(TextOrientation orientation)
Sets the orientation for the text.
void setShadow(const QgsTextShadowSettings &shadowSettings)
Sets the text's drop shadow settings.
void setMask(const QgsTextMaskSettings &maskSettings)
Sets the text's masking settings.
void setOpacity(double opacity)
Sets the text's opacity.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
TextOrientation orientation() const
Returns the orientation of the text.
QgsTextMaskSettings & mask()
Returns a reference to the masking settings.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
TextOrientation
Text orientation.
@ HorizontalOrientation
Vertically oriented text.
@ RotationBasedOrientation
Horizontally or vertically oriented text based on rotation (only available for map labeling)
@ VerticalOrientation
Horizontally oriented text.
double opacity() const
Returns the text's opacity.
QFont scaledFont(const QgsRenderContext &context, double scaleFactor=1.0) const
Returns a font with the size scaled to match the format's size settings (including units and map unit...
QString namedStyle() const
Returns the named style for the font used for rendering text (e.g., "bold").
double size() const
Returns the size for rendered text.
QgsTextShadowSettings & shadow()
Returns a reference to the text drop shadow settings.
void setBackground(const QgsTextBackgroundSettings &backgroundSettings)
Sets the text's background settings.q.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
QgsStringUtils::Capitalization capitalization() const
Returns the text capitalization style.
QColor color() const
Returns the color that text will be rendered in.
QFont font() const
Returns the font used for rendering text.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
QColor previewBackgroundColor() const
Returns the background color for text previews.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
void setLineHeight(double height)
Sets the line height for text.
Class that adds extra information to QgsLabelFeature for text labels.
void setDocument(const QgsTextDocument &document)
Sets the document for the label.
void setDefinedFont(const QFont &f)
Sets font to be used for rendering.
void calculateInfo(bool curvedLabeling, QFontMetricsF *fm, const QgsMapToPixel *xform, double fontScale, double maxinangle, double maxoutangle)
calculate data for info(). setDefinedFont() must have been called already.
void setDataDefinedValues(const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &values)
Sets data-defined values.
Container for settings relating to a selective masking around a text.
void setEnabled(bool)
Returns whether the mask is enabled.
void setSize(double size)
Sets the size of the buffer.
double size() const
Returns the size of the buffer.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the buffer size.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the buffer.
double opacity() const
Returns the mask's opacity.
bool enabled() const
Returns whether the mask is enabled.
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
void setOpacity(double opacity)
Sets the mask's opacity.
static QgsTextBackgroundSettings::ShapeType decodeShapeType(const QString &string)
Decodes a string representation of a background shape type to a type.
static QString encodeTextOrientation(QgsTextFormat::TextOrientation orientation)
Encodes a text orientation.
static QgsTextFormat::TextOrientation decodeTextOrientation(const QString &name, bool *ok=nullptr)
Attempts to decode a string representation of a text orientation.
static QgsTextShadowSettings::ShadowPlacement decodeShadowPlacementType(const QString &string)
Decodes a string representation of a shadow placement type to a type.
static QgsTextBackgroundSettings::RotationType decodeBackgroundRotationType(const QString &string)
Decodes a string representation of a background rotation type to a type.
static QgsTextBackgroundSettings::SizeType decodeBackgroundSizeType(const QString &string)
Decodes a string representation of a background size type to a type.
static double textWidth(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, QFontMetricsF *fontMetrics=nullptr)
Returns the width of a text based on a given format.
@ AlignCenter
Center align.
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, DrawMode mode=Point, QFontMetricsF *fontMetrics=nullptr)
Returns the height of a text based on a given format.
static int sizeToPixel(double size, const QgsRenderContext &c, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale())
Calculates pixel size (considering output size should be in pixel or map units, scale factors and opt...
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, VAlignment vAlignment=AlignTop)
Draws text within a rectangle using the specified settings.
@ Rect
Text within rectangle draw mode.
Container for settings relating to a text shadow.
int offsetAngle() const
Returns the angle for offsetting the position of the shadow from the text.
bool enabled() const
Returns whether the shadow is enabled.
int scale() const
Returns the scaling used for the drop shadow (in percentage of original size).
void setShadowPlacement(QgsTextShadowSettings::ShadowPlacement placement)
Sets the placement for the drop shadow.
double opacity() const
Returns the shadow's opacity.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the drop shadow.
void setColor(const QColor &color)
Sets the color for the drop shadow.
QColor color() const
Returns the color of the drop shadow.
ShadowPlacement
Placement positions for text shadow.
void setScale(int scale)
Sets the scaling used for the drop shadow (in percentage of original size).
double offsetDistance() const
Returns the distance for offsetting the position of the shadow from the text.
void setOffsetDistance(double distance)
Sets the distance for offsetting the position of the shadow from the text.
void setOpacity(double opacity)
Sets the shadow's opacity.
void setOffsetAngle(int angle)
Sets the angle for offsetting the position of the shadow from the text.
void setBlurRadiusUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shadow's blur radius.
double blurRadius() const
Returns the blur radius for the shadow.
void setBlurRadius(double blurRadius)
Sets the blur radius for the shadow.
void setOffsetUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shadow's offset.
void setEnabled(bool enabled)
Sets whether the text shadow will be drawn.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
RenderUnit
Rendering size units.
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
@ RenderPoints
Points (e.g., for font sizes)
@ RenderMillimeters
Millimeters.
@ RenderMapUnits
Map units.
Represents a vector layer which manages a vector based data sets.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
This class contains information how to simplify geometries fetched from a vector layer.
double tolerance() const
Gets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported,...
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
@ NoSimplification
No simplification can be applied.
Basic labeling configuration for vector tile layers.
Implements a map layer that is dedicated to rendering of vector tiles.
QgsVectorTileLabeling * labeling() const
Returns currently assigned labeling.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
LabelPosition is a candidate feature label position.
double getAlpha() const
Returns the angle to rotate text (in rad).
double cost() const
Returns the candidate label position's geographical cost.
bool conflictsWithObstacle() const
Returns whether the position is marked as conflicting with an obstacle feature.
LabelPosition * nextPart() const
Returns the next part of this label position (i.e.
FeaturePart * getFeaturePart() const
Returns the feature corresponding to this labelposition.
double getX(int i=0) const
Returns the down-left x coordinate.
double getY(int i=0) const
Returns the down-left y coordinate.
@ PointCloudLayer
Added in 3.18.
@ VectorTileLayer
Added in 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true)
Returns the value corresponding to the given key of an enum.
Q_GLOBAL_STATIC(QReadWriteLock, sDefinitionCacheLock)
#define QgsDebugMsgLevel(str, level)
QString updateDataDefinedString(const QString &value)
Q_GLOBAL_STATIC_WITH_ARGS(PredefinedPointPositionVector, DEFAULT_PLACEMENT_ORDER,({ QgsPalLayerSettings::TopRight, QgsPalLayerSettings::TopLeft, QgsPalLayerSettings::BottomRight, QgsPalLayerSettings::BottomLeft, QgsPalLayerSettings::MiddleRight, QgsPalLayerSettings::MiddleLeft, QgsPalLayerSettings::TopSlightlyRight, QgsPalLayerSettings::BottomSlightlyRight })) void QgsPalLayerSettings
QVector< QgsPalLayerSettings::PredefinedPointPosition > PredefinedPointPositionVector
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
const QgsCoordinateReferenceSystem & crs
Contains additional contextual information about the context in which a callout is being rendered.