34 #include <QApplication> 37 #include <QFontMetrics> 63 #include <QMessageBox> 78 const QVector< QgsPalLayerSettings::PredefinedPointPosition > QgsPalLayerSettings::DEFAULT_PLACEMENT_ORDER
97 void QgsPalLayerSettings::initPropertyDefinitions()
99 if ( !sPropertyDefinitions.isEmpty() )
102 const QString origin = QStringLiteral(
"labeling" );
114 "e.g. Helvetica or Helvetica [Cronyx]" ), origin )
118 "e.g. Bold Condensed or Light Italic" ), origin )
150 "<b>Ellipse</b>|<b>Circle</b>|<b>SVG</b>]" ), origin )
174 "<b>Buffer</b>|<b>Background</b>]" ), origin )
190 "<b>3</b>=Left|<b>4</b>=Over|<b>5</b>=Right|<br>" 191 "<b>6</b>=Below Left|<b>7</b>=Below|<b>8</b>=Below Right]" ), origin )
206 + QStringLiteral(
"[<b>TL</b>=Top left|<b>TSL</b>=Top, slightly left|<b>T</b>=Top middle|<br>" 207 "<b>TSR</b>=Top, slightly right|<b>TR</b>=Top right|<br>" 208 "<b>L</b>=Left|<b>R</b>=Right|<br>" 209 "<b>BL</b>=Bottom left|<b>BSL</b>=Bottom, slightly left|<b>B</b>=Bottom middle|<br>" 210 "<b>BSR</b>=Bottom, slightly right|<b>BR</b>=Bottom right]" ), origin )
214 + QStringLiteral(
"[<b>OL</b>=On line|<b>AL</b>=Above line|<b>BL</b>=Below line|<br>" 215 "<b>LO</b>=Respect line orientation]" ), origin )
222 "<b>Half</b>|<b>Cap</b>|<b>Top</b>]" ), origin )
243 initPropertyDefinitions();
246 isExpression =
false;
249 previewBkgrdColor = Qt::white;
250 useSubstitutions =
false;
253 multilineAlign = MultiFollowPlacement;
254 addDirectionSymbol =
false;
255 leftDirectionSymbol = QStringLiteral(
"<" );
256 rightDirectionSymbol = QStringLiteral(
">" );
257 reverseDirectionSymbol =
false;
258 placeDirectionSymbol = SymbolLeftRight;
259 formatNumbers =
false;
264 placement = AroundPoint;
265 placementFlags = AboveLine | MapOrientation;
266 centroidWhole =
false;
267 centroidInside =
false;
268 predefinedPositionOrder = DEFAULT_PLACEMENT_ORDER;
269 fitInPolygonOnly =
false;
270 quadOffset = QuadrantOver;
276 offsetType = FromPoint;
278 preserveRotation =
true;
279 maxCurvedCharAngleIn = 25.0;
280 maxCurvedCharAngleOut = -25.0;
286 scaleVisibility =
false;
289 fontLimitPixelSize =
false;
290 fontMinPixelSize = 0;
291 fontMaxPixelSize = 10000;
293 upsidedownLabels = Upright;
295 labelPerPart =
false;
297 minFeatureSize = 0.0;
298 limitNumLabels =
false;
301 obstacleFactor = 1.0;
302 obstacleType = PolygonInterior;
308 , mDataDefinedProperties( s.mDataDefinedProperties )
389 mDataDefinedProperties = s.mDataDefinedProperties;
405 initPropertyDefinitions();
406 return sPropertyDefinitions;
418 static Qt::PenJoinStyle _decodePenJoinStyle(
const QString &str )
420 if ( str.compare( QLatin1String(
"Miter" ), Qt::CaseInsensitive ) == 0 )
return Qt::MiterJoin;
421 if ( str.compare( QLatin1String(
"Round" ), Qt::CaseInsensitive ) == 0 )
return Qt::RoundJoin;
422 return Qt::BevelJoin;
428 QString newValue = value;
429 if ( !value.isEmpty() && !value.contains( QLatin1String(
"~~" ) ) )
432 values << QStringLiteral(
"1" );
433 values << QStringLiteral(
"0" );
436 newValue = values.join( QStringLiteral(
"~~" ) );
444 QString newPropertyName =
"labeling/dataDefined/" + sPropertyDefinitions.value( p ).name();
445 QVariant newPropertyField = layer->
customProperty( newPropertyName, QVariant() );
447 if ( !newPropertyField.isValid() )
450 QString ddString = newPropertyField.toString();
452 if ( !ddString.isEmpty() && ddString != QLatin1String(
"0~~0~~~~" ) )
456 QStringList ddv = newStyleString.split( QStringLiteral(
"~~" ) );
458 bool active = ddv.at( 0 ).toInt();
459 if ( ddv.at( 1 ).toInt() )
475 void QgsPalLayerSettings::readOldDataDefinedPropertyMap(
QgsVectorLayer *layer, QDomElement *parentElem )
477 if ( !layer && !parentElem )
482 QgsPropertiesDefinition::const_iterator i = sPropertyDefinitions.constBegin();
483 for ( ; i != sPropertyDefinitions.constEnd(); ++i )
488 readOldDataDefinedProperty( layer, static_cast< Property >( i.key() ) );
490 else if ( parentElem )
493 QDomElement e = parentElem->firstChildElement( i.value().name() );
496 bool active = e.attribute( QStringLiteral(
"active" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
497 bool isExpression = e.attribute( QStringLiteral(
"useExpr" ) ).compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
511 void QgsPalLayerSettings::readFromLayerCustomProperties(
QgsVectorLayer *layer )
513 if ( layer->
customProperty( QStringLiteral(
"labeling" ) ).toString() != QLatin1String(
"pal" ) )
536 QDomDocument doc( QStringLiteral(
"substitutions" ) );
537 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/substitutions" ) ).toString() );
538 QDomElement replacementElem = doc.firstChildElement( QStringLiteral(
"substitutions" ) );
568 if ( layer->
customProperty( QStringLiteral(
"labeling/distMapUnitScale" ) ).toString().isEmpty() )
571 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMinScale" ), 0.0 ).toDouble();
573 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/distMapUnitMaxScale" ), 0.0 ).toDouble();
584 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetInMapUnits" ), QVariant(
true ) ).toBool() )
589 if ( layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitScale" ) ).toString().isEmpty() )
592 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMinScale" ), 0.0 ).toDouble();
594 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/labelOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
602 QVariant tempAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant() );
603 if ( tempAngle.isValid() )
605 double oldAngle = layer->
customProperty( QStringLiteral(
"labeling/angleOffset" ), QVariant( 0.0 ) ).toDouble();
618 switch ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceUnit" ), QVariant( 1 ) ).toUInt() )
633 if ( layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitScale" ) ).toString().isEmpty() )
636 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMinScale" ), 0.0 ).toDouble();
638 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/repeatDistanceMapUnitMaxScale" ), 0.0 ).toDouble();
647 double scalemn = layer->
customProperty( QStringLiteral(
"labeling/scaleMin" ), QVariant( 0 ) ).toDouble();
648 double scalemx = layer->
customProperty( QStringLiteral(
"labeling/scaleMax" ), QVariant( 0 ) ).toDouble();
651 QVariant scalevis = layer->
customProperty( QStringLiteral(
"labeling/scaleVisibility" ), QVariant() );
652 if ( scalevis.isValid() )
658 else if ( scalemn > 0 || scalemx > 0 )
685 zIndex = layer->
customProperty( QStringLiteral(
"labeling/zIndex" ), QVariant( 0.0 ) ).toDouble();
687 mDataDefinedProperties.
clear();
688 if ( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).isValid() )
690 QDomDocument doc( QStringLiteral(
"dd" ) );
691 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/ddProperties" ) ).toString() );
692 QDomElement elem = doc.firstChildElement( QStringLiteral(
"properties" ) );
693 mDataDefinedProperties.
readXml( elem, sPropertyDefinitions );
698 readOldDataDefinedPropertyMap( layer,
nullptr );
742 QDomElement textStyleElem = elem.firstChildElement( QStringLiteral(
"text-style" ) );
743 fieldName = textStyleElem.attribute( QStringLiteral(
"fieldName" ) );
744 isExpression = textStyleElem.attribute( QStringLiteral(
"isExpression" ) ).toInt();
746 mFormat.
readXml( elem, context );
747 previewBkgrdColor = QColor( textStyleElem.attribute( QStringLiteral(
"previewBkgrdColor" ), QStringLiteral(
"#ffffff" ) ) );
749 useSubstitutions = textStyleElem.attribute( QStringLiteral(
"useSubstitutions" ) ).toInt();
752 QDomElement textFormatElem = elem.firstChildElement( QStringLiteral(
"text-format" ) );
753 wrapChar = textFormatElem.attribute( QStringLiteral(
"wrapChar" ) );
754 autoWrapLength = textFormatElem.attribute( QStringLiteral(
"autoWrapLength" ), QStringLiteral(
"0" ) ).toInt();
755 useMaxLineLengthForAutoWrap = textFormatElem.attribute( QStringLiteral(
"useMaxLineLengthForAutoWrap" ), QStringLiteral(
"1" ) ).toInt();
757 addDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"addDirectionSymbol" ) ).toInt();
758 leftDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"leftDirectionSymbol" ), QStringLiteral(
"<" ) );
759 rightDirectionSymbol = textFormatElem.attribute( QStringLiteral(
"rightDirectionSymbol" ), QStringLiteral(
">" ) );
762 formatNumbers = textFormatElem.attribute( QStringLiteral(
"formatNumbers" ) ).toInt();
763 decimals = textFormatElem.attribute( QStringLiteral(
"decimals" ) ).toInt();
764 plusSign = textFormatElem.attribute( QStringLiteral(
"plussign" ) ).toInt();
767 QDomElement placementElem = elem.firstChildElement( QStringLiteral(
"placement" ) );
768 placement =
static_cast< Placement >( placementElem.attribute( QStringLiteral(
"placement" ) ).toInt() );
769 placementFlags = placementElem.attribute( QStringLiteral(
"placementFlags" ) ).toUInt();
770 centroidWhole = placementElem.attribute( QStringLiteral(
"centroidWhole" ), QStringLiteral(
"0" ) ).toInt();
771 centroidInside = placementElem.attribute( QStringLiteral(
"centroidInside" ), QStringLiteral(
"0" ) ).toInt();
775 fitInPolygonOnly = placementElem.attribute( QStringLiteral(
"fitInPolygonOnly" ), QStringLiteral(
"0" ) ).toInt();
776 dist = placementElem.attribute( QStringLiteral(
"dist" ) ).toDouble();
777 if ( !placementElem.hasAttribute( QStringLiteral(
"distUnits" ) ) )
779 if ( placementElem.attribute( QStringLiteral(
"distInMapUnits" ) ).toInt() )
788 if ( !placementElem.hasAttribute( QStringLiteral(
"distMapUnitScale" ) ) )
791 double oldMin = placementElem.attribute( QStringLiteral(
"distMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
793 double oldMax = placementElem.attribute( QStringLiteral(
"distMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
802 xOffset = placementElem.attribute( QStringLiteral(
"xOffset" ), QStringLiteral(
"0" ) ).toDouble();
803 yOffset = placementElem.attribute( QStringLiteral(
"yOffset" ), QStringLiteral(
"0" ) ).toDouble();
804 if ( !placementElem.hasAttribute( QStringLiteral(
"offsetUnits" ) ) )
812 if ( !placementElem.hasAttribute( QStringLiteral(
"labelOffsetMapUnitScale" ) ) )
815 double oldMin = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
817 double oldMax = placementElem.attribute( QStringLiteral(
"labelOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
825 if ( placementElem.hasAttribute( QStringLiteral(
"angleOffset" ) ) )
827 double oldAngle = placementElem.attribute( QStringLiteral(
"angleOffset" ), QStringLiteral(
"0" ) ).toDouble();
832 angleOffset = placementElem.attribute( QStringLiteral(
"rotationAngle" ), QStringLiteral(
"0" ) ).toDouble();
835 preserveRotation = placementElem.attribute( QStringLiteral(
"preserveRotation" ), QStringLiteral(
"1" ) ).toInt();
836 maxCurvedCharAngleIn = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleIn" ), QStringLiteral(
"25" ) ).toDouble();
837 maxCurvedCharAngleOut = placementElem.attribute( QStringLiteral(
"maxCurvedCharAngleOut" ), QStringLiteral(
"-25" ) ).toDouble();
838 priority = placementElem.attribute( QStringLiteral(
"priority" ) ).toInt();
839 repeatDistance = placementElem.attribute( QStringLiteral(
"repeatDistance" ), QStringLiteral(
"0" ) ).toDouble();
840 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceUnits" ) ) )
843 switch ( placementElem.attribute( QStringLiteral(
"repeatDistanceUnit" ), QString::number( 1 ) ).toUInt() )
863 if ( !placementElem.hasAttribute( QStringLiteral(
"repeatDistanceMapUnitScale" ) ) )
866 double oldMin = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
868 double oldMax = placementElem.attribute( QStringLiteral(
"repeatDistanceMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
877 QDomElement renderingElem = elem.firstChildElement( QStringLiteral(
"rendering" ) );
879 drawLabels = renderingElem.attribute( QStringLiteral(
"drawLabels" ), QStringLiteral(
"1" ) ).toInt();
881 maximumScale = renderingElem.attribute( QStringLiteral(
"scaleMin" ), QStringLiteral(
"0" ) ).toDouble();
882 minimumScale = renderingElem.attribute( QStringLiteral(
"scaleMax" ), QStringLiteral(
"0" ) ).toDouble();
883 scaleVisibility = renderingElem.attribute( QStringLiteral(
"scaleVisibility" ) ).toInt();
885 fontLimitPixelSize = renderingElem.attribute( QStringLiteral(
"fontLimitPixelSize" ), QStringLiteral(
"0" ) ).toInt();
886 fontMinPixelSize = renderingElem.attribute( QStringLiteral(
"fontMinPixelSize" ), QStringLiteral(
"0" ) ).toInt();
887 fontMaxPixelSize = renderingElem.attribute( QStringLiteral(
"fontMaxPixelSize" ), QStringLiteral(
"10000" ) ).toInt();
888 displayAll = renderingElem.attribute( QStringLiteral(
"displayAll" ), QStringLiteral(
"0" ) ).toInt();
891 labelPerPart = renderingElem.attribute( QStringLiteral(
"labelPerPart" ) ).toInt();
892 mergeLines = renderingElem.attribute( QStringLiteral(
"mergeLines" ) ).toInt();
893 minFeatureSize = renderingElem.attribute( QStringLiteral(
"minFeatureSize" ) ).toDouble();
894 limitNumLabels = renderingElem.attribute( QStringLiteral(
"limitNumLabels" ), QStringLiteral(
"0" ) ).toInt();
895 maxNumLabels = renderingElem.attribute( QStringLiteral(
"maxNumLabels" ), QStringLiteral(
"2000" ) ).toInt();
896 obstacle = renderingElem.attribute( QStringLiteral(
"obstacle" ), QStringLiteral(
"1" ) ).toInt();
897 obstacleFactor = renderingElem.attribute( QStringLiteral(
"obstacleFactor" ), QStringLiteral(
"1" ) ).toDouble();
899 zIndex = renderingElem.attribute( QStringLiteral(
"zIndex" ), QStringLiteral(
"0.0" ) ).toDouble();
901 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"dd_properties" ) );
902 if ( !ddElem.isNull() )
904 mDataDefinedProperties.
readXml( ddElem, sPropertyDefinitions );
909 mDataDefinedProperties.
clear();
910 QDomElement ddElem = elem.firstChildElement( QStringLiteral(
"data-defined" ) );
911 readOldDataDefinedPropertyMap(
nullptr, &ddElem );
956 QDomElement textStyleElem = mFormat.
writeXml( doc, context );
959 textStyleElem.setAttribute( QStringLiteral(
"fieldName" ),
fieldName );
960 textStyleElem.setAttribute( QStringLiteral(
"isExpression" ),
isExpression );
961 textStyleElem.setAttribute( QStringLiteral(
"previewBkgrdColor" ),
previewBkgrdColor.name() );
962 QDomElement replacementElem = doc.createElement( QStringLiteral(
"substitutions" ) );
964 textStyleElem.appendChild( replacementElem );
965 textStyleElem.setAttribute( QStringLiteral(
"useSubstitutions" ),
useSubstitutions );
968 QDomElement textFormatElem = doc.createElement( QStringLiteral(
"text-format" ) );
969 textFormatElem.setAttribute( QStringLiteral(
"wrapChar" ),
wrapChar );
970 textFormatElem.setAttribute( QStringLiteral(
"autoWrapLength" ),
autoWrapLength );
972 textFormatElem.setAttribute( QStringLiteral(
"multilineAlign" ), static_cast< unsigned int >(
multilineAlign ) );
973 textFormatElem.setAttribute( QStringLiteral(
"addDirectionSymbol" ),
addDirectionSymbol );
974 textFormatElem.setAttribute( QStringLiteral(
"leftDirectionSymbol" ),
leftDirectionSymbol );
977 textFormatElem.setAttribute( QStringLiteral(
"placeDirectionSymbol" ), static_cast< unsigned int >(
placeDirectionSymbol ) );
978 textFormatElem.setAttribute( QStringLiteral(
"formatNumbers" ),
formatNumbers );
979 textFormatElem.setAttribute( QStringLiteral(
"decimals" ),
decimals );
980 textFormatElem.setAttribute( QStringLiteral(
"plussign" ),
plusSign );
983 QDomElement placementElem = doc.createElement( QStringLiteral(
"placement" ) );
984 placementElem.setAttribute( QStringLiteral(
"placement" ),
placement );
985 placementElem.setAttribute( QStringLiteral(
"placementFlags" ), static_cast< unsigned int >(
placementFlags ) );
986 placementElem.setAttribute( QStringLiteral(
"centroidWhole" ),
centroidWhole );
987 placementElem.setAttribute( QStringLiteral(
"centroidInside" ),
centroidInside );
989 placementElem.setAttribute( QStringLiteral(
"fitInPolygonOnly" ),
fitInPolygonOnly );
990 placementElem.setAttribute( QStringLiteral(
"dist" ),
dist );
993 placementElem.setAttribute( QStringLiteral(
"offsetType" ), static_cast< unsigned int >(
offsetType ) );
994 placementElem.setAttribute( QStringLiteral(
"quadOffset" ), static_cast< unsigned int >(
quadOffset ) );
995 placementElem.setAttribute( QStringLiteral(
"xOffset" ),
xOffset );
996 placementElem.setAttribute( QStringLiteral(
"yOffset" ),
yOffset );
999 placementElem.setAttribute( QStringLiteral(
"rotationAngle" ),
angleOffset );
1000 placementElem.setAttribute( QStringLiteral(
"preserveRotation" ),
preserveRotation );
1003 placementElem.setAttribute( QStringLiteral(
"priority" ),
priority );
1004 placementElem.setAttribute( QStringLiteral(
"repeatDistance" ),
repeatDistance );
1009 QDomElement renderingElem = doc.createElement( QStringLiteral(
"rendering" ) );
1010 renderingElem.setAttribute( QStringLiteral(
"drawLabels" ),
drawLabels );
1011 renderingElem.setAttribute( QStringLiteral(
"scaleVisibility" ),
scaleVisibility );
1012 renderingElem.setAttribute( QStringLiteral(
"scaleMin" ),
maximumScale );
1013 renderingElem.setAttribute( QStringLiteral(
"scaleMax" ),
minimumScale );
1014 renderingElem.setAttribute( QStringLiteral(
"fontLimitPixelSize" ),
fontLimitPixelSize );
1015 renderingElem.setAttribute( QStringLiteral(
"fontMinPixelSize" ),
fontMinPixelSize );
1016 renderingElem.setAttribute( QStringLiteral(
"fontMaxPixelSize" ),
fontMaxPixelSize );
1017 renderingElem.setAttribute( QStringLiteral(
"displayAll" ),
displayAll );
1018 renderingElem.setAttribute( QStringLiteral(
"upsidedownLabels" ), static_cast< unsigned int >(
upsidedownLabels ) );
1020 renderingElem.setAttribute( QStringLiteral(
"labelPerPart" ),
labelPerPart );
1021 renderingElem.setAttribute( QStringLiteral(
"mergeLines" ),
mergeLines );
1022 renderingElem.setAttribute( QStringLiteral(
"minFeatureSize" ),
minFeatureSize );
1023 renderingElem.setAttribute( QStringLiteral(
"limitNumLabels" ),
limitNumLabels );
1024 renderingElem.setAttribute( QStringLiteral(
"maxNumLabels" ),
maxNumLabels );
1025 renderingElem.setAttribute( QStringLiteral(
"obstacle" ),
obstacle );
1026 renderingElem.setAttribute( QStringLiteral(
"obstacleFactor" ),
obstacleFactor );
1027 renderingElem.setAttribute( QStringLiteral(
"obstacleType" ), static_cast< unsigned int >(
obstacleType ) );
1028 renderingElem.setAttribute( QStringLiteral(
"zIndex" ),
zIndex );
1030 QDomElement ddElem = doc.createElement( QStringLiteral(
"dd_properties" ) );
1031 mDataDefinedProperties.
writeXml( ddElem, sPropertyDefinitions );
1033 QDomElement elem = doc.createElement( QStringLiteral(
"settings" ) );
1034 elem.appendChild( textStyleElem );
1035 elem.appendChild( textFormatElem );
1036 elem.appendChild( placementElem );
1037 elem.appendChild( renderingElem );
1038 elem.appendChild( ddElem );
1044 return QgsPalLabeling::checkMinimumSizeMM( ct, geom, minSize );
1055 std::unique_ptr< QgsRenderContext > scopedRc;
1060 scopedRc->expressionContext().setFeature( *f );
1143 if ( wrapchr.isEmpty() )
1145 wrapchr = QStringLiteral(
"\n" );
1150 && ( !leftDirSymb.isEmpty() || !rightDirSymb.isEmpty() ) )
1152 QString dirSym = leftDirSymb;
1154 if ( fm->width( rightDirSymb ) > fm->width( dirSym ) )
1155 dirSym = rightDirSymb;
1159 text.append( dirSym );
1163 text.prepend( dirSym + QStringLiteral(
"\n" ) );
1167 double w = 0.0, h = 0.0;
1169 int lines = multiLineSplit.size();
1171 double labelHeight = fm->ascent() + fm->descent();
1173 h += fm->height() +
static_cast< double >( ( lines - 1 ) * labelHeight * multilineH );
1175 for (
int i = 0; i < lines; ++i )
1177 double width = fm->width( multiLineSplit.at( i ) );
1186 labelX = std::fabs( ptSize.
x() -
ptZero.
x() );
1187 labelY = std::fabs( ptSize.
y() -
ptZero.
y() );
1198 Q_ASSERT( labelFeature );
1210 registerObstacleFeature( f, context, labelFeature, obstacleGeometry );
1218 dataDefinedValues.clear();
1230 if ( useScaleVisibility )
1239 maxScale = 1 / std::fabs( maxScale );
1254 minScale = 1 / std::fabs( minScale );
1263 QFont labelFont = mFormat.
font();
1269 if ( exprVal.isValid() )
1271 QString units = exprVal.toString();
1272 if ( !units.isEmpty() )
1284 if ( fontSize <= 0.0 )
1291 if ( fontPixelSize < 1 )
1295 labelFont.setPixelSize( fontPixelSize );
1307 if ( fontMinPixel > labelFont.pixelSize() || labelFont.pixelSize() > fontMaxPixel )
1319 labelFont.setCapitalization( QFont::MixedCase );
1320 parseTextStyle( labelFont, fontunits, context );
1321 parseTextFormatting( context );
1322 parseTextBuffer( context );
1323 parseShapeBackground( context );
1324 parseDropShadow( context );
1344 labelText = result.isNull() ? QString() : result.toString();
1349 labelText = v.isNull() ? QString() : v.toString();
1361 if ( mFormat.
font().capitalization() != QFont::MixedCase )
1367 if ( exprVal.isValid() )
1369 QString fcase = exprVal.toString().trimmed();
1370 QgsDebugMsgLevel( QStringLiteral(
"exprVal FontCase:%1" ).arg( fcase ), 4 );
1372 if ( !fcase.isEmpty() )
1374 if ( fcase.compare( QLatin1String(
"NoChange" ), Qt::CaseInsensitive ) == 0 )
1378 else if ( fcase.compare( QLatin1String(
"Upper" ), Qt::CaseInsensitive ) == 0 )
1382 else if ( fcase.compare( QLatin1String(
"Lower" ), Qt::CaseInsensitive ) == 0 )
1386 else if ( fcase.compare( QLatin1String(
"Capitalize" ), Qt::CaseInsensitive ) == 0 )
1399 if ( decimalPlaces <= 0 )
1405 QVariant textV( labelText );
1407 double d = textV.toDouble( &ok );
1410 QString numberFormat;
1411 if ( d > 0 && signPlus )
1413 numberFormat.append(
'+' );
1415 numberFormat.append(
"%1" );
1416 labelText = numberFormat.arg( d, 0,
'f', decimalPlaces );
1421 std::unique_ptr<QFontMetricsF> labelFontMetrics(
new QFontMetricsF( labelFont ) );
1422 double labelX, labelY;
1428 double maxcharanglein = 20.0;
1429 double maxcharangleout = -20.0;
1438 if ( exprVal.isValid() )
1440 QString ptstr = exprVal.toString().trimmed();
1441 QgsDebugMsgLevel( QStringLiteral(
"exprVal CurvedCharAngleInOut:%1" ).arg( ptstr ), 4 );
1443 if ( !ptstr.isEmpty() )
1446 maxcharanglein = qBound( 20.0, static_cast< double >( maxcharanglePt.x() ), 60.0 );
1447 maxcharangleout = qBound( 20.0, static_cast< double >( maxcharanglePt.y() ), 95.0 );
1451 maxcharangleout = -( std::fabs( maxcharangleout ) );
1457 if ( exprVal.isValid() )
1459 QString str = exprVal.toString().trimmed();
1460 QgsDebugMsgLevel( QStringLiteral(
"exprVal CentroidWhole:%1" ).arg( str ), 4 );
1462 if ( !str.isEmpty() )
1464 if ( str.compare( QLatin1String(
"Visible" ), Qt::CaseInsensitive ) == 0 )
1466 wholeCentroid =
false;
1468 else if ( str.compare( QLatin1String(
"Whole" ), Qt::CaseInsensitive ) == 0 )
1470 wholeCentroid =
true;
1483 std::unique_ptr<QgsGeometry> scopedClonedGeom;
1490 geom = simplifier.
simplify( geom );
1500 bool doClip =
false;
1501 if ( !centroidPoly || !wholeCentroid )
1511 permissibleZone = geom;
1547 if ( !geos_geom_clone )
1576 if ( isObstacle && !obstacleGeometry.
isNull() )
1583 bool dataDefinedPosition =
false;
1584 bool layerDefinedRotation =
false;
1585 bool dataDefinedRotation =
false;
1586 double xPos = 0.0, yPos = 0.0,
angle = 0.0;
1587 bool ddXPos =
false, ddYPos =
false;
1588 double quadOffsetX = 0.0, quadOffsetY = 0.0;
1589 double offsetX = 0.0, offsetY = 0.0;
1592 bool ddFixedQuad =
false;
1596 if ( exprVal.isValid() )
1599 int quadInt = exprVal.toInt( &ok );
1600 QgsDebugMsgLevel( QStringLiteral(
"exprVal OffsetQuad:%1" ).arg( quadInt ), 4 );
1601 if ( ok && 0 <= quadInt && quadInt <= 8 )
1653 if ( exprVal.isValid() )
1655 QString ptstr = exprVal.toString().trimmed();
1656 QgsDebugMsgLevel( QStringLiteral(
"exprVal OffsetXY:%1" ).arg( ptstr ), 4 );
1658 if ( !ptstr.isEmpty() )
1669 if ( exprVal.isValid() )
1671 QString units = exprVal.toString().trimmed();
1672 QgsDebugMsgLevel( QStringLiteral(
"exprVal OffsetUnits:%1" ).arg( units ), 4 );
1673 if ( !units.isEmpty() )
1679 offUnit = decodedUnits;
1694 layerDefinedRotation =
true;
1702 if ( exprVal.isValid() )
1705 double rotD = exprVal.toDouble( &ok );
1706 QgsDebugMsgLevel( QStringLiteral(
"exprVal Rotation:%1" ).arg( rotD ), 4 );
1709 dataDefinedRotation =
true;
1713 angle = ( 360 - rotD ) * M_PI / 180.0;
1718 if ( exprVal.isValid() )
1720 if ( !exprVal.isNull() )
1721 xPos = exprVal.toDouble( &ddXPos );
1722 QgsDebugMsgLevel( QStringLiteral(
"exprVal PositionX:%1" ).arg( xPos ), 4 );
1725 if ( exprVal.isValid() )
1728 if ( !exprVal.isNull() )
1729 yPos = exprVal.toDouble( &ddYPos );
1730 QgsDebugMsgLevel( QStringLiteral(
"exprVal PositionY:%1" ).arg( yPos ), 4 );
1732 if ( ddXPos && ddYPos )
1734 dataDefinedPosition =
true;
1736 if ( layerDefinedRotation && !dataDefinedRotation )
1747 if ( exprVal.isValid() )
1749 QString haliString = exprVal.toString();
1750 QgsDebugMsgLevel( QStringLiteral(
"exprVal Hali:%1" ).arg( haliString ), 4 );
1751 if ( haliString.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
1753 xdiff -= labelX / 2.0;
1755 else if ( haliString.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
1763 if ( exprVal.isValid() )
1765 QString valiString = exprVal.toString();
1766 QgsDebugMsgLevel( QStringLiteral(
"exprVal Vali:%1" ).arg( valiString ), 4 );
1768 if ( valiString.compare( QLatin1String(
"Bottom" ), Qt::CaseInsensitive ) != 0 )
1770 if ( valiString.compare( QLatin1String(
"Top" ), Qt::CaseInsensitive ) == 0 )
1776 double descentRatio = labelFontMetrics->descent() / labelFontMetrics->height();
1777 if ( valiString.compare( QLatin1String(
"Base" ), Qt::CaseInsensitive ) == 0 )
1779 ydiff -= labelY * descentRatio;
1783 double capHeightRatio = ( labelFontMetrics->boundingRect(
'H' ).height() + 1 + labelFontMetrics->descent() ) / labelFontMetrics->height();
1784 ydiff -= labelY * capHeightRatio;
1785 if ( valiString.compare( QLatin1String(
"Half" ), Qt::CaseInsensitive ) == 0 )
1787 ydiff += labelY * ( capHeightRatio - descentRatio ) / 2.0;
1794 if ( dataDefinedRotation )
1797 double xd = xdiff * std::cos(
angle ) - ydiff * std::sin(
angle );
1798 double yd = xdiff * std::sin(
angle ) + ydiff * std::cos(
angle );
1837 if ( exprVal.isValid() )
1839 QString units = exprVal.toString().trimmed();
1840 QgsDebugMsgLevel( QStringLiteral(
"exprVal RepeatDistanceUnits:%1" ).arg( units ), 4 );
1841 if ( !units.isEmpty() )
1847 repeatUnits = decodedUnits;
1866 ( *labelFeature )->setFixedPosition(
QgsPointXY( xPos, yPos ) );
1868 ( *labelFeature )->setHasFixedAngle( dataDefinedRotation || ( !dataDefinedPosition && !
qgsDoubleNear(
angle, 0.0 ) ) );
1869 ( *labelFeature )->setFixedAngle(
angle );
1870 ( *labelFeature )->setQuadOffset( QPointF( quadOffsetX, quadOffsetY ) );
1871 ( *labelFeature )->setPositionOffset(
QgsPointXY( offsetX, offsetY ) );
1872 ( *labelFeature )->setOffsetType(
offsetType );
1873 ( *labelFeature )->setAlwaysShow( alwaysShow );
1874 ( *labelFeature )->setRepeatDistance( repeatDist );
1875 ( *labelFeature )->setLabelText( labelText );
1876 ( *labelFeature )->setPermissibleZone( permissibleZone );
1877 if ( geosObstacleGeomClone )
1879 ( *labelFeature )->setObstacleGeometry( std::move( geosObstacleGeomClone ) );
1884 ( *labelFeature )->setSymbolSize( QSizeF( obstacleGeometry.
boundingBox().
width(),
1891 double topMargin = std::max( 0.25 * labelFontMetrics->ascent(), 0.0 );
1892 double bottomMargin = 1.0 + labelFontMetrics->descent();
1893 QgsMargins vm( 0.0, topMargin, 0.0, bottomMargin );
1895 ( *labelFeature )->setVisualMargin( vm );
1898 QgsDebugMsgLevel( QStringLiteral(
"PAL font stored definedFont: %1, Style: %2" ).arg( labelFont.toString(), labelFont.styleName() ), 4 );
1904 labelFontMetrics.get(),
xform, maxcharanglein, maxcharangleout );
1916 if ( exprVal.isValid() )
1918 QString units = exprVal.toString().trimmed();
1919 QgsDebugMsgLevel( QStringLiteral(
"exprVal DistanceUnits:%1" ).arg( units ), 4 );
1920 if ( !units.isEmpty() )
1926 distUnit = decodedUnits;
1936 distance = ( distance < 0 ? -1 : 1 ) * std::max( std::fabs( distance ), 1.0 );
1942 ( *labelFeature )->setDistLabel( d );
1947 ( *labelFeature )->setHasFixedQuadrant(
true );
1950 pal::LineArrangementFlags featureArrangementFlags =
static_cast< pal::LineArrangementFlags
>(
placementFlags );
1953 if ( !dataDefinedLineArrangement.isEmpty() )
1957 ( *labelFeature )->setArrangementFlags( featureArrangementFlags );
1962 ( *labelFeature )->setZIndex( z );
1967 if ( exprVal.isValid() )
1970 double priorityD = exprVal.toDouble( &ok );
1973 priorityD = qBound( 0.0, priorityD, 10.0 );
1974 priorityD = 1 - priorityD / 10.0;
1975 ( *labelFeature )->setPriority( priorityD );
1979 ( *labelFeature )->setIsObstacle( isObstacle );
1984 if ( exprVal.isValid() )
1987 double factorD = exprVal.toDouble( &ok );
1990 factorD = qBound( 0.0, factorD, 10.0 );
1991 factorD = factorD / 5.0 + 0.0001;
1992 featObstacleFactor = factorD;
1995 ( *labelFeature )->setObstacleFactor( featObstacleFactor );
1998 if ( positionOrder.isEmpty() )
1999 positionOrder = QgsPalLayerSettings::DEFAULT_PLACEMENT_ORDER;
2003 if ( !dataDefinedOrder.isEmpty() )
2007 ( *labelFeature )->setPredefinedPositionOrder( positionOrder );
2018 if ( !obstacleGeometry.
isNull() )
2020 geom = obstacleGeometry;
2034 std::unique_ptr<QgsGeometry> scopedClonedGeom;
2040 geom = simplifier.
simplify( geom );
2044 std::unique_ptr<QgsGeometry> scopedPreparedGeom;
2052 if ( !geos_geom_clone )
2056 *obstacleFeature =
new QgsLabelFeature( f.
id(), std::move( geos_geom_clone ), QSizeF( 0, 0 ) );
2061 bool QgsPalLayerSettings::dataDefinedValEval( DataDefinedValueType valType,
2065 if ( !mDataDefinedProperties.
isActive( p ) )
2069 exprVal = mDataDefinedProperties.
value( p, context );
2070 if ( exprVal.isValid() )
2076 bool bol = exprVal.toBool();
2077 dataDefinedValues.insert( p, QVariant( bol ) );
2083 int size = exprVal.toInt( &ok );
2087 dataDefinedValues.insert( p, QVariant( size ) );
2095 int size = exprVal.toInt( &ok );
2097 if ( ok && size > 0 )
2099 dataDefinedValues.insert( p, QVariant( size ) );
2107 double size = exprVal.toDouble( &ok );
2111 dataDefinedValues.insert( p, QVariant( size ) );
2119 double size = exprVal.toDouble( &ok );
2121 if ( ok && size > 0.0 )
2123 dataDefinedValues.insert( p, QVariant( size ) );
2131 double rot = exprVal.toDouble( &ok );
2134 if ( rot < -180.0 && rot >= -360 )
2138 if ( rot > 180.0 && rot <= 360 )
2142 if ( rot >= -180 && rot <= 180 )
2144 dataDefinedValues.insert( p, QVariant( rot ) );
2153 int size = exprVal.toDouble( &ok );
2154 if ( ok && size >= 0 && size <= 100 )
2156 dataDefinedValues.insert( p, QVariant( size ) );
2163 QString str = exprVal.toString();
2165 dataDefinedValues.insert( p, QVariant( str ) );
2170 QString unitstr = exprVal.toString().trimmed();
2172 if ( !unitstr.isEmpty() )
2181 QString colorstr = exprVal.toString().trimmed();
2184 if ( color.isValid() )
2186 dataDefinedValues.insert( p, QVariant( color ) );
2193 QString joinstr = exprVal.toString().trimmed();
2195 if ( !joinstr.isEmpty() )
2197 dataDefinedValues.insert( p, QVariant( static_cast< int >( _decodePenJoinStyle( joinstr ) ) ) );
2204 QString blendstr = exprVal.toString().trimmed();
2206 if ( !blendstr.isEmpty() )
2215 QString ptstr = exprVal.toString().trimmed();
2217 if ( !ptstr.isEmpty() )
2226 QString ptstr = exprVal.toString().trimmed();
2228 if ( !ptstr.isEmpty() )
2240 void QgsPalLayerSettings::parseTextStyle( QFont &labelFont,
2253 QString ddFontFamily;
2256 if ( exprVal.isValid() )
2258 QString family = exprVal.toString().trimmed();
2259 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font family:%1" ).arg( family ), 4 );
2261 if ( labelFont.family() != family )
2267 ddFontFamily = family;
2273 QString ddFontStyle;
2275 if ( exprVal.isValid() )
2277 QString fontstyle = exprVal.toString().trimmed();
2278 QgsDebugMsgLevel( QStringLiteral(
"exprVal Font style:%1" ).arg( fontstyle ), 4 );
2279 ddFontStyle = fontstyle;
2293 QFont appFont = QApplication::font();
2294 bool newFontBuilt =
false;
2295 if ( ddBold || ddItalic )
2298 newFont = QFont( !ddFontFamily.isEmpty() ? ddFontFamily : labelFont.family() );
2299 newFontBuilt =
true;
2300 newFont.setBold( ddBold );
2301 newFont.setItalic( ddItalic );
2303 else if ( !ddFontStyle.isEmpty()
2304 && ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2306 if ( !ddFontFamily.isEmpty() )
2309 QFont styledfont = mFontDB.font( ddFontFamily, ddFontStyle, appFont.pointSize() );
2310 if ( appFont != styledfont )
2312 newFont = styledfont;
2313 newFontBuilt =
true;
2320 else if ( !ddFontFamily.isEmpty() )
2322 if ( ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2325 QFont styledfont = mFontDB.font( ddFontFamily, mFormat.
namedStyle(), appFont.pointSize() );
2326 if ( appFont != styledfont )
2328 newFont = styledfont;
2329 newFontBuilt =
true;
2334 newFont = QFont( ddFontFamily );
2335 newFontBuilt =
true;
2343 newFont.setPixelSize( labelFont.pixelSize() );
2344 newFont.setUnderline( labelFont.underline() );
2345 newFont.setStrikeOut( labelFont.strikeOut() );
2346 newFont.setWordSpacing( labelFont.wordSpacing() );
2347 newFont.setLetterSpacing( QFont::AbsoluteSpacing, labelFont.letterSpacing() );
2349 labelFont = newFont;
2353 double wordspace = labelFont.wordSpacing();
2359 double letterspace = labelFont.letterSpacing();
2369 labelFont.setStrikeOut( strikeout );
2377 labelFont.setUnderline( underline );
2403 drawBuffer = exprVal.toBool();
2412 double bufrSize = buffer.
size();
2415 bufrSize = exprVal.toDouble();
2419 double bufferOpacity = buffer.
opacity() * 100;
2422 bufferOpacity = exprVal.toDouble();
2425 drawBuffer = ( drawBuffer && bufrSize > 0.0 && bufferOpacity > 0 );
2456 wrapchr = exprVal.toString();
2462 evalAutoWrapLength = exprVal.toInt();
2471 if ( exprVal.isValid() )
2473 QString str = exprVal.toString().trimmed();
2474 QgsDebugMsgLevel( QStringLiteral(
"exprVal MultiLineAlignment:%1" ).arg( str ), 4 );
2476 if ( !str.isEmpty() )
2481 if ( str.compare( QLatin1String(
"Center" ), Qt::CaseInsensitive ) == 0 )
2485 else if ( str.compare( QLatin1String(
"Right" ), Qt::CaseInsensitive ) == 0 )
2489 else if ( str.compare( QLatin1String(
"Follow" ), Qt::CaseInsensitive ) == 0 )
2501 drawDirSymb = exprVal.toBool();
2514 if ( exprVal.isValid() )
2516 QString str = exprVal.toString().trimmed();
2517 QgsDebugMsgLevel( QStringLiteral(
"exprVal DirSymbPlacement:%1" ).arg( str ), 4 );
2519 if ( !str.isEmpty() )
2524 if ( str.compare( QLatin1String(
"Above" ), Qt::CaseInsensitive ) == 0 )
2528 else if ( str.compare( QLatin1String(
"Below" ), Qt::CaseInsensitive ) == 0 )
2543 void QgsPalLayerSettings::parseShapeBackground(
QgsRenderContext &context )
2550 bool drawShape = background.
enabled();
2553 drawShape = exprVal.toBool();
2562 double shapeOpacity = background.
opacity() * 100;
2565 shapeOpacity = 100.0 * exprVal.toDouble();
2568 drawShape = ( drawShape && shapeOpacity > 0 );
2580 if ( exprVal.isValid() )
2582 QString skind = exprVal.toString().trimmed();
2583 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeKind:%1" ).arg( skind ), 4 );
2585 if ( !skind.isEmpty() )
2590 if ( skind.compare( QLatin1String(
"Square" ), Qt::CaseInsensitive ) == 0 )
2594 else if ( skind.compare( QLatin1String(
"Ellipse" ), Qt::CaseInsensitive ) == 0 )
2598 else if ( skind.compare( QLatin1String(
"Circle" ), Qt::CaseInsensitive ) == 0 )
2602 else if ( skind.compare( QLatin1String(
"SVG" ), Qt::CaseInsensitive ) == 0 )
2606 shapeKind = shpkind;
2612 QString svgPath = background.
svgFile();
2615 if ( exprVal.isValid() )
2617 QString svgfile = exprVal.toString().trimmed();
2618 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSVGFile:%1" ).arg( svgfile ), 4 );
2628 if ( exprVal.isValid() )
2630 QString stype = exprVal.toString().trimmed();
2631 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeSizeType:%1" ).arg( stype ), 4 );
2633 if ( !stype.isEmpty() )
2638 if ( stype.compare( QLatin1String(
"Fixed" ), Qt::CaseInsensitive ) == 0 )
2642 shpSizeType = sizType;
2648 double ddShpSizeX = background.
size().width();
2651 ddShpSizeX = exprVal.toDouble();
2655 double ddShpSizeY = background.
size().height();
2658 ddShpSizeY = exprVal.toDouble();
2664 && ( svgPath.isEmpty()
2665 || ( !svgPath.isEmpty()
2667 && ddShpSizeX == 0.0 ) ) )
2673 && ( ddShpSizeX == 0.0 || ddShpSizeY == 0.0 ) )
2694 if ( exprVal.isValid() )
2696 QString rotstr = exprVal.toString().trimmed();
2697 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShapeRotationType:%1" ).arg( rotstr ), 4 );
2699 if ( !rotstr.isEmpty() )
2704 if ( rotstr.compare( QLatin1String(
"Offset" ), Qt::CaseInsensitive ) == 0 )
2708 else if ( rotstr.compare( QLatin1String(
"Fixed" ), Qt::CaseInsensitive ) == 0 )
2758 bool drawShadow = shadow.
enabled();
2761 drawShadow = exprVal.toBool();
2770 double shadowOpacity = shadow.
opacity() * 100;
2773 shadowOpacity = exprVal.toDouble();
2780 shadowOffDist = exprVal.toDouble();
2787 shadowRad = exprVal.toDouble();
2790 drawShadow = ( drawShadow && shadowOpacity > 0 && !( shadowOffDist == 0.0 && shadowRad == 0.0 ) );
2803 if ( exprVal.isValid() )
2805 QString str = exprVal.toString().trimmed();
2806 QgsDebugMsgLevel( QStringLiteral(
"exprVal ShadowUnder:%1" ).arg( str ), 4 );
2808 if ( !str.isEmpty() )
2813 if ( str.compare( QLatin1String(
"Text" ), Qt::CaseInsensitive ) == 0 )
2817 else if ( str.compare( QLatin1String(
"Buffer" ), Qt::CaseInsensitive ) == 0 )
2821 else if ( str.compare( QLatin1String(
"Background" ), Qt::CaseInsensitive ) == 0 )
2894 QStringList multiLineSplit;
2895 if ( !wrapCharacter.isEmpty() && wrapCharacter != QLatin1String(
"\n" ) )
2898 const QStringList lines = text.split( wrapCharacter );
2899 for (
const QString &line : lines )
2901 multiLineSplit.append( line.split(
'\n' ) );
2906 multiLineSplit = text.split(
'\n' );
2910 if ( autoWrapLength != 0 )
2912 QStringList autoWrappedLines;
2913 autoWrappedLines.reserve( multiLineSplit.count() );
2914 for (
const QString &line : qgis::as_const( multiLineSplit ) )
2916 autoWrappedLines.append(
QgsStringUtils::wordWrap( line, autoWrapLength, useMaxLineLengthWhenAutoWrapping ).split(
'\n' ) );
2918 multiLineSplit = autoWrappedLines;
2920 return multiLineSplit;
2925 QStringList graphemes;
2926 QTextBoundaryFinder boundaryFinder( QTextBoundaryFinder::Grapheme, text );
2927 int currentBoundary = -1;
2928 int previousBoundary = 0;
2929 while ( ( currentBoundary = boundaryFinder.toNextBoundary() ) > 0 )
2931 graphemes << text.mid( previousBoundary, currentBoundary - previousBoundary );
2932 previousBoundary = currentBoundary;
2962 QgsDebugMsgLevel( QStringLiteral(
"Ignoring feature due to transformation exception" ), 4 );
2968 return std::isfinite( point.
x() ) && std::isfinite( point.
y() );
2971 cp->removeInvalidRings();
2981 QgsDebugMsg( QStringLiteral(
"Error rotating geometry" ).arg( geom.
asWkt() ) );
2995 QVector< QgsGeometry> parts;
2996 parts.reserve( qgsgeometry_cast< const QgsGeometryCollection * >( geom.
constGet() )->numGeometries() );
3000 if ( !partGeom.isGeosValid() )
3002 partGeom = partGeom.
buffer( 0, 0 );
3004 parts.append( partGeom );
3011 if ( bufferGeom.
isNull() )
3013 QgsDebugMsg( QStringLiteral(
"Could not repair geometry: %1" ).arg( bufferGeom.
lastError() ) );
3020 if ( !clipGeometry.
isNull() &&
3056 double length = geom.
length();
3057 if ( length >= 0.0 )
3059 return ( length >= ( minSize * mapUnitsPerMM ) );
3064 double area = geom.
area();
3067 return ( std::sqrt( area ) >= ( minSize * mapUnitsPerMM ) );
3075 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3078 bool changed =
false;
3084 format.
setColor( ddColor.value<QColor>() );
3109 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3164 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3167 bool changed =
false;
3215 buffer.
setColor( ddColor.value<QColor>() );
3242 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3245 bool changed =
false;
3285 QSizeF size = background.
size();
3292 QSizeF size = background.
size();
3393 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues )
3396 bool changed =
false;
3455 shadow.
setColor( ddColor.value<QColor>() );
3493 #if 0 // TODO: generalize some of this 3496 double cx = lp->
getX() + w / 2.0;
3497 double cy = lp->
getY() + h / 2.0;
3500 double sw = w * scale;
3501 double sh = h * scale;
3502 QRectF rect( -sw / 2, -sh / 2, sw, sh );
3508 if ( lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT &&
3509 lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT_OVER &&
3512 painter->rotate( rotation );
3515 painter->translate( rect.bottomLeft() );
3516 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
3517 painter->translate( -rect.bottomLeft() );
3520 QRectF rect( 0, 0, outPt2.
x() - outPt.
x(), outPt2.
y() - outPt.
y() );
3521 painter->translate( QPointF( outPt.
x(), outPt.
y() ) );
3522 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
3527 painter->setPen( QColor( 255, 0, 0, 64 ) );
3531 painter->setPen( QColor( 0, 0, 0, 64 ) );
3533 painter->drawRect( rect );
3537 rect.moveTo( outPt.
x(), outPt.
y() );
3555 QList<QgsLabelPosition> positions;
3557 QList<QgsLabelPosition *> positionPointers;
3558 if ( mLabelSearchTree )
3560 mLabelSearchTree->label( p, positionPointers );
3561 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
3562 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
3573 QList<QgsLabelPosition> positions;
3575 QList<QgsLabelPosition *> positionPointers;
3576 if ( mLabelSearchTree )
3578 mLabelSearchTree->labelsInRect( r, positionPointers );
3579 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
3580 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
3591 mLabelSearchTree->setMapSettings( settings );
QPointF toQPointF() const
Converts a point to a QPointF.
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)
Class for parsing and evaluation of expressions (formerly called "search strings").
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the labeling property definitions.
ShapeType type() const
Returns the type of background shape (e.g., square, ellipse, SVG).
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
double xOffset
Horizontal offset of label.
The class is used as a container of context for various read/write operations on other objects...
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...
Shape transparency (deprecated)
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.
void setScale(int scale)
Sets the scaling used for the drop shadow (in percentage of original size).
Shape size is determined by adding a buffer margin around text.
bool isGeosValid(QgsGeometry::ValidityFlags flags=nullptr) const
Checks validity of the geometry using GEOS.
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).
Label on bottom-left of point.
RotationType
Methods for determining the rotation of the background shape.
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.
QPointF offset() const
Returns the offset used for drawing the background shape.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
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.
QFont font() const
Returns the font used for rendering text.
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the shape's size.
QSizeF size() const
Returns the size of the background shape.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
double opacity() const
Returns the buffer opacity.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via 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.
Qt::PenJoinStyle joinStyle() const
Returns the join style used for drawing the background shape.
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.
void registerFeature(QgsFeature &f, QgsRenderContext &context, QgsLabelFeature **labelFeature=nullptr, QgsGeometry obstacleGeometry=QgsGeometry())
Register a feature for labeling.
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.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Added in QGIS v2.4.
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.
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...
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.
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.
int scale() const
Returns the scaling used for the drop shadow (in percentage of original size).
double tolerance() const
Gets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
QgsTextShadowSettings & shadow()
Returns a reference to the text drop shadow settings.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
static void drawLabelCandidateRect(pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform, QList< QgsLabelCandidate > *candidates=nullptr)
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
void setStrokeColor(const QColor &color)
Sets the color used for outlining the background shape.
double rendererScale() const
Returns the renderer map scale.
void setSize(double size)
Sets the size of the buffer.
A class to represent a 2D point.
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.
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.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
double convertToMapUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
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...
double cost() const
Returns the candidate label position's geographical cost.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
QuadrantPosition quadOffset
Sets the quadrant in which to offset labels from feature.
QgsUnitTypes::RenderUnit offsetUnits
Units for offsets of label.
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
double size() const
Returns the size for rendered text.
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)
double yOffset
Vertical offset of label.
Class that adds extra information to QgsLabelFeature for text labels.
Curve polygon geometry type.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
void setBlurRadius(double blurRadius)
Sets the blur radius for the shadow.
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.
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...
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
bool enabled() const
Returns whether the background is enabled.
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc...
FeaturePart * getFeaturePart()
Returns the feature corresponding to this labelposition.
double opacity() const
Returns the text's opacity.
QColor color() const
Returns the color that text will be rendered in.
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...
QSizeF radii() const
Returns the radii used for rounding the corners of shapes.
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...
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 enabled() const
Returns whether the shadow is enabled.
double blurRadius() const
Returns the blur radius for the shadow.
double mapRotation() const
Returns current map rotation in degrees.
double maxCurvedCharAngleIn
Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
QgsCoordinateTransform ct
QColor color() const
Returns the color of the buffer.
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.
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...
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.
bool contains(const QgsPointXY *p) const
Tests for containment of a point (uses GEOS)
The QgsMapSettings class contains configuration for rendering of the map.
static QString encodeColor(const QColor &color)
static bool staticWillUseLayer(QgsVectorLayer *layer)
called to find out whether the layer is used for labeling
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...
QColor strokeColor() const
Returns the color used for outlining the background shape.
bool conflictsWithObstacle() const
Returns whether the position is marked as conflicting with an obstacle feature.
Place direction symbols on left/right of label.
Perform transforms between map coordinates and device coordinates.
QList< QgsLabelPosition > labelsWithinRect(const QgsRectangle &r) const
Returns infos about labels within a given (map) rectangle.
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.
No simplification can be applied.
ObstacleType obstacleType
Controls how features act as obstacles for labels.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static pal::LineArrangementFlags decodeLinePlacementFlags(const QString &string)
Decodes a string to set of line placement flags.
QString namedStyle() const
Returns the named style for the font used for rendering text (e.g., "bold").
bool displayAll
If true, all features will be labelled even when overlaps occur.
void setIsObstacle(bool enabled)
Sets whether the feature will act as an obstacle for labels.
bool enabled() const
Returns whether the buffer is enabled.
void setOffsetDistance(double distance)
Sets the distance for offsetting the position of the shadow from the text.
double offsetDistance() const
Returns 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.
#define QgsDebugMsgLevel(str, level)
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
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].
Maximum map scale (ie most "zoomed in")
static bool geometryRequiresPreparation(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry(), bool mergeLines=false)
Checks whether a geometry requires preparation before registration with PAL.
The geometries can be fully simplified by its BoundingBox.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the drop shadow.
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.
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
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.
double getY(int i=0) const
Returns the down-left y coordinate.
QgsPointXY center() const
Returns the center point of the rectangle.
Horizontal alignment for data defined label position (Left, Center, Right)
QString svgFile() const
Returns the absolute path to the background SVG file, if set.
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
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.
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
double opacity() const
Returns the background shape's opacity.
Upside-down labels (90 <= angle < 270) are shown upright.
SizeType
Methods for determining the background shape size.
double mapUnitsPerPixel() const
Returns current map units per pixel.
OffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes...
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
LabelPosition * getNextPart() const
static QPainter::CompositionMode decodeBlendMode(const QString &s)
void calculateLabelSize(const QFontMetricsF *fm, QString text, double &labelX, double &labelY, QgsFeature *f=nullptr, QgsRenderContext *context=nullptr)
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.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
A store for object properties.
double getX(int i=0) const
Returns the down-left x coordinate.
void setRadii(QSizeF radii)
Sets the radii used for rounding the corners of shapes.
Implementation of GeometrySimplifier using the "MapToPixel" algorithm.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the size.
Point geometry type, with support for z-dimension and m-values.
Double value (including negative values)
static QString encodeLinePlacementFlags(pal::LineArrangementFlags flags)
Encodes line placement flags to a string.
Minimum map scale (ie most "zoomed out")
Convert just the first letter of each word to uppercase, leave the rest untouched.
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...
Definition for a property.
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported...
Capitalization
Capitalization options.
int offsetAngle() const
Returns the angle for offsetting the position of the shadow from the text.
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.
QgsExpressionContext & expressionContext()
Gets the expression context.
Label rotation (deprecated, for old project compatibility only)
static QSizeF decodeSize(const QString &string)
Decodes a QSizeF from a string.
double length() const
Returns the length of geometry using GEOS.
double getAlpha() const
Returns the angle to rotate text (in rad).
bool plusSign
Whether '+' signs should be prepended to positive numeric labels.
void setEnabled(bool enabled)
Sets whether the text background will be drawn.
unsigned int placementFlags
ShapeType
Background shape types.
QString wrapChar
Wrapping character string.
QgsPalLayerSettings & operator=(const QgsPalLayerSettings &s)
copy operator - only copies the permanent members
QgsGeometry simplify(double tolerance) const
Returns a simplified version of this geometry using a specified tolerance value.
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 process(const QString &input) const
Processes a given input string, applying any valid replacements which should be made using QgsStringR...
QString rightDirectionSymbol
String to use for right direction arrows.
bool preserveRotation
True if label rotation should be preserved during label pin/unpin operations.
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...
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.
bool centroidWhole
True if feature centroid should be calculated from the whole feature, or false if only the visible pa...
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry...
bool scaleVisibility
Set to true to limit label visibility to a range of scales.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
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...
Property requires a string value.
Mixed case, ie no change.
QgsMapUnitScale distMapUnitScale
Map unit scale for label feature distance.
QColor color() const
Returns the color of the drop shadow.
bool fitInPolygonOnly
True if only labels which completely fit within a polygon are allowed.
Container for settings relating to a text shadow.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
void setMapSettings(const QgsMapSettings &settings)
Sets the map settings associated with the labeling run.
Container for settings relating to a text buffer.
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.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
bool useSubstitutions
True if substitutions should be applied.
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's stroke width.
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.
double size() const
Returns the size of the buffer.
LabelPosition is a candidate feature label position.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
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.
Draw shadow under background shape.
double rotation() const
Returns the rotation for the background shape, in degrees clockwise.
bool isExpression
True if this label is made from a expression string, e.g., FieldName || 'mm'.
Convert all characters to lowercase.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
void setShadow(const QgsTextShadowSettings &shadowSettings)
Sets the text's drop shadow settings.
void readXml(const QDomElement &elem)
Reads the collection state from an XML element.
Custom exception class for Coordinate Reference System related exceptions.
static QVector< QgsPalLayerSettings::PredefinedPointPosition > decodePredefinedPositionOrder(const QString &positionString)
Decodes a string to an ordered list of predefined point label positions.
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
Y-coordinate data defined label position.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
Container for all settings relating to text rendering.
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)
double width() const
Returns the width of the rectangle.
void setSvgFile(const QString &file)
Sets the path to the background SVG file.
double opacity() const
Returns the shadow's opacity.
double lineHeight() const
Returns the line height for text.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
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.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
Square - buffered sizes only.
QString updateDataDefinedString(const QString &value)
QgsWkbTypes::GeometryType type() const
Returns type of the geometry as a QgsWkbTypes::GeometryType.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
QString parserErrorString() const
Returns parser error.
double minFeatureSize
Minimum feature size (in millimeters) for a feature to be labelled.
double strokeWidth() const
Returns the width of the shape's stroke (stroke).
Vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top) ...
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
QColor fillColor() const
Returns the color used for filing the background shape.
QgsGeometry mergeLines() const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
QString evalErrorString() const
Returns evaluation error.
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...
void writeXml(QDomElement &elem, QDomDocument &doc) const
Writes the collection state to an XML element.
double area() const
Returns the area of the geometry using GEOS.
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.
static QColor decodeColor(const QString &str)
Buffer transparency (deprecated)
double height() const
Returns the height of the rectangle.
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...
QList< QgsLabelPosition > labelsAtPosition(const QgsPointXY &p) const
Returns infos about labels at a given (map) position.
Text transparency (deprecated)
double minimumScale
The minimum map scale (i.e.
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
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.