18#include "moc_qgslayoutitemscalebar.cpp"
43#include <QDomDocument>
45#include <QFontMetricsF>
47#include <QTextDocument>
48#include <QAbstractTextDocumentLayout>
93 if (
mLayout->renderContext().isPreviewRender() )
99 const QRectF thisPaintRect = QRectF( 0, 0, rect().width() * scale, rect().
height() * scale );
101 painter->setBrush( QBrush( QColor( 255, 125, 125, 125 ) ) );
102 painter->setPen( Qt::NoPen );
103 painter->drawRect( thisPaintRect );
104 painter->setBrush( Qt::NoBrush );
106 painter->setPen( QColor( 200, 0, 0, 255 ) );
108 td.setTextWidth( thisPaintRect.width() );
109 td.setHtml( QStringLiteral(
"<span style=\"color: rgb(200,0,0);\"><b>%1</b><br>%2</span>" ).arg(
110 tr(
"Invalid scale!" ),
111 tr(
"The scale bar cannot be rendered due to invalid settings or an incompatible linked map extent." ) ) );
112 painter->setClipRect( thisPaintRect );
113 QAbstractTextDocumentLayout::PaintContext ctx;
114 td.documentLayout()->draw( painter, ctx );
123 std::unique_ptr< QgsLineSymbol > sym( mSettings.
lineSymbol()->
clone() );
136 std::unique_ptr< QgsFillSymbol > sym( mSettings.
fillSymbol()->
clone() );
153 mStyle->draw( context.
renderContext(), mSettings, scaleContext );
175 refreshSegmentMillimeters();
188 refreshSegmentMillimeters();
200 refreshSegmentMillimeters();
212 refreshSegmentMillimeters();
302 disconnectCurrentMap();
312 connect( mMap, &QObject::destroyed,
this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
314 refreshSegmentMillimeters();
318void QgsLayoutItemScaleBar::disconnectCurrentMap()
326 disconnect( mMap, &QObject::destroyed,
this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
341 refreshSegmentMillimeters();
448 bool forceUpdate =
false;
492 refreshNumberOfSegmentsLeft( &context );
498 refreshNumberOfSegmentsRight( &context );
525 refreshUnitsPerSegment( &context );
531 refreshMinimumBarWidth( &context );
537 refreshMaximumBarWidth( &context );
569void QgsLayoutItemScaleBar::refreshSegmentMillimeters()
574 const QRectF composerItemRect = mMap->rect();
576 const double currentMapWidth = mapWidth();
577 if (
qgsDoubleNear( currentMapWidth, 0 ) || std::isnan( currentMapWidth ) )
579 mSegmentMillimeters = std::numeric_limits< double >::quiet_NaN();
588 mSegmentMillimeters = composerItemRect.width() / currentMapWidth * mSettings.
unitsPerSegment();
596 mSegmentMillimeters = 0;
602 const double minUnitsPerSeg = ( mSettings.
minimumBarWidth() * currentMapWidth ) / ( nSegments * composerItemRect.width() );
603 const double maxUnitsPerSeg = ( mSettings.
maximumBarWidth() * currentMapWidth ) / ( nSegments * composerItemRect.width() );
605 mSegmentMillimeters = composerItemRect.width() / currentMapWidth * mSettings.
unitsPerSegment();
613double QgsLayoutItemScaleBar::mapWidth()
const
623 return mapExtent.
width();
633 QList< double > yValues;
656 double sumValidMeasures = 0;
657 int validMeasureCount = 0;
659 for (
const double y : std::as_const( yValues ) )
665 if ( std::isnan( measure ) )
668 QgsDebugError( QStringLiteral(
"An error occurred while calculating length" ) );
673 sumValidMeasures += measure;
679 QgsDebugError( QStringLiteral(
"An error occurred while calculating length" ) );
684 if ( validMeasureCount == 0 )
685 return std::numeric_limits< double >::quiet_NaN();
687 return sumValidMeasures / validMeasureCount;
694 scaleContext.
size = rect().size();
696 scaleContext.
scale = mMap ? mMap->
scale() : 1.0;
697 scaleContext.
flags = mStyle->flags();
725 refreshSegmentMillimeters();
775 mStyle = std::make_unique< QgsSingleBoxScaleBarRenderer >();
782 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
785 if ( !defaultFontString.isEmpty() )
821 const double widthInSelectedUnits = mapWidth();
822 if ( std::isnan( widthInSelectedUnits ) )
825 const double initialUnitsPerSegment = widthInSelectedUnits / 10.0;
830 if ( initialUnitsPerSegment > 1000.0 )
838 if ( initialUnitsPerSegment > 5419.95 )
856 double upperMagnitudeMultiplier = 1.0;
857 const double widthInSelectedUnits = mapWidth();
858 if ( !std::isnan( widthInSelectedUnits ) )
860 const double initialUnitsPerSegment = widthInSelectedUnits / 10.0;
864 upperMagnitudeMultiplier = 1;
866 const double segmentWidth = initialUnitsPerSegment / upperMagnitudeMultiplier;
867 const int segmentMagnitude = std::floor( std::log10( segmentWidth ) );
868 double unitsPerSegment = upperMagnitudeMultiplier * ( std::pow( 10.0, segmentMagnitude ) );
869 const double multiplier = std::floor( ( widthInSelectedUnits / (
unitsPerSegment * 10.0 ) ) / 2.5 ) * 2.5;
871 if ( multiplier > 0 )
883 refreshSegmentMillimeters();
899 const double widthMM = mStyle->calculateBoxSize( context, mSettings, scaleContext ).width();
910 if ( mStyle && mStyle->id() != QLatin1String(
"Numeric" ) )
914 QgsLayoutItem::update();
917void QgsLayoutItemScaleBar::updateScale()
919 refreshSegmentMillimeters();
921 if ( mStyle && mStyle->id() != QLatin1String(
"Numeric" ) )
934 mStyle = std::move( renderer );
1048 return mSettings.
pen();
1055 return mSettings.
brush();
1062 return mSettings.
brush2();
1068 composerScaleBarElem.setAttribute( QStringLiteral(
"height" ), QString::number( mSettings.
height() ) );
1069 composerScaleBarElem.setAttribute( QStringLiteral(
"labelBarSpace" ), QString::number( mSettings.
labelBarSpace() ) );
1070 composerScaleBarElem.setAttribute( QStringLiteral(
"boxContentSpace" ), QString::number( mSettings.
boxContentSpace() ) );
1071 composerScaleBarElem.setAttribute( QStringLiteral(
"numSegments" ), mSettings.
numberOfSegments() );
1072 composerScaleBarElem.setAttribute( QStringLiteral(
"numSegmentsLeft" ), mSettings.
numberOfSegmentsLeft() );
1073 composerScaleBarElem.setAttribute( QStringLiteral(
"numSubdivisions" ), mSettings.
numberOfSubdivisions() );
1074 composerScaleBarElem.setAttribute( QStringLiteral(
"subdivisionsHeight" ), mSettings.
subdivisionsHeight() );
1075 composerScaleBarElem.setAttribute( QStringLiteral(
"numUnitsPerSegment" ), QString::number( mSettings.
unitsPerSegment() ) );
1076 composerScaleBarElem.setAttribute( QStringLiteral(
"segmentSizeMode" ),
static_cast< int >( mSettings.
segmentSizeMode() ) );
1077 composerScaleBarElem.setAttribute( QStringLiteral(
"minBarWidth" ), mSettings.
minimumBarWidth() );
1078 composerScaleBarElem.setAttribute( QStringLiteral(
"maxBarWidth" ), mSettings.
maximumBarWidth() );
1079 composerScaleBarElem.setAttribute( QStringLiteral(
"segmentMillimeters" ), QString::number( mSegmentMillimeters ) );
1080 composerScaleBarElem.setAttribute( QStringLiteral(
"numMapUnitsPerScaleBarUnit" ), QString::number( mSettings.
mapUnitsPerScaleBarUnit() ) );
1081 composerScaleBarElem.setAttribute( QStringLiteral(
"method" ),
qgsEnumValueToKey( mMethod ) );
1084 composerScaleBarElem.appendChild( textElem );
1088 composerScaleBarElem.setAttribute( QStringLiteral(
"outlineWidth" ), QString::number( mSettings.
lineWidth() ) );
1092 QDomElement strokeColorElem = doc.createElement( QStringLiteral(
"strokeColor" ) );
1093 strokeColorElem.setAttribute( QStringLiteral(
"red" ), QString::number( mSettings.
lineColor().red() ) );
1094 strokeColorElem.setAttribute( QStringLiteral(
"green" ), QString::number( mSettings.
lineColor().green() ) );
1095 strokeColorElem.setAttribute( QStringLiteral(
"blue" ), QString::number( mSettings.
lineColor().blue() ) );
1096 strokeColorElem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mSettings.
lineColor().alpha() ) );
1097 composerScaleBarElem.appendChild( strokeColorElem );
1100 composerScaleBarElem.setAttribute( QStringLiteral(
"unitLabel" ), mSettings.
unitLabel() );
1103 QDomElement numericFormatElem = doc.createElement( QStringLiteral(
"numericFormat" ) );
1105 composerScaleBarElem.appendChild( numericFormatElem );
1110 composerScaleBarElem.setAttribute( QStringLiteral(
"style" ), mStyle->id() );
1116 composerScaleBarElem.setAttribute( QStringLiteral(
"mapUuid" ), mMap->
uuid() );
1125 QDomElement fillColorElem = doc.createElement( QStringLiteral(
"fillColor" ) );
1126 fillColorElem.setAttribute( QStringLiteral(
"red" ), QString::number( mSettings.
fillColor().red() ) );
1127 fillColorElem.setAttribute( QStringLiteral(
"green" ), QString::number( mSettings.
fillColor().green() ) );
1128 fillColorElem.setAttribute( QStringLiteral(
"blue" ), QString::number( mSettings.
fillColor().blue() ) );
1129 fillColorElem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mSettings.
fillColor().alpha() ) );
1130 composerScaleBarElem.appendChild( fillColorElem );
1133 QDomElement fillColor2Elem = doc.createElement( QStringLiteral(
"fillColor2" ) );
1134 fillColor2Elem.setAttribute( QStringLiteral(
"red" ), QString::number( mSettings.
fillColor2().red() ) );
1135 fillColor2Elem.setAttribute( QStringLiteral(
"green" ), QString::number( mSettings.
fillColor2().green() ) );
1136 fillColor2Elem.setAttribute( QStringLiteral(
"blue" ), QString::number( mSettings.
fillColor2().blue() ) );
1137 fillColor2Elem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mSettings.
fillColor2().alpha() ) );
1138 composerScaleBarElem.appendChild( fillColor2Elem );
1143 composerScaleBarElem.setAttribute( QStringLiteral(
"labelVerticalPlacement" ), QString::number(
static_cast< int >( mSettings.
labelVerticalPlacement() ) ) );
1144 composerScaleBarElem.setAttribute( QStringLiteral(
"labelHorizontalPlacement" ), QString::number(
static_cast< int >( mSettings.
labelHorizontalPlacement() ) ) );
1147 composerScaleBarElem.setAttribute( QStringLiteral(
"alignment" ), QString::number(
static_cast< int >( mSettings.
alignment() ) ) );
1149 QDomElement
lineSymbol = doc.createElement( QStringLiteral(
"lineSymbol" ) );
1155 composerScaleBarElem.appendChild(
lineSymbol );
1157 QDomElement divisionSymbol = doc.createElement( QStringLiteral(
"divisionLineSymbol" ) );
1162 divisionSymbol.appendChild( divisionSymbolElem );
1163 composerScaleBarElem.appendChild( divisionSymbol );
1165 QDomElement subdivisionSymbol = doc.createElement( QStringLiteral(
"subdivisionLineSymbol" ) );
1170 subdivisionSymbol.appendChild( subdivisionSymbolElem );
1171 composerScaleBarElem.appendChild( subdivisionSymbol );
1173 QDomElement fillSymbol1Elem = doc.createElement( QStringLiteral(
"fillSymbol1" ) );
1178 fillSymbol1Elem.appendChild( symbol1Elem );
1179 composerScaleBarElem.appendChild( fillSymbol1Elem );
1181 QDomElement fillSymbol2Elem = doc.createElement( QStringLiteral(
"fillSymbol2" ) );
1186 fillSymbol2Elem.appendChild( symbol2Elem );
1187 composerScaleBarElem.appendChild( fillSymbol2Elem );
1195 mSettings.
setHeight( itemElem.attribute( QStringLiteral(
"height" ), QStringLiteral(
"5.0" ) ).toDouble() );
1196 mSettings.
setLabelBarSpace( itemElem.attribute( QStringLiteral(
"labelBarSpace" ), QStringLiteral(
"3.0" ) ).toDouble() );
1197 mSettings.
setBoxContentSpace( itemElem.attribute( QStringLiteral(
"boxContentSpace" ), QStringLiteral(
"1.0" ) ).toDouble() );
1198 mSettings.
setNumberOfSegments( itemElem.attribute( QStringLiteral(
"numSegments" ), QStringLiteral(
"2" ) ).toInt() );
1199 mSettings.
setNumberOfSegmentsLeft( itemElem.attribute( QStringLiteral(
"numSegmentsLeft" ), QStringLiteral(
"0" ) ).toInt() );
1200 mSettings.
setNumberOfSubdivisions( itemElem.attribute( QStringLiteral(
"numSubdivisions" ), QStringLiteral(
"1" ) ).toInt() );
1201 mSettings.
setSubdivisionsHeight( itemElem.attribute( QStringLiteral(
"subdivisionsHeight" ), QStringLiteral(
"1.5" ) ).toDouble() );
1202 mSettings.
setUnitsPerSegment( itemElem.attribute( QStringLiteral(
"numUnitsPerSegment" ), QStringLiteral(
"1.0" ) ).toDouble() );
1204 mSettings.
setMinimumBarWidth( itemElem.attribute( QStringLiteral(
"minBarWidth" ), QStringLiteral(
"50" ) ).toDouble() );
1205 mSettings.
setMaximumBarWidth( itemElem.attribute( QStringLiteral(
"maxBarWidth" ), QStringLiteral(
"150" ) ).toDouble() );
1206 mSegmentMillimeters = itemElem.attribute( QStringLiteral(
"segmentMillimeters" ), QStringLiteral(
"0.0" ) ).toDouble();
1207 mSettings.
setMapUnitsPerScaleBarUnit( itemElem.attribute( QStringLiteral(
"numMapUnitsPerScaleBarUnit" ), QStringLiteral(
"1.0" ) ).toDouble() );
1212 const QDomElement lineSymbolElem = itemElem.firstChildElement( QStringLiteral(
"lineSymbol" ) );
1213 bool foundLineSymbol =
false;
1214 if ( !lineSymbolElem.isNull() )
1216 const QDomElement symbolElem = lineSymbolElem.firstChildElement( QStringLiteral(
"symbol" ) );
1217 std::unique_ptr< QgsLineSymbol >
lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
1221 foundLineSymbol =
true;
1224 const QDomElement divisionSymbolElem = itemElem.firstChildElement( QStringLiteral(
"divisionLineSymbol" ) );
1225 if ( !divisionSymbolElem.isNull() )
1227 const QDomElement symbolElem = divisionSymbolElem.firstChildElement( QStringLiteral(
"symbol" ) );
1228 std::unique_ptr< QgsLineSymbol >
lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
1234 else if ( foundLineSymbol )
1238 const QDomElement subdivisionSymbolElem = itemElem.firstChildElement( QStringLiteral(
"subdivisionLineSymbol" ) );
1239 if ( !subdivisionSymbolElem.isNull() )
1241 const QDomElement symbolElem = subdivisionSymbolElem.firstChildElement( QStringLiteral(
"symbol" ) );
1242 std::unique_ptr< QgsLineSymbol >
lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
1248 else if ( foundLineSymbol )
1253 if ( !foundLineSymbol )
1256 std::unique_ptr< QgsLineSymbol >
lineSymbol = std::make_unique< QgsLineSymbol >();
1257 std::unique_ptr< QgsSimpleLineSymbolLayer > lineSymbolLayer = std::make_unique< QgsSimpleLineSymbolLayer >();
1258 lineSymbolLayer->setWidth( itemElem.attribute( QStringLiteral(
"outlineWidth" ), QStringLiteral(
"0.3" ) ).toDouble() );
1264 const QDomNodeList strokeColorList = itemElem.elementsByTagName( QStringLiteral(
"strokeColor" ) );
1265 if ( !strokeColorList.isEmpty() )
1267 const QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
1268 bool redOk, greenOk, blueOk, alphaOk;
1269 int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
1271 strokeRed = strokeColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1272 strokeGreen = strokeColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1273 strokeBlue = strokeColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1274 strokeAlpha = strokeColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1276 if ( redOk && greenOk && blueOk && alphaOk )
1278 lineSymbolLayer->setColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) );
1283 lineSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral(
"penColor" ), QStringLiteral(
"#000000" ) ) ) );
1299 mSettings.
setUnitLabel( itemElem.attribute( QStringLiteral(
"unitLabel" ) ) );
1301 const QDomNodeList textFormatNodeList = itemElem.elementsByTagName( QStringLiteral(
"text-style" ) );
1302 if ( !textFormatNodeList.isEmpty() )
1304 const QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
1312 f.fromString( itemElem.attribute( QStringLiteral(
"font" ), QString() ) );
1315 if ( f.pointSizeF() > 0 )
1320 else if ( f.pixelSize() > 0 )
1327 const QDomNodeList numericFormatNodeList = itemElem.elementsByTagName( QStringLiteral(
"numericFormat" ) );
1328 if ( !numericFormatNodeList.isEmpty() )
1330 const QDomElement numericFormatElem = numericFormatNodeList.at( 0 ).toElement();
1334 const QDomElement fillSymbol1Elem = itemElem.firstChildElement( QStringLiteral(
"fillSymbol1" ) );
1335 bool foundFillSymbol1 =
false;
1336 if ( !fillSymbol1Elem.isNull() )
1338 const QDomElement symbolElem = fillSymbol1Elem.firstChildElement( QStringLiteral(
"symbol" ) );
1339 std::unique_ptr< QgsFillSymbol >
fillSymbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context ) );
1343 foundFillSymbol1 =
true;
1346 if ( !foundFillSymbol1 )
1349 std::unique_ptr< QgsFillSymbol >
fillSymbol = std::make_unique< QgsFillSymbol >();
1350 std::unique_ptr< QgsSimpleFillSymbolLayer > fillSymbolLayer = std::make_unique< QgsSimpleFillSymbolLayer >();
1351 fillSymbolLayer->setStrokeStyle( Qt::NoPen );
1354 const QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral(
"fillColor" ) );
1355 if ( !fillColorList.isEmpty() )
1357 const QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
1358 bool redOk, greenOk, blueOk, alphaOk;
1359 int fillRed, fillGreen, fillBlue, fillAlpha;
1361 fillRed = fillColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1362 fillGreen = fillColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1363 fillBlue = fillColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1364 fillAlpha = fillColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1366 if ( redOk && greenOk && blueOk && alphaOk )
1368 fillSymbolLayer->setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1373 fillSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral(
"brushColor" ), QStringLiteral(
"#000000" ) ) ) );
1385 const QDomElement fillSymbol2Elem = itemElem.firstChildElement( QStringLiteral(
"fillSymbol2" ) );
1386 bool foundFillSymbol2 =
false;
1387 if ( !fillSymbol2Elem.isNull() )
1389 const QDomElement symbolElem = fillSymbol2Elem.firstChildElement( QStringLiteral(
"symbol" ) );
1390 std::unique_ptr< QgsFillSymbol >
fillSymbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context ) );
1394 foundFillSymbol2 =
true;
1397 if ( !foundFillSymbol2 )
1400 std::unique_ptr< QgsFillSymbol >
fillSymbol = std::make_unique< QgsFillSymbol >();
1401 std::unique_ptr< QgsSimpleFillSymbolLayer > fillSymbolLayer = std::make_unique< QgsSimpleFillSymbolLayer >();
1402 fillSymbolLayer->setStrokeStyle( Qt::NoPen );
1406 const QDomNodeList fillColor2List = itemElem.elementsByTagName( QStringLiteral(
"fillColor2" ) );
1407 if ( !fillColor2List.isEmpty() )
1409 const QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
1410 bool redOk, greenOk, blueOk, alphaOk;
1411 int fillRed, fillGreen, fillBlue, fillAlpha;
1413 fillRed = fillColor2Elem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1414 fillGreen = fillColor2Elem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1415 fillBlue = fillColor2Elem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1416 fillAlpha = fillColor2Elem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1418 if ( redOk && greenOk && blueOk && alphaOk )
1420 fillSymbolLayer->setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1425 fillSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral(
"brush2Color" ), QStringLiteral(
"#ffffff" ) ) ) );
1439 const QDomNodeList textColorList = itemElem.elementsByTagName( QStringLiteral(
"textColor" ) );
1440 if ( !textColorList.isEmpty() )
1442 const QDomElement textColorElem = textColorList.at( 0 ).toElement();
1443 bool redOk, greenOk, blueOk, alphaOk;
1444 int textRed, textGreen, textBlue, textAlpha;
1446 textRed = textColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1447 textGreen = textColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1448 textBlue = textColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1449 textAlpha = textColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1451 if ( redOk && greenOk && blueOk && alphaOk )
1453 mSettings.
textFormat().
setColor( QColor( textRed, textGreen, textBlue, textAlpha ) );
1456 else if ( itemElem.hasAttribute( QStringLiteral(
"fontColor" ) ) )
1459 c.setNamedColor( itemElem.attribute( QStringLiteral(
"fontColor" ), QStringLiteral(
"#000000" ) ) );
1464 setStyle( itemElem.attribute( QStringLiteral(
"style" ), QString() ) );
1469 if ( itemElem.attribute( QStringLiteral(
"unitType" ) ).isEmpty() )
1472 switch ( itemElem.attribute( QStringLiteral(
"units" ) ).toInt() )
1500 disconnectCurrentMap();
1502 mMapUuid = itemElem.attribute( QStringLiteral(
"mapUuid" ) );
1509 if (
mLayout && !mMapUuid.isEmpty() )
1511 disconnectCurrentMap();
1512 mMap = qobject_cast< QgsLayoutItemMap * >(
mLayout->itemByUuid( mMapUuid,
true ) );
1516 connect( mMap, &QObject::destroyed,
this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
ScaleBarDistanceLabelHorizontalPlacement
Scale bar distance label horizontal placement.
ScaleBarDistanceLabelVerticalPlacement
Scale bar distance label vertical placement.
@ Millimeters
Millimeters.
ScaleBarAlignment
Scalebar alignment.
DistanceUnit
Units of distance.
@ Miles
Terrestrial miles.
@ Unknown
Unknown distance unit.
@ Degrees
Degrees, for planar geographic CRS distance measurements.
@ NauticalMiles
Nautical miles.
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
ScaleCalculationMethod
Scale calculation logic.
@ HorizontalTop
Calculate horizontally, across top of map.
@ HorizontalMiddle
Calculate horizontally, across midle of map.
@ HorizontalAverage
Calculate horizontally, using the average of the top, middle and bottom scales.
@ HorizontalBottom
Calculate horizontally, across bottom of map.
ScaleBarSegmentSizeMode
Modes for setting size for scale bar segments.
@ FitWidth
Scale bar segment size is calculated to fit a size range.
@ Fixed
Scale bar segment size is fixed to a map unit.
QColor valueAsColor(int key, const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a color.
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.
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 QgsScaleBarRendererRegistry * scaleBarRendererRegistry()
Gets the registry of available scalebar renderers.
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
This class represents a coordinate reference system (CRS).
Qgis::DistanceUnit mapUnits
Custom exception class for Coordinate Reference System related exceptions.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
double measureLine(const QVector< QgsPointXY > &points) const
Measures the length of a line with multiple segments.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
Qgis::DistanceUnit lengthUnits() const
Returns the units of distance for length calculations made by this object.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
static void setFontFamily(QFont &font, const QString &family)
Sets the family for a font object.
Layout graphical items for displaying a map.
void extentChanged()
Emitted when the map's extent changes.
double scale() const
Returns the map scale.
QgsRectangle extent() const
Returns the current map extent.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
@ LayoutScaleBar
Scale bar item.
Contains settings and helpers relating to a render of a QgsLayoutItem.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
A layout item subclass for scale bars.
void setNumberOfSegments(int segments)
Sets the number of segments included in the scalebar.
Q_DECL_DEPRECATED QBrush brush() const
Returns the primary brush for the scalebar.
Q_DECL_DEPRECATED QColor fillColor2() const
Returns the secondary color used for fills in the scalebar.
Q_DECL_DEPRECATED double lineWidth() const
Returns the line width in millimeters for lines in the scalebar.
QIcon icon() const override
Returns the item's icon.
Q_DECL_DEPRECATED void setFillColor(const QColor &color)
Sets the color used for fills in the scalebar.
QgsLineSymbol * divisionLineSymbol() const
Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).
QgsFillSymbol * alternateFillSymbol() const
Returns the secondary fill symbol used to render the scalebar (only used for some scalebar types).
Q_DECL_DEPRECATED QBrush brush2() const
Returns the secondary brush for the scalebar.
double height() const
Returns the scalebar height (in millimeters).
void setMinimumBarWidth(double minWidth)
Sets the minimum width (in millimeters) for scale bar segments.
QgsFillSymbol * fillSymbol() const
Returns the primary fill symbol used to render the scalebar (only used for some scalebar types).
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
Q_DECL_DEPRECATED QColor fontColor() const
Returns the color used for drawing text in the scalebar.
void setMaximumBarWidth(double maxWidth)
Sets the maximum width (in millimeters) for scale bar segments.
Q_DECL_DEPRECATED QColor fillColor() const
Returns the color used for fills in the scalebar.
void setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for numbers in the scalebar.
Q_DECL_DEPRECATED void setLineColor(const QColor &color)
Sets the color used for lines in the scalebar.
void setDivisionLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar divisions (only used for some scalebar types).
Q_DECL_DEPRECATED QColor lineColor() const
Returns the color used for lines in the scalebar.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
void update()
Adjusts the scale bar box size and updates the item.
void setFillSymbol(QgsFillSymbol *symbol)
Sets the primary fill symbol used to render the scalebar (only used for some scalebar types).
double unitsPerSegment() const
Returns the number of scalebar units per segment.
void setAlignment(Qgis::ScaleBarAlignment alignment)
Sets the scalebar alignment.
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
bool applyDefaultRendererSettings(QgsScaleBarRenderer *renderer)
Applies any default settings relating to the specified renderer to the item.
double minimumBarWidth() const
Returns the minimum width (in millimeters) for scale bar segments.
QgsLineSymbol * subdivisionLineSymbol() const
Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
Q_DECL_DEPRECATED QFont font() const
Returns the font used for drawing text in the scalebar.
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
void setAlternateFillSymbol(QgsFillSymbol *symbol)
Sets the secondary fill symbol used to render the scalebar (only used for some scalebar types).
int type() const override
void setLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar (only used for some scalebar types).
void setStyle(const QString &name)
Sets the scale bar style by name.
Q_DECL_DEPRECATED void setFillColor2(const QColor &color)
Sets the secondary color used for fills in the scalebar.
void applyDefaultSettings()
Applies the default scalebar settings to the scale bar.
void setLabelVerticalPlacement(Qgis::ScaleBarDistanceLabelVerticalPlacement placement)
Sets the vertical placement of text labels.
void setLabelHorizontalPlacement(Qgis::ScaleBarDistanceLabelHorizontalPlacement placement)
Sets the horizontal placement of text labels.
void setHeight(double height)
Sets the scalebar height (in millimeters).
Q_DECL_DEPRECATED Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
void setSubdivisionsHeight(double height)
Sets the scalebar subdivisions height (in millimeters) for segments included in the right part of the...
void setNumberOfSegmentsLeft(int segments)
Sets the number of segments included in the left part of the scalebar.
Qgis::DistanceUnit units() const
Returns the distance units used by the scalebar.
void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties) override
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
Q_DECL_DEPRECATED Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for drawing text in the scalebar.
void setUnits(Qgis::DistanceUnit units)
Sets the distance units used by the scalebar.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map item linked to the scalebar.
QgsLayoutSize minimumSize() const override
Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely r...
Q_DECL_DEPRECATED void setLineJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the lines in the scalebar.
void setSegmentSizeMode(Qgis::ScaleBarSegmentSizeMode mode)
Sets the size mode for scale bar segments.
QgsLineSymbol * lineSymbol() const
Returns the line symbol used to render the scalebar (only used for some scalebar types).
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
Q_DECL_DEPRECATED void setFontColor(const QColor &color)
Sets the color used for drawing text in the scalebar.
Q_DECL_DEPRECATED void setLineWidth(double width)
Sets the line width in millimeters for lines in the scalebar.
Q_DECL_DEPRECATED QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
void setBoxContentSpace(double space)
Sets the space (margin) between the scalebar box and content in millimeters.
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the scalebar.
void setUnitLabel(const QString &label)
Sets the label for units.
QString style() const
Returns the scale bar style name.
ExportLayerBehavior exportLayerBehavior() const override
Returns the behavior of this item during exporting to layered exports (e.g.
QgsTextFormat textFormat() const
Returns the text format used for drawing text in the scalebar.
Q_DECL_DEPRECATED void setLineCapStyle(Qt::PenCapStyle style)
Sets the cap style used when drawing the lines in the scalebar.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
void resizeToMinimumWidth()
Resizes the scale bar to its minimum width, without changing the height.
void setUnitsPerSegment(double units)
Sets the number of scalebar units per segment.
static QgsLayoutItemScaleBar * create(QgsLayout *layout)
Returns a new scale bar item for the specified layout.
void setMethod(Qgis::ScaleCalculationMethod method)
Sets the scale calculation method, which determines how the bar's scale will be calculated.
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
Qgis::DistanceUnit guessUnits() const
Attempts to guess the most reasonable unit choice for the scalebar, given the current linked map's sc...
void setSubdivisionLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
void applyDefaultSize(Qgis::DistanceUnit units=Qgis::DistanceUnit::Meters)
Applies the default size to the scale bar (scale bar 1/5 of map item width)
Qgis::ScaleCalculationMethod method() const
Returns the scale calculation method, which determines how the bar's scale will be calculated.
void setNumberOfSubdivisions(int subdivisions)
Sets the number of subdivisions for segments included in the right part of the scalebar (only used fo...
QgsLayoutItemScaleBar(QgsLayout *layout)
Constructor for QgsLayoutItemScaleBar, with the specified parent layout.
Base class for graphical items within a QgsLayout.
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
void refreshItemSize()
Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
virtual QString displayName() const
Gets item display name.
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
virtual QString uuid() const
Returns the item identification string.
ExportLayerBehavior
Behavior of item when exporting to layered outputs.
@ CanGroupWithItemsOfSameType
Item can only be placed on layers with other items of the same type, but multiple items of this type ...
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
QgsPropertyCollection mDataDefinedProperties
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the object's property collection, used for data defined overrides.
const QgsLayout * layout() const
Returns the layout the object is attached to.
void changed()
Emitted when the object's properties change.
QPointer< QgsLayout > mLayout
DataDefinedProperty
Data defined properties for different item types.
@ ScalebarMinimumWidth
Scalebar segment minimum width.
@ ScalebarRightSegments
Number of segments on the right of 0.
@ ScalebarLineColor
Scalebar line color (deprecated, use data defined properties on scalebar line symbol instead)
@ ScalebarRightSegmentSubdivisions
Number of subdivisions per segment on right of 0.
@ ScalebarMaximumWidth
Scalebar segment maximum width.
@ ScalebarHeight
Scalebar height.
@ ScalebarFillColor2
Scalebar secondary fill color (deprecated, use data defined properties on scalebar fill symbol 2 inst...
@ ScalebarSubdivisionHeight
Scalebar subdivision height.
@ ScalebarFillColor
Scalebar fill color (deprecated, use data defined properties on scalebar fill symbol 1 instead)
@ ScalebarLineWidth
Scalebar line width (deprecated, use data defined properties on scalebar line symbol instead)
@ ScalebarLeftSegments
Number of segments on the left of 0.
@ ScalebarSegmentWidth
Scalebar width in map units of a single segment.
@ AllProperties
All properties for item.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
static QgsLayoutSize decodeSize(const QString &string)
Decodes a size from a string.
void setWidth(const double width)
Sets the width for the size.
Qgis::LayoutUnit units() const
Returns the units for the size.
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
static double calculatePrettySize(double minimumSize, double maximumSize)
Calculates a "pretty" size which falls between the range [minimumSize, maximumSize].
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
A line symbol type, for rendering LineString and MultiLineString geometries.
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
A class to represent a 2D point.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
A store for object properties.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
Abstract base class for scale bar renderers.
virtual bool applyDefaultSettings(QgsScaleBarSettings &settings) const
Applies any default settings relating to the scalebar to the passed settings object.
Qgis::ScaleBarAlignment alignment() const
Returns the scalebar alignment.
double subdivisionsHeight() const
Returns the scalebar subdivisions height (in millimeters) for segments included in the right part of ...
void setSubdivisionLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
Q_DECL_DEPRECATED QColor fillColor() const
Returns the color used for fills in the scalebar.
QgsLineSymbol * lineSymbol() const
Returns the line symbol used to render the scalebar (only used for some scalebar types).
QgsLineSymbol * subdivisionLineSymbol() const
Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
Q_DECL_DEPRECATED QColor fillColor2() const
Returns the secondary color used for fills in the scalebar.
void setAlternateFillSymbol(QgsFillSymbol *symbol)
Sets the secondary fill symbol used to render the scalebar (only used for some scalebar types).
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the scalebar.
Q_DECL_DEPRECATED void setFillColor(const QColor &color)
Sets the color used for fills in the scalebar.
int numberOfSegments() const
Returns the number of segments included in the scalebar.
Q_DECL_DEPRECATED void setFillColor2(const QColor &color)
Sets the secondary color used for fills in the scalebar.
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
Q_DECL_DEPRECATED void setLineCapStyle(Qt::PenCapStyle style)
Sets the cap style used when drawing the lines in the scalebar.
void setLabelHorizontalPlacement(Qgis::ScaleBarDistanceLabelHorizontalPlacement placement)
Sets the horizontal placement of text labels.
Qgis::ScaleBarDistanceLabelVerticalPlacement labelVerticalPlacement() const
Returns the vertical placement of text labels.
void setFillSymbol(QgsFillSymbol *symbol)
Sets the primary fill symbol used to render the scalebar (only used for some scalebar types).
double unitsPerSegment() const
Returns the number of scalebar units per segment.
Q_DECL_DEPRECATED void setLineJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the lines in the scalebar.
QgsTextFormat & textFormat()
Returns the text format used for drawing text in the scalebar.
Q_DECL_DEPRECATED QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
Q_DECL_DEPRECATED void setLineColor(const QColor &color)
Sets the color used for lines in the scalebar.
void setUnitLabel(const QString &label)
Sets the label for units.
void setLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar (only used for some scalebar types).
void setSegmentSizeMode(Qgis::ScaleBarSegmentSizeMode mode)
Sets the size mode for scale bar segments.
void setDivisionLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar divisions (only used for some scalebar types).
void setBoxContentSpace(double space)
Sets the space (margin) between the scalebar box and content in millimeters.
Q_DECL_DEPRECATED void setLineWidth(double width)
Sets the line width in millimeters for lines in the scalebar.
double boxContentSpace() const
Returns the spacing (margin) between the scalebar box and content in millimeters.
void setHeight(double height)
Sets the scalebar height (in millimeters).
QgsFillSymbol * alternateFillSymbol() const
Returns the secondary fill symbol used to render the scalebar (only used for some scalebar types).
Qgis::ScaleBarSegmentSizeMode segmentSizeMode() const
Returns the size mode for the scale bar segments.
void setLabelVerticalPlacement(Qgis::ScaleBarDistanceLabelVerticalPlacement placement)
Sets the vertical placement of text labels.
QgsFillSymbol * fillSymbol() const
Returns the primary fill symbol used to render the scalebar (only used for some scalebar types).
Q_DECL_DEPRECATED double lineWidth() const
Returns the line width in millimeters for lines in the scalebar.
Q_DECL_DEPRECATED QBrush brush2() const
Returns the secondary brush for the scalebar.
void setNumberOfSubdivisions(int subdivisions)
Sets the number of subdivisions for segments included in the right part of the scalebar (only used fo...
void setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for numbers in the scalebar.
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for drawing text in the scalebar.
double minimumBarWidth() const
Returns the minimum width (in millimeters) for scale bar segments.
QString unitLabel() const
Returns the label for units.
int numberOfSubdivisions() const
Returns the number of subdivisions for segments included in the right part of the scalebar (only used...
Qgis::ScaleBarDistanceLabelHorizontalPlacement labelHorizontalPlacement() const
Returns the horizontal placement of text labels.
Q_DECL_DEPRECATED QColor lineColor() const
Returns the color used for lines in the scalebar.
Qgis::DistanceUnit units() const
Returns the distance units used by the scalebar.
void setLabelBarSpace(double space)
Sets the spacing (in millimeters) between labels and the scalebar.
void setAlignment(Qgis::ScaleBarAlignment alignment)
Sets the scalebar alignment.
void setNumberOfSegments(int segments)
Sets the number of segments included in the scalebar.
void setUnitsPerSegment(double units)
Sets the number of scalebar units per segment.
Q_DECL_DEPRECATED Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
void setSubdivisionsHeight(double height)
Sets the scalebar subdivisions height (in millimeters) for segments included in the right part of the...
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
double height() const
Returns the scalebar height (in millimeters).
int numberOfSegmentsLeft() const
Returns the number of segments included in the left part of the scalebar.
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
Q_DECL_DEPRECATED Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
void setNumberOfSegmentsLeft(int segments)
Sets the number of segments included in the left part of the scalebar.
Q_DECL_DEPRECATED QBrush brush() const
Returns the primary brush used for filling the scalebar.
QgsLineSymbol * divisionLineSymbol() const
Returns the line symbol used to render the scalebar divisions (only used for some scalebar types).
void setMapUnitsPerScaleBarUnit(double units)
Sets the number of map units per scale bar unit used by the scalebar.
void setUnits(Qgis::DistanceUnit units)
Sets the distance units used by the scalebar.
double mapUnitsPerScaleBarUnit() const
Returns the number of map units per scale bar unit used by the scalebar.
void setMinimumBarWidth(double width)
Sets the minimum width (in millimeters) for scale bar segments.
void setMaximumBarWidth(double width)
Sets the maximum width (in millimeters) for scale bar segments.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
An interface for classes which can visit style entity (e.g.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
A text format entity for QgsStyle databases.
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
static Qt::PenCapStyle decodePenCapStyle(const QString &str)
static QString encodePenCapStyle(Qt::PenCapStyle style)
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
@ StrokeColor
Stroke color.
@ StrokeWidth
Stroke width.
bool changeSymbolLayer(int index, QgsSymbolLayer *layer)
Deletes the current layer at the specified index and replaces it with layer.
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setSize(double size)
Sets the size for rendered text.
void setFont(const QFont &font)
Sets the font used for rendering text.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units for the size of rendered text.
void setOpacity(double opacity)
Sets the text's opacity.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
double opacity() const
Returns the text's opacity.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
QColor color() const
Returns the color that text will be rendered in.
QFont font() const
Returns the font used for rendering text.
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static Q_INVOKABLE QString toAbbreviatedString(Qgis::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
static Q_INVOKABLE Qgis::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=nullptr)
Decodes a distance unit from a string.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
#define Q_NOWARN_DEPRECATED_POP
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
#define QgsDebugError(str)
const QgsCoordinateReferenceSystem & crs
Contains parameters regarding scalebar calculations.
Flags flags
Scalebar renderer flags.
QSizeF size
Destination size for scalebar.
double scale
Scale denominator.
bool isValid() const
Returns true if the context has valid settings.
double segmentWidth
The width, in millimeters, of each individual segment drawn.
Contains information relating to the style entity currently being visited.