34 #include <QApplication> 37 #include <QFontMetrics> 62 #include <QMessageBox> 77 const QVector< QgsPalLayerSettings::PredefinedPointPosition > QgsPalLayerSettings::DEFAULT_PLACEMENT_ORDER
96 void QgsPalLayerSettings::initPropertyDefinitions()
98 if ( !sPropertyDefinitions.isEmpty() )
101 const QString origin = QStringLiteral(
"labeling" );
113 "e.g. Helvetica or Helvetica [Cronyx]" ), origin )
117 "e.g. Bold Condensed or Light Italic" ), origin )
149 "<b>Ellipse</b>|<b>Circle</b>|<b>SVG</b>]" ), origin )
173 "<b>Buffer</b>|<b>Background</b>]" ), origin )
189 "<b>3</b>=Left|<b>4</b>=Over|<b>5</b>=Right|<br>" 190 "<b>6</b>=Below Left|<b>7</b>=Below|<b>8</b>=Below Right]" ), origin )
205 + QStringLiteral(
"[<b>TL</b>=Top left|<b>TSL</b>=Top, slightly left|<b>T</b>=Top middle|<br>" 206 "<b>TSR</b>=Top, slightly right|<b>TR</b>=Top right|<br>" 207 "<b>L</b>=Left|<b>R</b>=Right|<br>" 208 "<b>BL</b>=Bottom left|<b>BSL</b>=Bottom, slightly left|<b>B</b>=Bottom middle|<br>" 209 "<b>BSR</b>=Bottom, slightly right|<b>BR</b>=Bottom right]" ), origin )
216 "<b>Half</b>|<b>Cap</b>|<b>Top</b>]" ), origin )
237 initPropertyDefinitions();
240 isExpression =
false;
243 previewBkgrdColor = Qt::white;
244 useSubstitutions =
false;
247 multilineAlign = MultiFollowPlacement;
248 addDirectionSymbol =
false;
249 leftDirectionSymbol = QStringLiteral(
"<" );
250 rightDirectionSymbol = QStringLiteral(
">" );
251 reverseDirectionSymbol =
false;
252 placeDirectionSymbol = SymbolLeftRight;
253 formatNumbers =
false;
258 placement = AroundPoint;
259 placementFlags = AboveLine | MapOrientation;
260 centroidWhole =
false;
261 centroidInside =
false;
262 predefinedPositionOrder = DEFAULT_PLACEMENT_ORDER;
263 fitInPolygonOnly =
false;
264 quadOffset = QuadrantOver;
270 offsetType = FromPoint;
272 preserveRotation =
true;
273 maxCurvedCharAngleIn = 25.0;
274 maxCurvedCharAngleOut = -25.0;
280 scaleVisibility =
false;
283 fontLimitPixelSize =
false;
284 fontMinPixelSize = 0;
285 fontMaxPixelSize = 10000;
287 upsidedownLabels = Upright;
289 labelPerPart =
false;
291 minFeatureSize = 0.0;
292 limitNumLabels =
false;
295 obstacleFactor = 1.0;
296 obstacleType = PolygonInterior;
302 , mDataDefinedProperties( s.mDataDefinedProperties )
383 mDataDefinedProperties = s.mDataDefinedProperties;
399 initPropertyDefinitions();
400 return sPropertyDefinitions;
412 static Qt::PenJoinStyle _decodePenJoinStyle(
const QString &str )
414 if ( str.compare( QLatin1String(
"Miter" ), Qt::CaseInsensitive ) == 0 )
return Qt::MiterJoin;
415 if ( str.compare( QLatin1String(
"Round" ), Qt::CaseInsensitive ) == 0 )
return Qt::RoundJoin;
416 return Qt::BevelJoin;
422 QString newValue = value;
423 if ( !value.isEmpty() && !value.contains( QLatin1String(
"~~" ) ) )
426 values << QStringLiteral(
"1" );
427 values << QStringLiteral(
"0" );
430 newValue = values.join( QStringLiteral(
"~~" ) );
438 QString newPropertyName =
"labeling/dataDefined/" + sPropertyDefinitions.value( p ).name();
439 QVariant newPropertyField = layer->
customProperty( newPropertyName, QVariant() );
441 if ( !newPropertyField.isValid() )
444 QString ddString = newPropertyField.toString();
446 if ( !ddString.isEmpty() && ddString != QLatin1String(
"0~~0~~~~" ) )
450 QStringList ddv = newStyleString.split( QStringLiteral(
"~~" ) );
452 bool active = ddv.at( 0 ).toInt();
453 if ( ddv.at( 1 ).toInt() )
469 void QgsPalLayerSettings::readOldDataDefinedPropertyMap(
QgsVectorLayer *layer, QDomElement *parentElem )
471 if ( !layer && !parentElem )
476 QgsPropertiesDefinition::const_iterator i = sPropertyDefinitions.constBegin();
477 for ( ; i != sPropertyDefinitions.constEnd(); ++i )
482 readOldDataDefinedProperty( layer, static_cast< Property >( i.key() ) );
484 else if ( parentElem )
487 QDomElement e = parentElem->firstChildElement( i.value().name() );
490 bool active = e.attribute( QStringLiteral(
"active" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
491 bool isExpression = e.attribute( QStringLiteral(
"useExpr" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
505 void QgsPalLayerSettings::readFromLayerCustomProperties(
QgsVectorLayer *layer )
507 if ( layer->
customProperty( QStringLiteral(
"labeling" ) ).toString() != QLatin1String(
"pal" ) )
530 QDomDocument doc( QStringLiteral(
"substitutions" ) );
531 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/substitutions" ) ).toString() );
532 QDomElement replacementElem = doc.firstChildElement( QStringLiteral(
"substitutions" ) );
562 if ( layer->
customProperty( QStringLiteral(
"labeling/distMapUnitScale" ) ).toString().isEmpty() )
565 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMinScale" ), 0.0 ).toDouble();
567 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMaxScale" ), 0.0 ).toDouble();
578 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetInMapUnits" ), QVariant(
true ) ).toBool() )
583 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitScale" ) ).toString().isEmpty() )
586 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMinScale" ), 0.0 ).toDouble();
588 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
596 QVariant tempAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant() );
597 if ( tempAngle.isValid() )
599 double oldAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant( 0.0 ) ).toDouble();
612 switch ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceUnit" ), QVariant( 1 ) ).toUInt() )
627 if ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitScale" ) ).toString().isEmpty() )
630 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMinScale" ), 0.0 ).toDouble();
632 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMaxScale" ), 0.0 ).toDouble();
641 double scalemn = layer->
customProperty( QStringLiteral(
"labeling/scaleMin" ), QVariant( 0 ) ).toDouble();
642 double scalemx = layer->
customProperty( QStringLiteral(
"labeling/scaleMax" ), QVariant( 0 ) ).toDouble();
645 QVariant scalevis = layer->
customProperty( QStringLiteral(
"labeling/scaleVisibility" ), QVariant() );
646 if ( scalevis.isValid() )
652 else if ( scalemn > 0 || scalemx > 0 )
679 zIndex = layer->
customProperty( QStringLiteral(
"labeling/zIndex" ), QVariant( 0.0 ) ).toDouble();
681 mDataDefinedProperties.
clear();
682 if ( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).isValid() )
684 QDomDocument doc( QStringLiteral(
"dd" ) );
685 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).toString() );
686 QDomElement elem = doc.firstChildElement( QStringLiteral(
"properties" ) );
687 mDataDefinedProperties.
readXml( elem, sPropertyDefinitions );
692 readOldDataDefinedPropertyMap( layer,
nullptr );
736 QDomElement textStyleElem = elem.firstChildElement( QStringLiteral(
"text-style" ) );
737 fieldName = textStyleElem.attribute( QStringLiteral(
"fieldName" ) );
738 isExpression = textStyleElem.attribute( QStringLiteral(
"isExpression" ) ).toInt();
740 mFormat.
readXml( elem, context );
741 previewBkgrdColor = QColor( textStyleElem.attribute( QStringLiteral(
"previewBkgrdColor" ), QStringLiteral(
"#ffffff" ) ) );
743 useSubstitutions = textStyleElem.attribute( QStringLiteral(
"useSubstitutions" ) ).toInt();
746 QDomElement textFormatElem = elem.firstChildElement( QStringLiteral(
"text-format" ) );
747 wrapChar = textFormatElem.attribute( QStringLiteral(
"wrapChar" ) );
748 autoWrapLength = textFormatElem.attribute( QStringLiteral(
"autoWrapLength" ), QStringLiteral(
"0" ) ).toInt();
749 useMaxLineLengthForAutoWrap = textFormatElem.attribute( QStringLiteral(
"useMaxLineLengthForAutoWrap" ), QStringLiteral(
"1" ) ).toInt();
751 addDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"addDirectionSymbol" ) ).toInt();
752 leftDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"leftDirectionSymbol" ), QStringLiteral(
"<" ) );
753 rightDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"rightDirectionSymbol" ), QStringLiteral(
">" ) );
756 formatNumbers = textFormatElem.attribute( QStringLiteral(
"formatNumbers" ) ).toInt();
757 decimals = textFormatElem.attribute( QStringLiteral(
"decimals" ) ).toInt();
758 plusSign = textFormatElem.attribute( QStringLiteral(
"plussign" ) ).toInt();
761 QDomElement placementElem = elem.firstChildElement( QStringLiteral(
"placement" ) );
762 placement =
static_cast< Placement >( placementElem.attribute( QStringLiteral(
"placement" ) ).toInt() );
763 placementFlags = placementElem.attribute( QStringLiteral(
"placementFlags" ) ).toUInt();
764 centroidWhole = placementElem.attribute( QStringLiteral(
"centroidWhole" ), QStringLiteral(
"0" ) ).toInt();
765 centroidInside = placementElem.attribute( QStringLiteral(
"centroidInside" ), QStringLiteral(
"0" ) ).toInt();
769 fitInPolygonOnly = placementElem.attribute( QStringLiteral(
"fitInPolygonOnly" ), QStringLiteral(
"0" ) ).toInt();
770 dist = placementElem.attribute( QStringLiteral(
"dist" ) ).toDouble();
771 if ( !placementElem.hasAttribute( QStringLiteral(
"distUnits" ) ) )
773 if ( placementElem.attribute( QStringLiteral(
"distInMapUnits" ) ).toInt() )
782 if ( !placementElem.hasAttribute( QStringLiteral(
"distMapUnitScale" ) ) )
785 double oldMin = placementElem.attribute( QStringLiteral(
"distMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
787 double oldMax = placementElem.attribute( QStringLiteral(
"distMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
796 xOffset = placementElem.attribute( QStringLiteral(
"xOffset" ), QStringLiteral(
"0" ) ).toDouble();
797 yOffset = placementElem.attribute( QStringLiteral(
"yOffset" ), QStringLiteral(
"0" ) ).toDouble();
798 if ( !placementElem.hasAttribute( QStringLiteral(
"offsetUnits" ) ) )
806 if ( !placementElem.hasAttribute( QStringLiteral(
"labelOffsetMapUnitScale" ) ) )
809 double oldMin = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
811 double oldMax = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
819 if ( placementElem.hasAttribute( QStringLiteral(
"angleOffset" ) ) )
821 double oldAngle = placementElem.attribute( QStringLiteral(
"angleOffset" ), QStringLiteral(
"0" ) ).toDouble();
826 angleOffset = placementElem.attribute( QStringLiteral(
"rotationAngle" ), QStringLiteral(
"0" ) ).toDouble();
829 preserveRotation = placementElem.attribute( QStringLiteral(
"preserveRotation" ), QStringLiteral(
"1" ) ).toInt();
830 maxCurvedCharAngleIn = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleIn" ), QStringLiteral(
"25" ) ).toDouble();
831 maxCurvedCharAngleOut = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleOut" ), QStringLiteral(
"-25" ) ).toDouble();
832 priority = placementElem.attribute( QStringLiteral(
"priority" ) ).toInt();
833 repeatDistance = placementElem.attribute( QStringLiteral(
"repeatDistance" ), QStringLiteral(
"0" ) ).toDouble();
834 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceUnits" ) ) )
837 switch ( placementElem.attribute( QStringLiteral(
"repeatDistanceUnit" ), QString::number( 1 ) ).toUInt() )
857 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceMapUnitScale" ) ) )
860 double oldMin = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
862 double oldMax = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
871 QDomElement renderingElem = elem.firstChildElement( QStringLiteral(
"rendering" ) );
873 drawLabels = renderingElem.attribute( QStringLiteral(
"drawLabels" ), QStringLiteral(
"1" ) ).toInt();
875 maximumScale = renderingElem.attribute( QStringLiteral(
"scaleMin" ), QStringLiteral(
"0" ) ).toDouble();
876 minimumScale = renderingElem.attribute( QStringLiteral(
"scaleMax" ), QStringLiteral(
"0" ) ).toDouble();
877 scaleVisibility = renderingElem.attribute( QStringLiteral(
"scaleVisibility" ) ).toInt();
879 fontLimitPixelSize = renderingElem.attribute( QStringLiteral(
"fontLimitPixelSize" ), QStringLiteral(
"0" ) ).toInt();
880 fontMinPixelSize = renderingElem.attribute( QStringLiteral(
"fontMinPixelSize" ), QStringLiteral(
"0" ) ).toInt();
881 fontMaxPixelSize = renderingElem.attribute( QStringLiteral(
"fontMaxPixelSize" ), QStringLiteral(
"10000" ) ).toInt();
882 displayAll = renderingElem.attribute( QStringLiteral(
"displayAll" ), QStringLiteral(
"0" ) ).toInt();
885 labelPerPart = renderingElem.attribute( QStringLiteral(
"labelPerPart" ) ).toInt();
886 mergeLines = renderingElem.attribute( QStringLiteral(
"mergeLines" ) ).toInt();
887 minFeatureSize = renderingElem.attribute( QStringLiteral(
"minFeatureSize" ) ).toDouble();
888 limitNumLabels = renderingElem.attribute( QStringLiteral(
"limitNumLabels" ), QStringLiteral(
"0" ) ).toInt();
889 maxNumLabels = renderingElem.attribute( QStringLiteral(
"maxNumLabels" ), QStringLiteral(
"2000" ) ).toInt();
890 obstacle = renderingElem.attribute( QStringLiteral(
"obstacle" ), QStringLiteral(
"1" ) ).toInt();
891 obstacleFactor = renderingElem.attribute( QStringLiteral(
"obstacleFactor" ), QStringLiteral(
"1" ) ).toDouble();
893 zIndex = renderingElem.attribute( QStringLiteral(
"zIndex" ), QStringLiteral(
"0.0" ) ).toDouble();
895 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"dd_properties" ) );
896 if ( !ddElem.isNull() )
898 mDataDefinedProperties.
readXml( ddElem, sPropertyDefinitions );
903 mDataDefinedProperties.
clear();
904 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"data-defined" ) );
905 readOldDataDefinedPropertyMap(
nullptr, &ddElem );
950 QDomElement textStyleElem = mFormat.
writeXml( doc, context );
953 textStyleElem.setAttribute( QStringLiteral(
"fieldName" ),
fieldName );
954 textStyleElem.setAttribute( QStringLiteral(
"isExpression" ),
isExpression );
955 textStyleElem.setAttribute( QStringLiteral(
"previewBkgrdColor" ),
previewBkgrdColor.name() );
956 QDomElement replacementElem = doc.createElement( QStringLiteral(
"substitutions" ) );
958 textStyleElem.appendChild( replacementElem );
959 textStyleElem.setAttribute( QStringLiteral(
"useSubstitutions" ),
useSubstitutions );
962 QDomElement textFormatElem = doc.createElement( QStringLiteral(
"text-format" ) );
963 textFormatElem.setAttribute( QStringLiteral(
"wrapChar" ),
wrapChar );
964 textFormatElem.setAttribute( QStringLiteral(
"autoWrapLength" ),
autoWrapLength );
966 textFormatElem.setAttribute( QStringLiteral(
"multilineAlign" ), static_cast< unsigned int >(
multilineAlign ) );
967 textFormatElem.setAttribute( QStringLiteral(
"addDirectionSymbol" ),
addDirectionSymbol );
968 textFormatElem.setAttribute( QStringLiteral(
"leftDirectionSymbol" ),
leftDirectionSymbol );
971 textFormatElem.setAttribute( QStringLiteral(
"placeDirectionSymbol" ), static_cast< unsigned int >(
placeDirectionSymbol ) );
972 textFormatElem.setAttribute( QStringLiteral(
"formatNumbers" ),
formatNumbers );
973 textFormatElem.setAttribute( QStringLiteral(
"decimals" ),
decimals );
974 textFormatElem.setAttribute( QStringLiteral(
"plussign" ),
plusSign );
977 QDomElement placementElem = doc.createElement( QStringLiteral(
"placement" ) );
978 placementElem.setAttribute( QStringLiteral(
"placement" ),
placement );
979 placementElem.setAttribute( QStringLiteral(
"placementFlags" ), static_cast< unsigned int >(
placementFlags ) );
980 placementElem.setAttribute( QStringLiteral(
"centroidWhole" ),
centroidWhole );
981 placementElem.setAttribute( QStringLiteral(
"centroidInside" ),
centroidInside );
983 placementElem.setAttribute( QStringLiteral(
"fitInPolygonOnly" ),
fitInPolygonOnly );
984 placementElem.setAttribute( QStringLiteral(
"dist" ),
dist );
987 placementElem.setAttribute( QStringLiteral(
"offsetType" ), static_cast< unsigned int >(
offsetType ) );
988 placementElem.setAttribute( QStringLiteral(
"quadOffset" ), static_cast< unsigned int >(
quadOffset ) );
989 placementElem.setAttribute( QStringLiteral(
"xOffset" ),
xOffset );
990 placementElem.setAttribute( QStringLiteral(
"yOffset" ),
yOffset );
993 placementElem.setAttribute( QStringLiteral(
"rotationAngle" ),
angleOffset );
994 placementElem.setAttribute( QStringLiteral(
"preserveRotation" ),
preserveRotation );
997 placementElem.setAttribute( QStringLiteral(
"priority" ),
priority );
998 placementElem.setAttribute( QStringLiteral(
"repeatDistance" ),
repeatDistance );
1003 QDomElement renderingElem = doc.createElement( QStringLiteral(
"rendering" ) );
1004 renderingElem.setAttribute( QStringLiteral(
"drawLabels" ),
drawLabels );
1005 renderingElem.setAttribute( QStringLiteral(
"scaleVisibility" ),
scaleVisibility );
1006 renderingElem.setAttribute( QStringLiteral(
"scaleMin" ),
maximumScale );
1007 renderingElem.setAttribute( QStringLiteral(
"scaleMax" ),
minimumScale );
1008 renderingElem.setAttribute( QStringLiteral(
"fontLimitPixelSize" ),
fontLimitPixelSize );
1009 renderingElem.setAttribute( QStringLiteral(
"fontMinPixelSize" ),
fontMinPixelSize );
1010 renderingElem.setAttribute( QStringLiteral(
"fontMaxPixelSize" ),
fontMaxPixelSize );
1011 renderingElem.setAttribute( QStringLiteral(
"displayAll" ),
displayAll );
1012 renderingElem.setAttribute( QStringLiteral(
"upsidedownLabels" ), static_cast< unsigned int >(
upsidedownLabels ) );
1014 renderingElem.setAttribute( QStringLiteral(
"labelPerPart" ),
labelPerPart );
1015 renderingElem.setAttribute( QStringLiteral(
"mergeLines" ),
mergeLines );
1016 renderingElem.setAttribute( QStringLiteral(
"minFeatureSize" ),
minFeatureSize );
1017 renderingElem.setAttribute( QStringLiteral(
"limitNumLabels" ),
limitNumLabels );
1018 renderingElem.setAttribute( QStringLiteral(
"maxNumLabels" ),
maxNumLabels );
1019 renderingElem.setAttribute( QStringLiteral(
"obstacle" ),
obstacle );
1020 renderingElem.setAttribute( QStringLiteral(
"obstacleFactor" ),
obstacleFactor );
1021 renderingElem.setAttribute( QStringLiteral(
"obstacleType" ), static_cast< unsigned int >(
obstacleType ) );
1022 renderingElem.setAttribute( QStringLiteral(
"zIndex" ),
zIndex );
1024 QDomElement ddElem = doc.createElement( QStringLiteral(
"dd_properties" ) );
1025 mDataDefinedProperties.
writeXml( ddElem, sPropertyDefinitions );
1027 QDomElement elem = doc.createElement( QStringLiteral(
"settings" ) );
1028 elem.appendChild( textStyleElem );
1029 elem.appendChild( textFormatElem );
1030 elem.appendChild( placementElem );
1031 elem.appendChild( renderingElem );
1032 elem.appendChild( ddElem );
1038 return QgsPalLabeling::checkMinimumSizeMM( ct, geom, minSize );
1048 QString textCopy( text );
1051 std::unique_ptr< QgsRenderContext > scopedRc;
1056 scopedRc->expressionContext().setFeature( *f );
1139 if ( wrapchr.isEmpty() )
1141 wrapchr = QStringLiteral(
"\n" );
1146 && ( !leftDirSymb.isEmpty() || !rightDirSymb.isEmpty() ) )
1148 QString dirSym = leftDirSymb;
1150 if ( fm->width( rightDirSymb ) > fm->width( dirSym ) )
1151 dirSym = rightDirSymb;
1155 textCopy.append( dirSym );
1159 textCopy.prepend( dirSym + QStringLiteral(
"\n" ) );
1163 double w = 0.0, h = 0.0;
1165 int lines = multiLineSplit.size();
1167 double labelHeight = fm->ascent() + fm->descent();
1169 h += fm->height() +
static_cast< double >( ( lines - 1 ) * labelHeight * multilineH );
1171 for (
const QString &line : multiLineSplit )
1173 w = std::max( w, fm->width( line ) );
1178 labelX = std::fabs( ptSize.x() -
ptZero.
x() );
1179 labelY = std::fabs( ptSize.y() -
ptZero.
y() );
1190 Q_ASSERT( labelFeature );
1202 registerObstacleFeature( f, context, labelFeature, obstacleGeometry );
1210 dataDefinedValues.clear();
1222 if ( useScaleVisibility )
1231 maxScale = 1 / std::fabs( maxScale );
1246 minScale = 1 / std::fabs( minScale );
1255 QFont labelFont = mFormat.
font();
1261 if ( exprVal.isValid() )
1263 QString units = exprVal.toString();
1264 if ( !units.isEmpty() )
1276 if ( fontSize <= 0.0 )
1283 if ( fontPixelSize < 1 )
1287 labelFont.setPixelSize( fontPixelSize );
1299 if ( fontMinPixel > labelFont.pixelSize() || labelFont.pixelSize() > fontMaxPixel )
1311 labelFont.setCapitalization( QFont::MixedCase );
1312 parseTextStyle( labelFont, fontunits, context );
1313 parseTextFormatting( context );
1314 parseTextBuffer( context );
1315 parseShapeBackground( context );
1316 parseDropShadow( context );
1336 labelText = result.isNull() ? QString() : result.toString();
1341 labelText = v.isNull() ? QString() : v.toString();
1353 if ( mFormat.
font().capitalization() != QFont::MixedCase )
1359 if ( exprVal.isValid() )
1361 QString fcase = exprVal.toString().trimmed();
1362 QgsDebugMsgLevel( QStringLiteral(
"exprVal FontCase:%1" ).arg( fcase ), 4 );
1364 if ( !fcase.isEmpty() )
1366 if ( fcase.compare( QLatin1String(
"NoChange" ), Qt::CaseInsensitive ) == 0 )
1370 else if ( fcase.compare( QLatin1String(
"Upper" ), Qt::CaseInsensitive ) == 0 )
1374 else if ( fcase.compare( QLatin1String(
"Lower" ), Qt::CaseInsensitive ) == 0 )
1378 else if ( fcase.compare( QLatin1String(
"Capitalize" ), Qt::CaseInsensitive ) == 0 )
1391 if ( decimalPlaces <= 0 )
1397 QVariant textV( labelText );
1399 double d = textV.toDouble( &ok );
1402 QString numberFormat;
1403 if ( d > 0 && signPlus )
1405 numberFormat.append(
'+' );
1407 numberFormat.append(
"%1" );
1408 labelText = numberFormat.arg( d, 0,
'f', decimalPlaces );
1413 std::unique_ptr<QFontMetricsF> labelFontMetrics(
new QFontMetricsF( labelFont ) );
1414 double labelX, labelY;
1420 double maxcharanglein = 20.0;
1421 double maxcharangleout = -20.0;
1430 if ( exprVal.isValid() )
1432 QString ptstr = exprVal.toString().trimmed();
1433 QgsDebugMsgLevel( QStringLiteral(
"exprVal CurvedCharAngleInOut:%1" ).arg( ptstr ), 4 );
1435 if ( !ptstr.isEmpty() )
1438 maxcharanglein = qBound( 20.0, static_cast< double >( maxcharanglePt.x() ), 60.0 );
1439 maxcharangleout = qBound( 20.0, static_cast< double >( maxcharanglePt.y() ), 95.0 );
1443 maxcharangleout = -( std::fabs( maxcharangleout ) );
1449 if ( exprVal.isValid() )
1451 QString str = exprVal.toString().trimmed();
1452 QgsDebugMsgLevel( QStringLiteral(
"exprVal CentroidWhole:%1" ).arg( str ), 4 );
1454 if ( !str.isEmpty() )
1456 if ( str.compare( QLatin1String(
"Visible" ), Qt::CaseInsensitive ) == 0 )
1458 wholeCentroid =
false;
1460 else if ( str.compare( QLatin1String(
"Whole" ), Qt::CaseInsensitive ) == 0 )
1462 wholeCentroid =
true;
1475 std::unique_ptr<QgsGeometry> scopedClonedGeom;
1482 geom = simplifier.
simplify( geom );
1492 bool doClip =
false;
1493 if ( !centroidPoly || !wholeCentroid )
1503 permissibleZone = geom;
1539 if ( !geos_geom_clone )
1568 if ( !obstacleGeometry.
isNull() )
1575 bool dataDefinedPosition =
false;
1576 bool layerDefinedRotation =
false;
1577 bool dataDefinedRotation =
false;
1578 double xPos = 0.0, yPos = 0.0,
angle = 0.0;
1579 bool ddXPos =
false, ddYPos =
false;
1580 double quadOffsetX = 0.0, quadOffsetY = 0.0;
1581 double offsetX = 0.0, offsetY = 0.0;
1584 bool ddFixedQuad =
false;
1588 if ( exprVal.isValid() )
1591 int quadInt = exprVal.toInt( &ok );
1592 QgsDebugMsgLevel( QStringLiteral(
"exprVal OffsetQuad:%1" ).arg( quadInt ), 4 );
1593 if ( ok && 0 <= quadInt && quadInt <= 8 )
1645 if ( exprVal.isValid() )
1647 QString ptstr = exprVal.toString().trimmed();
1648 QgsDebugMsgLevel( QStringLiteral(
"exprVal OffsetXY:%1" ).arg( ptstr ), 4 );
1650 if ( !ptstr.isEmpty() )
1661 if ( exprVal.isValid() )
1663 QString units = exprVal.toString().trimmed();
1664 QgsDebugMsgLevel( QStringLiteral(
"exprVal OffsetUnits:%1" ).arg( units ), 4 );
1665 if ( !units.isEmpty() )
1671 offUnit = decodedUnits;
1686 layerDefinedRotation =
true;
1694 if ( exprVal.isValid() )
1697 double rotD = exprVal.toDouble( &ok );
1698 QgsDebugMsgLevel( QStringLiteral(
"exprVal Rotation:%1" ).arg( rotD ), 4 );
1701 dataDefinedRotation =
true;
1705 angle = ( 360 - rotD ) * M_PI / 180.0;
1710 if ( exprVal.isValid() )
1712 if ( !exprVal.isNull() )
1713 xPos = exprVal.toDouble( &ddXPos );
1714 QgsDebugMsgLevel( QStringLiteral(
"exprVal PositionX:%1" ).arg( xPos ), 4 );
1717 if ( exprVal.isValid() )
1720 if ( !exprVal.isNull() )
1721 yPos = exprVal.toDouble( &ddYPos );
1722 QgsDebugMsgLevel( QStringLiteral(
"exprVal PositionY:%1" ).arg( yPos ), 4 );
1724 if ( ddXPos && ddYPos )
1726 dataDefinedPosition =
true;
1728 if ( layerDefinedRotation && !dataDefinedRotation )
1739 if ( exprVal.isValid() )
1741 QString haliString = exprVal.toString();
1742 QgsDebugMsgLevel( QStringLiteral(
"exprVal Hali:%1" ).arg( haliString ), 4 );
1743 if ( haliString.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
1745 xdiff -= labelX / 2.0;
1747 else if ( haliString.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
1755 if ( exprVal.isValid() )
1757 QString valiString = exprVal.toString();
1758 QgsDebugMsgLevel( QStringLiteral(
"exprVal Vali:%1" ).arg( valiString ), 4 );
1760 if ( valiString.compare( QLatin1String(
"Bottom" ), Qt::CaseInsensitive ) != 0 )
1762 if ( valiString.compare( QLatin1String(
"Top" ), Qt::CaseInsensitive ) == 0 )
1768 double descentRatio = labelFontMetrics->descent() / labelFontMetrics->height();
1769 if ( valiString.compare( QLatin1String(
"Base" ), Qt::CaseInsensitive ) == 0 )
1771 ydiff -= labelY * descentRatio;
1775 double capHeightRatio = ( labelFontMetrics->boundingRect(
'H' ).height() + 1 + labelFontMetrics->descent() ) / labelFontMetrics->height();
1776 ydiff -= labelY * capHeightRatio;
1777 if ( valiString.compare( QLatin1String(
"Half" ), Qt::CaseInsensitive ) == 0 )
1779 ydiff += labelY * ( capHeightRatio - descentRatio ) / 2.0;
1786 if ( dataDefinedRotation )
1789 double xd = xdiff * std::cos(
angle ) - ydiff * std::sin(
angle );
1790 double yd = xdiff * std::sin(
angle ) + ydiff * std::cos(
angle );
1829 if ( exprVal.isValid() )
1831 QString units = exprVal.toString().trimmed();
1832 QgsDebugMsgLevel( QStringLiteral(
"exprVal RepeatDistanceUnits:%1" ).arg( units ), 4 );
1833 if ( !units.isEmpty() )
1839 repeatUnits = decodedUnits;
1858 ( *labelFeature )->setFixedPosition(
QgsPointXY( xPos, yPos ) );
1860 ( *labelFeature )->setHasFixedAngle( dataDefinedRotation || ( !dataDefinedPosition && !
qgsDoubleNear(
angle, 0.0 ) ) );
1861 ( *labelFeature )->setFixedAngle(
angle );
1862 ( *labelFeature )->setQuadOffset( QPointF( quadOffsetX, quadOffsetY ) );
1863 ( *labelFeature )->setPositionOffset(
QgsPointXY( offsetX, offsetY ) );
1864 ( *labelFeature )->setOffsetType(
offsetType );
1865 ( *labelFeature )->setAlwaysShow( alwaysShow );
1866 ( *labelFeature )->setRepeatDistance( repeatDist );
1867 ( *labelFeature )->setLabelText( labelText );
1868 ( *labelFeature )->setPermissibleZone( permissibleZone );
1869 if ( geosObstacleGeomClone )
1871 ( *labelFeature )->setObstacleGeometry( std::move( geosObstacleGeomClone ) );
1876 ( *labelFeature )->setSymbolSize( QSizeF( obstacleGeometry.
boundingBox().
width(),
1883 double topMargin = std::max( 0.25 * labelFontMetrics->ascent(), 0.0 );
1884 double bottomMargin = 1.0 + labelFontMetrics->descent();
1885 QgsMargins vm( 0.0, topMargin, 0.0, bottomMargin );
1887 ( *labelFeature )->setVisualMargin( vm );
1890 QgsDebugMsgLevel( QStringLiteral(
"PAL font stored definedFont: %1, Style: %2" ).arg( labelFont.toString(), labelFont.styleName() ), 4 );
1896 labelFontMetrics.get(),
xform, maxcharanglein, maxcharangleout );
1908 if ( exprVal.isValid() )
1910 QString units = exprVal.toString().trimmed();
1911 QgsDebugMsgLevel( QStringLiteral(
"exprVal DistanceUnits:%1" ).arg( units ), 4 );
1912 if ( !units.isEmpty() )
1918 distUnit = decodedUnits;
1928 distance = std::max( distance, 1.0 );
1934 ( *labelFeature )->setDistLabel( d );
1939 ( *labelFeature )->setHasFixedQuadrant(
true );
1945 ( *labelFeature )->setZIndex( z );
1950 if ( exprVal.isValid() )
1953 double priorityD = exprVal.toDouble( &ok );
1956 priorityD = qBound( 0.0, priorityD, 10.0 );
1957 priorityD = 1 - priorityD / 10.0;
1958 ( *labelFeature )->setPriority( priorityD );
1962 ( *labelFeature )->setIsObstacle( isObstacle );
1967 if ( exprVal.isValid() )
1970 double factorD = exprVal.toDouble( &ok );
1973 factorD = qBound( 0.0, factorD, 10.0 );
1974 factorD = factorD / 5.0 + 0.0001;
1975 featObstacleFactor = factorD;
1978 ( *labelFeature )->setObstacleFactor( featObstacleFactor );
1981 if ( positionOrder.isEmpty() )
1982 positionOrder = QgsPalLayerSettings::DEFAULT_PLACEMENT_ORDER;
1986 if ( !dataDefinedOrder.isEmpty() )
1990 ( *labelFeature )->setPredefinedPositionOrder( positionOrder );
2001 if ( !obstacleGeometry.
isNull() )
2003 geom = obstacleGeometry;
2017 std::unique_ptr<QgsGeometry> scopedClonedGeom;
2023 geom = simplifier.
simplify( geom );
2027 std::unique_ptr<QgsGeometry> scopedPreparedGeom;
2035 if ( !geos_geom_clone )
2039 *obstacleFeature =
new QgsLabelFeature( f.
id(), std::move( geos_geom_clone ), QSizeF( 0, 0 ) );
2044 bool QgsPalLayerSettings::dataDefinedValEval( DataDefinedValueType valType,
2048 if ( !mDataDefinedProperties.
isActive( p ) )
2052 exprVal = mDataDefinedProperties.
value( p, context );
2053 if ( exprVal.isValid() )
2059 bool bol = exprVal.toBool();
2060 dataDefinedValues.insert( p, QVariant( bol ) );
2066 int size = exprVal.toInt( &ok );
2070 dataDefinedValues.insert( p, QVariant( size ) );
2078 int size = exprVal.toInt( &ok );
2080 if ( ok && size > 0 )
2082 dataDefinedValues.insert( p, QVariant( size ) );
2090 double size = exprVal.toDouble( &ok );
2094 dataDefinedValues.insert( p, QVariant( size ) );
2102 double size = exprVal.toDouble( &ok );
2104 if ( ok && size > 0.0 )
2106 dataDefinedValues.insert( p, QVariant( size ) );
2114 double rot = exprVal.toDouble( &ok );
2117 if ( rot < -180.0 && rot >= -360 )
2121 if ( rot > 180.0 && rot <= 360 )
2125 if ( rot >= -180 && rot <= 180 )
2127 dataDefinedValues.insert( p, QVariant( rot ) );
2136 int size = exprVal.toDouble( &ok );
2137 if ( ok && size >= 0 && size <= 100 )
2139 dataDefinedValues.insert( p, QVariant( size ) );
2146 QString str = exprVal.toString();
2148 dataDefinedValues.insert( p, QVariant( str ) );
2153 QString unitstr = exprVal.toString().trimmed();
2155 if ( !unitstr.isEmpty() )
2164 QString colorstr = exprVal.toString().trimmed();
2167 if ( color.isValid() )
2169 dataDefinedValues.insert( p, QVariant( color ) );
2176 QString joinstr = exprVal.toString().trimmed();
2178 if ( !joinstr.isEmpty() )
2180 dataDefinedValues.insert( p, QVariant( static_cast< int >( _decodePenJoinStyle( joinstr ) ) ) );
2187 QString blendstr = exprVal.toString().trimmed();
2189 if ( !blendstr.isEmpty() )
2198 QString ptstr = exprVal.toString().trimmed();
2200 if ( !ptstr.isEmpty() )
2209 QString ptstr = exprVal.toString().trimmed();
2211 if ( !ptstr.isEmpty() )
2223 void QgsPalLayerSettings::parseTextStyle( QFont &labelFont,
2236 QString ddFontFamily;
2239 if ( exprVal.isValid() )
2241 QString family = exprVal.toString().trimmed();
2242 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font family:%1" ).arg( family ), 4 );
2244 if ( labelFont.family() != family )
2250 ddFontFamily = family;
2256 QString ddFontStyle;
2258 if ( exprVal.isValid() )
2260 QString fontstyle = exprVal.toString().trimmed();
2261 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font style:%1" ).arg( fontstyle ), 4 );
2262 ddFontStyle = fontstyle;
2276 QFont appFont = QApplication::font();
2277 bool newFontBuilt =
false;
2278 if ( ddBold || ddItalic )
2281 newFont = QFont( !ddFontFamily.isEmpty() ? ddFontFamily : labelFont.family() );
2282 newFontBuilt =
true;
2283 newFont.setBold( ddBold );
2284 newFont.setItalic( ddItalic );
2286 else if ( !ddFontStyle.isEmpty()
2287 && ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2289 if ( !ddFontFamily.isEmpty() )
2292 QFont styledfont = mFontDB.font( ddFontFamily, ddFontStyle, appFont.pointSize() );
2293 if ( appFont != styledfont )
2295 newFont = styledfont;
2296 newFontBuilt =
true;
2303 else if ( !ddFontFamily.isEmpty() )
2305 if ( ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2308 QFont styledfont = mFontDB.font( ddFontFamily, mFormat.
namedStyle(), appFont.pointSize() );
2309 if ( appFont != styledfont )
2311 newFont = styledfont;
2312 newFontBuilt =
true;
2317 newFont = QFont( ddFontFamily );
2318 newFontBuilt =
true;
2326 newFont.setPixelSize( labelFont.pixelSize() );
2327 newFont.setUnderline( labelFont.underline() );
2328 newFont.setStrikeOut( labelFont.strikeOut() );
2329 newFont.setWordSpacing( labelFont.wordSpacing() );
2330 newFont.setLetterSpacing( QFont::AbsoluteSpacing, labelFont.letterSpacing() );
2332 labelFont = newFont;
2336 double wordspace = labelFont.wordSpacing();
2342 double letterspace = labelFont.letterSpacing();
2352 labelFont.setStrikeOut( strikeout );
2360 labelFont.setUnderline( underline );
2386 drawBuffer = exprVal.toBool();
2395 double bufrSize = buffer.
size();
2398 bufrSize = exprVal.toDouble();
2402 double bufferOpacity = buffer.
opacity() * 100;
2405 bufferOpacity = exprVal.toDouble();
2408 drawBuffer = ( drawBuffer && bufrSize > 0.0 && bufferOpacity > 0 );
2439 wrapchr = exprVal.toString();
2445 evalAutoWrapLength = exprVal.toInt();
2454 if ( exprVal.isValid() )
2456 QString str = exprVal.toString().trimmed();
2457 QgsDebugMsgLevel( QStringLiteral(
"exprVal MultiLineAlignment:%1" ).arg( str ), 4 );
2459 if ( !str.isEmpty() )
2464 if ( str.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
2468 else if ( str.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
2472 else if ( str.compare( QLatin1String(
"Follow" ), Qt::CaseInsensitive ) == 0 )
2484 drawDirSymb = exprVal.toBool();
2497 if ( exprVal.isValid() )
2499 QString str = exprVal.toString().trimmed();
2500 QgsDebugMsgLevel( QStringLiteral(
"exprVal DirSymbPlacement:%1" ).arg( str ), 4 );
2502 if ( !str.isEmpty() )
2507 if ( str.compare( QLatin1String(
"Above" ), Qt::CaseInsensitive ) == 0 )
2511 else if ( str.compare( QLatin1String(
"Below" ), Qt::CaseInsensitive ) == 0 )
2526 void QgsPalLayerSettings::parseShapeBackground(
QgsRenderContext &context )
2533 bool drawShape = background.
enabled();
2536 drawShape = exprVal.toBool();
2545 double shapeOpacity = background.
opacity() * 100;
2548 shapeOpacity = 100.0 * exprVal.toDouble();
2551 drawShape = ( drawShape && shapeOpacity > 0 );
2563 if ( exprVal.isValid() )
2565 QString skind = exprVal.toString().trimmed();
2566 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeKind:%1" ).arg( skind ), 4 );
2568 if ( !skind.isEmpty() )
2573 if ( skind.compare( QLatin1String(
"Square" ), Qt::CaseInsensitive ) == 0 )
2577 else if ( skind.compare( QLatin1String(
"Ellipse" ), Qt::CaseInsensitive ) == 0 )
2581 else if ( skind.compare( QLatin1String(
"Circle" ), Qt::CaseInsensitive ) == 0 )
2585 else if ( skind.compare( QLatin1String(
"SVG" ), Qt::CaseInsensitive ) == 0 )
2589 shapeKind = shpkind;
2595 QString svgPath = background.
svgFile();
2598 if ( exprVal.isValid() )
2600 QString svgfile = exprVal.toString().trimmed();
2601 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSVGFile:%1" ).arg( svgfile ), 4 );
2611 if ( exprVal.isValid() )
2613 QString stype = exprVal.toString().trimmed();
2614 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSizeType:%1" ).arg( stype ), 4 );
2616 if ( !stype.isEmpty() )
2621 if ( stype.compare( QLatin1String(
"Fixed" ), Qt::CaseInsensitive ) == 0 )
2625 shpSizeType = sizType;
2631 double ddShpSizeX = background.
size().width();
2634 ddShpSizeX = exprVal.toDouble();
2638 double ddShpSizeY = background.
size().height();
2641 ddShpSizeY = exprVal.toDouble();
2647 && ( svgPath.isEmpty()
2648 || ( !svgPath.isEmpty()
2650 && ddShpSizeX == 0.0 ) ) )
2656 && ( ddShpSizeX == 0.0 || ddShpSizeY == 0.0 ) )
2677 if ( exprVal.isValid() )
2679 QString rotstr = exprVal.toString().trimmed();
2680 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeRotationType:%1" ).arg( rotstr ), 4 );
2682 if ( !rotstr.isEmpty() )
2687 if ( rotstr.compare( QLatin1String(
"Offset" ), Qt::CaseInsensitive ) == 0 )
2691 else if ( rotstr.compare( QLatin1String(
"Fixed" ), Qt::CaseInsensitive ) == 0 )
2741 bool drawShadow = shadow.
enabled();
2744 drawShadow = exprVal.toBool();
2753 double shadowOpacity = shadow.
opacity() * 100;
2756 shadowOpacity = exprVal.toDouble();
2763 shadowOffDist = exprVal.toDouble();
2770 shadowRad = exprVal.toDouble();
2773 drawShadow = ( drawShadow && shadowOpacity > 0 && !( shadowOffDist == 0.0 && shadowRad == 0.0 ) );
2786 if ( exprVal.isValid() )
2788 QString str = exprVal.toString().trimmed();
2789 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShadowUnder:%1" ).arg( str ), 4 );
2791 if ( !str.isEmpty() )
2796 if ( str.compare( QLatin1String(
"Text" ), Qt::CaseInsensitive ) == 0 )
2800 else if ( str.compare( QLatin1String(
"Buffer" ), Qt::CaseInsensitive ) == 0 )
2804 else if ( str.compare( QLatin1String(
"Background" ), Qt::CaseInsensitive ) == 0 )
2872 QStringList multiLineSplit;
2873 if ( !wrapCharacter.isEmpty() && wrapCharacter != QLatin1String(
"\n" ) )
2876 const QStringList lines = text.split( wrapCharacter );
2877 for (
const QString &line : lines )
2879 multiLineSplit.append( line.split(
'\n' ) );
2884 multiLineSplit = text.split(
'\n' );
2888 if ( autoWrapLength != 0 )
2890 QStringList autoWrappedLines;
2891 autoWrappedLines.reserve( multiLineSplit.count() );
2892 for (
const QString &line : qgis::as_const( multiLineSplit ) )
2894 autoWrappedLines.append(
QgsStringUtils::wordWrap( line, autoWrapLength, useMaxLineLengthWhenAutoWrapping ).split(
'\n' ) );
2896 multiLineSplit = autoWrappedLines;
2898 return multiLineSplit;
2903 QStringList graphemes;
2904 QTextBoundaryFinder boundaryFinder( QTextBoundaryFinder::Grapheme, text );
2905 int currentBoundary = -1;
2906 int previousBoundary = 0;
2907 while ( ( currentBoundary = boundaryFinder.toNextBoundary() ) > 0 )
2909 graphemes << text.mid( previousBoundary, currentBoundary - previousBoundary );
2910 previousBoundary = currentBoundary;
2935 QgsDebugMsgLevel( QStringLiteral(
"Ignoring feature due to transformation exception" ), 4 );
2941 return std::isfinite( point.
x() ) && std::isfinite( point.
y() );
2944 cp->removeInvalidRings();
2962 QgsDebugMsgLevel( QStringLiteral(
"Ignoring feature due to transformation exception" ), 4 );
2969 QgsDebugMsg( QStringLiteral(
"Error rotating geometry" ).arg( geom.
asWkt() ) );
2978 if ( bufferGeom.
isNull() )
2980 QgsDebugMsg( QStringLiteral(
"Could not repair geometry: %1" ).arg( bufferGeom.
lastError() ) );
2986 if ( !clipGeometry.
isNull() &&
3022 double length = geom.
length();
3023 if ( length >= 0.0 )
3025 return ( length >= ( minSize * mapUnitsPerMM ) );
3030 double area = geom.
area();
3033 return ( std::sqrt( area ) >= ( minSize * mapUnitsPerMM ) );
3041 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3044 bool changed =
false;
3050 format.
setColor( ddColor.value<QColor>() );
3075 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3130 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3133 bool changed =
false;
3181 buffer.
setColor( ddColor.value<QColor>() );
3208 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3211 bool changed =
false;
3251 QSizeF size = background.
size();
3258 QSizeF size = background.
size();
3359 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3362 bool changed =
false;
3421 shadow.
setColor( ddColor.value<QColor>() );
3459 #if 0 // TODO: generalize some of this 3462 double cx = lp->
getX() + w / 2.0;
3463 double cy = lp->
getY() + h / 2.0;
3466 double sw = w * scale;
3467 double sh = h * scale;
3468 QRectF rect( -sw / 2, -sh / 2, sw, sh );
3474 if ( lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT &&
3475 lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT_OVER &&
3478 painter->rotate( rotation );
3481 painter->translate( rect.bottomLeft() );
3482 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
3483 painter->translate( -rect.bottomLeft() );
3486 QRectF rect( 0, 0, outPt2.
x() - outPt.
x(), outPt2.
y() - outPt.
y() );
3487 painter->translate( QPointF( outPt.
x(), outPt.
y() ) );
3488 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
3493 painter->setPen( QColor( 255, 0, 0, 64 ) );
3497 painter->setPen( QColor( 0, 0, 0, 64 ) );
3499 painter->drawRect( rect );
3503 rect.moveTo( outPt.
x(), outPt.
y() );
3519 delete mLabelSearchTree;
3520 mLabelSearchTree =
nullptr;
3525 QList<QgsLabelPosition> positions;
3527 QList<QgsLabelPosition *> positionPointers;
3528 if ( mLabelSearchTree )
3530 mLabelSearchTree->label( p, positionPointers );
3531 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
3532 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
3543 QList<QgsLabelPosition> positions;
3545 QList<QgsLabelPosition *> positionPointers;
3546 if ( mLabelSearchTree )
3548 mLabelSearchTree->labelsInRect( r, positionPointers );
3549 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
3550 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
Label below point, slightly right of center.
Render units (eg mm/pixels/map units)
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
void registerFeature(const QgsFeature &f, QgsRenderContext &context, QgsLabelFeature **labelFeature=nullptr, QgsGeometry obstacleGeometry=QgsGeometry())
Register a feature for labeling.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the labeling property definitions.
double xOffset
Horizontal offset of label.
The class is used as a container of context for various read/write operations on other objects...
Shape transparency (deprecated)
QColor strokeColor() const
Returns the color used for outlining the background shape.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
void setScale(int scale)
Sets the scaling used for the drop shadow (in percentage of original size).
double convertToMapUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
Shape size is determined by adding a buffer margin around text.
void setLineHeight(double height)
Sets the line height for text.
void setRadiiUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's radii.
A rectangle specified with double values.
void setStrokeWidth(double width)
Sets the width of the shape's stroke (stroke).
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
double rendererScale() const
Returns the renderer map scale.
Label on bottom-left of point.
RotationType
Methods for determining the rotation of the background shape.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
double maxCurvedCharAngleOut
Maximum angle between outside curved label characters (valid range -20.0 to -95.0) ...
double maximumScale
The maximum map scale (i.e.
QString leftDirectionSymbol
String to use for left direction arrows.
void setOpacity(double opacity)
Sets the text's opacity.
Positive integer values (including 0)
void setOffsetUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shadow's offset.
QgsUnitTypes::RenderUnit repeatDistanceUnit
Units for repeating labels for a single feature.
QSizeF radii() const
Returns the radii used for rounding the corners of shapes.
QSizeF size() const
Returns the size of the background shape.
double opacity() const
Returns the text's opacity.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Added in QGIS v2.4.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the shape's size.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QPointF offset() const
Returns the offset used for drawing the background shape.
QColor fillColor() const
Returns the color used for filing the background shape.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double...
static QString wordWrap(const QString &string, int length, bool useMaxLineLength=true, const QString &customDelimiter=QString())
Automatically wraps a string by inserting new line characters at appropriate locations in the string...
static QString encodeSize(QSizeF size)
Encodes a QSizeF to a string.
double angleOffset
Label rotation, in degrees clockwise.
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
bool formatNumbers
Set to true to format numeric label text as numbers (e.g.
A class to query the labeling structure at a given point (small wrapper around pal RTree class) ...
void readXml(QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
Draw shadow under buffer.
UpsideDownLabels upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
double obstacleFactor
Obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels, 1.0 less likely to be covered
Label on top-left of point.
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
void filterVertices(const std::function< bool(const QgsPoint &) > &filter)
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
ShadowPlacement
Placement positions for text shadow.
Place direction symbols on below label.
QgsTextShadowSettings & shadow()
Returns a reference to the text drop shadow settings.
double blurRadius() const
Returns the blur radius for the shadow.
static void drawLabelCandidateRect(pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform, QList< QgsLabelCandidate > *candidates=nullptr)
double getY(int i=0) const
Returns the down-left y coordinate.
double opacity() const
Returns the background shape's opacity.
void setStrokeColor(const QColor &color)
Sets the color used for outlining the background shape.
void setSize(double size)
Sets the size of the buffer.
A class to represent a 2D point.
double strokeWidth() const
Returns the width of the shape's stroke (stroke).
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the buffer size.
OperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
double offsetDistance() const
Returns the distance for offsetting the position of the shadow from the text.
bool obstacle
True if features for layer are obstacles to labels of other layers.
int decimals
Number of decimal places to show for numeric labels.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the buffer.
double repeatDistance
Distance for repeating labels for a single feature.
QVariant evaluate()
Evaluate the feature and return the result.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
static QPointF decodePoint(const QString &string)
Decodes a QSizeF from a string.
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
QuadrantPosition quadOffset
Sets the quadrant in which to offset labels from feature.
QgsUnitTypes::RenderUnit offsetUnits
Units for offsets of label.
void setOffsetUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's offset.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
Shadow transparency (deprecated)
QColor color() const
Returns the color that text will be rendered in.
double yOffset
Vertical offset of label.
Class that adds extra information to QgsLabelFeature for text labels.
Curve polygon geometry type.
QString evalErrorString() const
Returns evaluation error.
void setBlurRadius(double blurRadius)
Sets the blur radius for the shadow.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
void setDefinedFont(const QFont &f)
Sets font to be used for rendering.
void setOpacity(double opacity)
Sets the shadow's opacity.
X-coordinate data defined label position.
Min scale (deprecated, for old project compatibility only)
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
Label on top of point, slightly right of center.
bool addDirectionSymbol
If true, '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) will be ...
A geometry is the spatial representation of a feature.
bool drawLabels
Whether to draw labels for this layer.
QgsGeometry buffer(double distance, int segments) const
Returns a buffer region around this geometry having the given width and with a specified number of se...
void setBackground(const QgsTextBackgroundSettings &backgroundSettings)
Sets the text's background settings.q.
bool mergeLines
True if connected line features with identical label text should be merged prior to generating label ...
Color with alpha channel.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the background shape.
QgsMapUnitScale repeatDistanceMapUnitScale
Map unit scale for repeating labels for a single feature.
MultiLineAlign multilineAlign
Horizontal alignment of multi-line labels.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
FeaturePart * getFeaturePart()
Returns the feature corresponding to this labelposition.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Positive double value (including 0)
Container for settings relating to a text background object.
Percentage of another measurement (e.g., canvas size, feature size)
static int sizeToPixel(double size, const QgsRenderContext &c, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale())
Calculates pixel size (considering output size should be in pixel or map units, scale factors and opt...
void setBlurRadiusUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shadow's blur radius.
QVector< PredefinedPointPosition > predefinedPositionOrder
Ordered list of predefined label positions for points.
SimplifyAlgorithm
Types of simplification algorithms that can be used.
int autoWrapLength
If non-zero, indicates that label text should be automatically wrapped to (ideally) the specified num...
QString parserErrorString() const
Returns parser error.
double maxCurvedCharAngleIn
Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
QgsCoordinateTransform ct
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
static QString encodePoint(QPointF point)
Encodes a QPointF to a string.
bool reverseDirectionSymbol
True if direction symbols should be reversed.
Rotation (value between 0-360 degrees)
double maxScale
The maximum scale, or 0.0 if unset.
bool isGeosValid() const
Checks validity of the geometry using GEOS.
ShapeType type() const
Returns the type of background shape (e.g., square, ellipse, SVG).
void setOffset(QPointF offset)
Sets the offset used for drawing the background shape.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
double zIndex
Z-Index of label, where labels with a higher z-index are rendered on top of labels with a lower z-ind...
double mapRotation() const
Returns current map rotation in degrees.
void setHasFixedPosition(bool enabled)
Sets whether the label should use a fixed position instead of being automatically placed...
QgsStringReplacementCollection substitutions
Substitution collection for automatic text substitution with labels.
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
static QString encodeColor(const QColor &color)
static bool staticWillUseLayer(QgsVectorLayer *layer)
called to find out whether the layer is used for labeling
void writeXml(QDomElement &elem, QDomDocument &doc) const
Writes the collection state to an XML element.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the property with the specified key from within the collection...
Place direction symbols on left/right of label.
Perform transforms between map coordinates and device coordinates.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the background shape.
Shape rotation is a fixed angle.
Property
Data definable properties.
double cost() const
Returns the candidate label position's geographical cost.
No simplification can be applied.
ObstacleType obstacleType
Controls how features act as obstacles for labels.
QPointF toQPointF() const
Converts a point to a QPointF.
bool displayAll
If true, all features will be labelled even when overlaps occur.
QColor color() const
Returns the color of the drop shadow.
void setIsObstacle(bool enabled)
Sets whether the feature will act as an obstacle for labels.
void setOffsetDistance(double distance)
Sets the distance for offsetting the position of the shadow from the text.
static QString capitalize(const QString &string, Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
Offset distance applies from point geometry.
QList< QgsLabelPosition > labelsAtPosition(const QgsPointXY &p) const
Returns infos about labels at a given (map) position.
#define QgsDebugMsgLevel(str, level)
double tolerance() const
Gets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
int fontMaxPixelSize
Maximum pixel size for showing rendered map unit labels (1 - 10000).
static bool fontFamilyOnSystem(const QString &family)
Check whether font family is on system in a quick manner, which does not compare [foundry].
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
Maximum map scale (ie most "zoomed in")
The geometries can be fully simplified by its BoundingBox.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the drop shadow.
double width() const
Returns the width of the rectangle.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context)
Write settings into a DOM element.
void setColor(const QColor &color)
Sets the color for the drop shadow.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setDataDefinedValues(const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &values)
Sets data-defined values.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
void setEnabled(bool enabled)
Sets whether the text shadow will be drawn.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
Horizontal alignment for data defined label position (Left, Center, Right)
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
LabelPosition * getNextPart() const
const QgsMapToPixel * xform
Property requires a numeric value.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void calculateInfo(bool curvedLabeling, QFontMetricsF *fm, const QgsMapToPixel *xform, double fontScale, double maxinangle, double maxoutangle)
calculate data for info(). setDefinedFont() must have been called already.
QString svgFile() const
Returns the absolute path to the background SVG file, if set.
Qt::PenJoinStyle joinStyle() const
Returns the join style used for drawing the background shape.
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
Upside-down labels (90 <= angle < 270) are shown upright.
SizeType
Methods for determining the background shape size.
double opacity() const
Returns the buffer opacity.
OffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes...
static QPainter::CompositionMode decodeBlendMode(const QString &s)
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
void setSize(QSizeF size)
Sets the size of the background shape.
void clear() override
Removes all properties from the collection.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
double mapUnitsPerPixel() const
Returns current map units per pixel.
A store for object properties.
void setRadii(QSizeF radii)
Sets the radii used for rounding the corners of shapes.
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
Implementation of GeometrySimplifier using the "MapToPixel" algorithm.
Point geometry type, with support for z-dimension and m-values.
Double value (including negative values)
Minimum map scale (ie most "zoomed out")
Convert just the first letter of each word to uppercase, leave the rest untouched.
double length() const
Returns the length of geometry using GEOS.
Convert all characters to uppercase.
void setSizeType(SizeType type)
Sets the method used to determine the size of the background shape (e.g., fixed size or buffer around...
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc...
Definition for a property.
QList< QgsLabelPosition > labelsWithinRect(const QgsRectangle &r) const
Returns infos about labels within a given (map) rectangle.
Capitalization
Capitalization options.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
int maxNumLabels
The maximum number of labels which should be drawn for this layer.
void setType(ShapeType type)
Sets the type of background shape to draw (e.g., square, ellipse, SVG).
Place direction symbols on above label.
Draw shadow below all text components.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsExpressionContext & expressionContext()
Gets the expression context.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
Label rotation (deprecated, for old project compatibility only)
static QSizeF decodeSize(const QString &string)
Decodes a QSizeF from a string.
double rotation() const
Returns the rotation for the background shape, in degrees clockwise.
bool plusSign
Whether '+' signs should be prepended to positive numeric labels.
double lineHeight() const
Returns the line height for text.
void setEnabled(bool enabled)
Sets whether the text background will be drawn.
unsigned int placementFlags
int offsetAngle() const
Returns the angle for offsetting the position of the shadow from the text.
void calculateLabelSize(const QFontMetricsF *fm, const QString &text, double &labelX, double &labelY, const QgsFeature *f=nullptr, QgsRenderContext *context=nullptr)
Calculates the space required to render the provided text in map units.
ShapeType
Background shape types.
QString wrapChar
Wrapping character string.
QgsPalLayerSettings & operator=(const QgsPalLayerSettings &s)
copy operator - only copies the permanent members
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean...
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Placement
Placement modes which determine how label candidates are generated for a feature. ...
static QString encodePredefinedPositionOrder(const QVector< QgsPalLayerSettings::PredefinedPointPosition > &positions)
Encodes an ordered list of predefined point label positions to a string.
QString rightDirectionSymbol
String to use for right direction arrows.
bool preserveRotation
True if label rotation should be preserved during label pin/unpin operations.
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a string...
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
QgsGeometry simplify(double tolerance) const
Returns a simplified version of this geometry using a specified tolerance value.
QgsExpression * getLabelExpression()
Returns the QgsExpression for this label settings.
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point...
This class contains information how to simplify geometries fetched from a vector layer.
Contains information about the context of a rendering operation.
Shape rotation is offset from text rotation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
bool centroidWhole
True if feature centroid should be calculated from the whole feature, or false if only the visible pa...
bool scaleVisibility
Set to true to limit label visibility to a range of scales.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the size.
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
const QgsMapToPixel & mapToPixel() const
static geos::unique_ptr asGeos(const QgsGeometry &geometry, double precision=0)
Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destr...
const QgsFeature * mCurFeat
double getAlpha() const
Returns the angle to rotate text (in rad).
Property requires a string value.
bool enabled() const
Returns whether the shadow is enabled.
Mixed case, ie no change.
QgsMapUnitScale distMapUnitScale
Map unit scale for label feature distance.
bool fitInPolygonOnly
True if only labels which completely fit within a polygon are allowed.
Container for settings relating to a text shadow.
QColor color() const
Returns the color of the buffer.
bool conflictsWithObstacle() const
Returns whether the position is marked as conflicting with an obstacle feature.
double getX(int i=0) const
Returns the down-left x coordinate.
double size() const
Returns the size of the buffer.
Container for settings relating to a text buffer.
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported...
void setFillColor(const QColor &color)
Sets the color used for filing the background shape.
static bool updateFontViaStyle(QFont &f, const QString &fontstyle, bool fallback=false)
Updates font with named style and retain all font properties.
OffsetType offsetType
Offset type for layer (only applies in certain placement modes)
double dist
Distance from feature to the label.
double size() const
Returns the size for rendered text.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
bool useSubstitutions
True if substitutions should be applied.
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's stroke width.
bool enabled() const
Returns whether the background is enabled.
static QStringList splitToGraphemes(const QString &text)
Splits a text string to a list of graphemes, which are the smallest allowable character divisions in ...
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
LabelPosition is a candidate feature label position.
bool enabled() const
Returns whether the buffer is enabled.
int scale() const
Returns the scaling used for the drop shadow (in percentage of original size).
Shape rotation is synced with text rotation.
void setShadowPlacement(QgsTextShadowSettings::ShadowPlacement placement)
Sets the placement for the drop shadow.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the text.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
bool limitNumLabels
True if the number of labels drawn should be limited.
static bool geometryRequiresPreparation(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry())
Checks whether a geometry requires preparation before registration with PAL.
Draw shadow under background shape.
bool isExpression
True if this label is made from a expression string, e.g., FieldName || 'mm'.
Convert all characters to lowercase.
void setShadow(const QgsTextShadowSettings &shadowSettings)
Sets the text's drop shadow settings.
static QgsGeometry prepareGeometry(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry())
Prepares a geometry for registration with PAL.
QgsWkbTypes::GeometryType type
void readXml(const QDomElement &elem)
Reads the collection state from an XML element.
Custom exception class for Coordinate Reference System related exceptions.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
static QVector< QgsPalLayerSettings::PredefinedPointPosition > decodePredefinedPositionOrder(const QString &positionString)
Decodes a string to an ordered list of predefined point label positions.
QString process(const QString &input) const
Processes a given input string, applying any valid replacements which should be made using QgsStringR...
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
QgsPointXY center() const
Returns the center point of the rectangle.
double area() const
Returns the area of the geometry using GEOS.
Y-coordinate data defined label position.
Container for all settings relating to text rendering.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the buffer.
bool centroidInside
True if centroid positioned labels must be placed inside their corresponding feature polygon...
Max scale (deprecated, for old project compatibility only)
bool contains(const QgsPointXY *p) const
Tests for containment of a point (uses GEOS)
void setSvgFile(const QString &file)
Sets the path to the background SVG file.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Represents a vector layer which manages a vector based data sets.
double minScale
The minimum scale, or 0.0 if unset.
void setOpacity(double opacity)
Sets the buffer opacity.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
Square - buffered sizes only.
QString updateDataDefinedString(const QString &value)
int valueAsInt(int key, const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an integer...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
double minFeatureSize
Minimum feature size (in millimeters) for a feature to be labelled.
Vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top) ...
QString namedStyle() const
Returns the named style for the font used for rendering text (e.g., "bold").
QFont font() const
Returns the font used for rendering text.
void setRotationType(RotationType type)
Sets the method used for rotating the background shape.
int fontMinPixelSize
Minimum pixel size for showing rendered map unit labels (1 - 1000).
void setColor(const QColor &color)
Sets the color for the buffer.
int priority
Label priority.
bool labelPerPart
True if every part of a multi-part feature should be labeled.
QgsUnitTypes::RenderUnit distUnits
Units the distance from feature to the label.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
bool useMaxLineLengthForAutoWrap
If true, indicates that when auto wrapping label text the autoWrapLength length indicates the maximum...
double opacity() const
Returns the shadow's opacity.
QgsMapUnitScale labelOffsetMapUnitScale
Map unit scale for label offset.
static QStringList splitToLines(const QString &text, const QString &wrapCharacter, int autoWrapLength=0, bool useMaxLineLengthWhenAutoWrapping=true)
Splits a text string to a list of separate lines, using a specified wrap character (wrapCharacter)...
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
2D size (width/height different)
The QgsMargins class defines the four margins of a rectangle.
void setOpacity(double opacity)
Sets the background shape's opacity.
RenderUnit
Rendering size units.
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
static QColor decodeColor(const QString &str)
Buffer transparency (deprecated)
double height() const
Returns the height of the rectangle.
Text transparency (deprecated)
double minimumScale
The minimum map scale (i.e.
QString fieldName
Name of field (or an expression) to use for label text.
bool fontLimitPixelSize
True if label sizes should be limited by pixel size.
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels...
DirectionSymbols placeDirectionSymbol
Placement option for direction symbols.
void setOffsetAngle(int angle)
Sets the angle for offsetting the position of the shadow from the text.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
Color with no alpha channel.
void setRotation(double rotation)
Sets the rotation for the background shape, in degrees clockwise.