39 #include <QDomDocument>
40 #include <QDomElement>
41 #include <QFontMetricsF>
83 std::unique_ptr< QgsLineSymbol > sym( mSettings.
lineSymbol()->
clone() );
96 std::unique_ptr< QgsFillSymbol > sym( mSettings.
fillSymbol()->
clone() );
113 mStyle->draw( context.
renderContext(), mSettings, createScaleContext() );
135 refreshSegmentMillimeters();
147 refreshSegmentMillimeters();
159 refreshSegmentMillimeters();
171 refreshSegmentMillimeters();
261 disconnectCurrentMap();
271 connect( mMap, &QObject::destroyed,
this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
273 refreshSegmentMillimeters();
277 void QgsLayoutItemScaleBar::disconnectCurrentMap()
285 disconnect( mMap, &QObject::destroyed,
this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
293 bool forceUpdate =
false;
320 void QgsLayoutItemScaleBar::refreshSegmentMillimeters()
325 QRectF composerItemRect = mMap->rect();
332 mSegmentMillimeters = composerItemRect.width() / mapWidth() * mSettings.
unitsPerSegment();
340 mSegmentMillimeters = 0;
346 double minUnitsPerSeg = ( mSettings.
minimumBarWidth() * mapWidth() ) / ( nSegments * composerItemRect.width() );
347 double maxUnitsPerSeg = ( mSettings.
maximumBarWidth() * mapWidth() ) / ( nSegments * composerItemRect.width() );
349 mSegmentMillimeters = composerItemRect.width() / mapWidth() * mSettings.
unitsPerSegment();
357 double QgsLayoutItemScaleBar::mapWidth()
const
367 return mapExtent.
width();
386 scaleContext.
size = rect().size();
388 scaleContext.
scale = mMap ? mMap->
scale() : 1.0;
389 scaleContext.
flags = mStyle->flags();
417 refreshSegmentMillimeters();
467 mStyle = qgis::make_unique< QgsSingleBoxScaleBarRenderer >();
474 QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
477 if ( !defaultFontString.isEmpty() )
479 f.setFamily( defaultFontString );
513 double widthInSelectedUnits = mapWidth();
514 double initialUnitsPerSegment = widthInSelectedUnits / 10.0;
519 if ( initialUnitsPerSegment > 1000.0 )
527 if ( initialUnitsPerSegment > 5419.95 )
545 double upperMagnitudeMultiplier = 1.0;
546 double widthInSelectedUnits = mapWidth();
547 double initialUnitsPerSegment = widthInSelectedUnits / 10.0;
551 upperMagnitudeMultiplier = 1;
553 double segmentWidth = initialUnitsPerSegment / upperMagnitudeMultiplier;
554 int segmentMagnitude = std::floor( std::log10( segmentWidth ) );
555 double unitsPerSegment = upperMagnitudeMultiplier * ( std::pow( 10.0, segmentMagnitude ) );
556 double multiplier = std::floor( ( widthInSelectedUnits / (
unitsPerSegment * 10.0 ) ) / 2.5 ) * 2.5;
558 if ( multiplier > 0 )
569 refreshSegmentMillimeters();
580 double widthMM = mStyle->calculateBoxSize( context, mSettings, createScaleContext() ).width();
591 if ( mStyle && mStyle->id() != QLatin1String(
"Numeric" ) )
595 QgsLayoutItem::update();
598 void QgsLayoutItemScaleBar::updateScale()
600 refreshSegmentMillimeters();
602 if ( mStyle && mStyle->id() != QLatin1String(
"Numeric" ) )
615 mStyle = std::move( renderer );
729 return mSettings.
pen();
736 return mSettings.
brush();
743 return mSettings.
brush2();
749 composerScaleBarElem.setAttribute( QStringLiteral(
"height" ), QString::number( mSettings.
height() ) );
750 composerScaleBarElem.setAttribute( QStringLiteral(
"labelBarSpace" ), QString::number( mSettings.
labelBarSpace() ) );
751 composerScaleBarElem.setAttribute( QStringLiteral(
"boxContentSpace" ), QString::number( mSettings.
boxContentSpace() ) );
752 composerScaleBarElem.setAttribute( QStringLiteral(
"numSegments" ), mSettings.
numberOfSegments() );
753 composerScaleBarElem.setAttribute( QStringLiteral(
"numSegmentsLeft" ), mSettings.
numberOfSegmentsLeft() );
754 composerScaleBarElem.setAttribute( QStringLiteral(
"numSubdivisions" ), mSettings.
numberOfSubdivisions() );
755 composerScaleBarElem.setAttribute( QStringLiteral(
"subdivisionsHeight" ), mSettings.
subdivisionsHeight() );
756 composerScaleBarElem.setAttribute( QStringLiteral(
"numUnitsPerSegment" ), QString::number( mSettings.
unitsPerSegment() ) );
757 composerScaleBarElem.setAttribute( QStringLiteral(
"segmentSizeMode" ), mSettings.
segmentSizeMode() );
758 composerScaleBarElem.setAttribute( QStringLiteral(
"minBarWidth" ), mSettings.
minimumBarWidth() );
759 composerScaleBarElem.setAttribute( QStringLiteral(
"maxBarWidth" ), mSettings.
maximumBarWidth() );
760 composerScaleBarElem.setAttribute( QStringLiteral(
"segmentMillimeters" ), QString::number( mSegmentMillimeters ) );
761 composerScaleBarElem.setAttribute( QStringLiteral(
"numMapUnitsPerScaleBarUnit" ), QString::number( mSettings.
mapUnitsPerScaleBarUnit() ) );
764 composerScaleBarElem.appendChild( textElem );
768 composerScaleBarElem.setAttribute( QStringLiteral(
"outlineWidth" ), QString::number( mSettings.
lineWidth() ) );
772 QDomElement strokeColorElem = doc.createElement( QStringLiteral(
"strokeColor" ) );
773 strokeColorElem.setAttribute( QStringLiteral(
"red" ), QString::number( mSettings.
lineColor().red() ) );
774 strokeColorElem.setAttribute( QStringLiteral(
"green" ), QString::number( mSettings.
lineColor().green() ) );
775 strokeColorElem.setAttribute( QStringLiteral(
"blue" ), QString::number( mSettings.
lineColor().blue() ) );
776 strokeColorElem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mSettings.
lineColor().alpha() ) );
777 composerScaleBarElem.appendChild( strokeColorElem );
780 composerScaleBarElem.setAttribute( QStringLiteral(
"unitLabel" ), mSettings.
unitLabel() );
783 QDomElement numericFormatElem = doc.createElement( QStringLiteral(
"numericFormat" ) );
785 composerScaleBarElem.appendChild( numericFormatElem );
790 composerScaleBarElem.setAttribute( QStringLiteral(
"style" ), mStyle->id() );
796 composerScaleBarElem.setAttribute( QStringLiteral(
"mapUuid" ), mMap->
uuid() );
805 QDomElement fillColorElem = doc.createElement( QStringLiteral(
"fillColor" ) );
806 fillColorElem.setAttribute( QStringLiteral(
"red" ), QString::number( mSettings.
fillColor().red() ) );
807 fillColorElem.setAttribute( QStringLiteral(
"green" ), QString::number( mSettings.
fillColor().green() ) );
808 fillColorElem.setAttribute( QStringLiteral(
"blue" ), QString::number( mSettings.
fillColor().blue() ) );
809 fillColorElem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mSettings.
fillColor().alpha() ) );
810 composerScaleBarElem.appendChild( fillColorElem );
813 QDomElement fillColor2Elem = doc.createElement( QStringLiteral(
"fillColor2" ) );
814 fillColor2Elem.setAttribute( QStringLiteral(
"red" ), QString::number( mSettings.
fillColor2().red() ) );
815 fillColor2Elem.setAttribute( QStringLiteral(
"green" ), QString::number( mSettings.
fillColor2().green() ) );
816 fillColor2Elem.setAttribute( QStringLiteral(
"blue" ), QString::number( mSettings.
fillColor2().blue() ) );
817 fillColor2Elem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mSettings.
fillColor2().alpha() ) );
818 composerScaleBarElem.appendChild( fillColor2Elem );
823 composerScaleBarElem.setAttribute( QStringLiteral(
"labelVerticalPlacement" ), QString::number(
static_cast< int >( mSettings.
labelVerticalPlacement() ) ) );
824 composerScaleBarElem.setAttribute( QStringLiteral(
"labelHorizontalPlacement" ), QString::number(
static_cast< int >( mSettings.
labelHorizontalPlacement() ) ) );
827 composerScaleBarElem.setAttribute( QStringLiteral(
"alignment" ), QString::number(
static_cast< int >( mSettings.
alignment() ) ) );
829 QDomElement
lineSymbol = doc.createElement( QStringLiteral(
"lineSymbol" ) );
835 composerScaleBarElem.appendChild(
lineSymbol );
837 QDomElement divisionSymbol = doc.createElement( QStringLiteral(
"divisionLineSymbol" ) );
842 divisionSymbol.appendChild( divisionSymbolElem );
843 composerScaleBarElem.appendChild( divisionSymbol );
845 QDomElement subdivisionSymbol = doc.createElement( QStringLiteral(
"subdivisionLineSymbol" ) );
850 subdivisionSymbol.appendChild( subdivisionSymbolElem );
851 composerScaleBarElem.appendChild( subdivisionSymbol );
853 QDomElement fillSymbol1Elem = doc.createElement( QStringLiteral(
"fillSymbol1" ) );
858 fillSymbol1Elem.appendChild( symbol1Elem );
859 composerScaleBarElem.appendChild( fillSymbol1Elem );
861 QDomElement fillSymbol2Elem = doc.createElement( QStringLiteral(
"fillSymbol2" ) );
866 fillSymbol2Elem.appendChild( symbol2Elem );
867 composerScaleBarElem.appendChild( fillSymbol2Elem );
874 mSettings.
setHeight( itemElem.attribute( QStringLiteral(
"height" ), QStringLiteral(
"5.0" ) ).toDouble() );
875 mSettings.
setLabelBarSpace( itemElem.attribute( QStringLiteral(
"labelBarSpace" ), QStringLiteral(
"3.0" ) ).toDouble() );
876 mSettings.
setBoxContentSpace( itemElem.attribute( QStringLiteral(
"boxContentSpace" ), QStringLiteral(
"1.0" ) ).toDouble() );
877 mSettings.
setNumberOfSegments( itemElem.attribute( QStringLiteral(
"numSegments" ), QStringLiteral(
"2" ) ).toInt() );
878 mSettings.
setNumberOfSegmentsLeft( itemElem.attribute( QStringLiteral(
"numSegmentsLeft" ), QStringLiteral(
"0" ) ).toInt() );
879 mSettings.
setNumberOfSubdivisions( itemElem.attribute( QStringLiteral(
"numSubdivisions" ), QStringLiteral(
"1" ) ).toInt() );
880 mSettings.
setSubdivisionsHeight( itemElem.attribute( QStringLiteral(
"subdivisionsHeight" ), QStringLiteral(
"1.5" ) ).toDouble() );
881 mSettings.
setUnitsPerSegment( itemElem.attribute( QStringLiteral(
"numUnitsPerSegment" ), QStringLiteral(
"1.0" ) ).toDouble() );
883 mSettings.
setMinimumBarWidth( itemElem.attribute( QStringLiteral(
"minBarWidth" ), QStringLiteral(
"50" ) ).toDouble() );
884 mSettings.
setMaximumBarWidth( itemElem.attribute( QStringLiteral(
"maxBarWidth" ), QStringLiteral(
"150" ) ).toDouble() );
885 mSegmentMillimeters = itemElem.attribute( QStringLiteral(
"segmentMillimeters" ), QStringLiteral(
"0.0" ) ).toDouble();
886 mSettings.
setMapUnitsPerScaleBarUnit( itemElem.attribute( QStringLiteral(
"numMapUnitsPerScaleBarUnit" ), QStringLiteral(
"1.0" ) ).toDouble() );
888 QDomElement lineSymbolElem = itemElem.firstChildElement( QStringLiteral(
"lineSymbol" ) );
889 bool foundLineSymbol =
false;
890 if ( !lineSymbolElem.isNull() )
892 QDomElement symbolElem = lineSymbolElem.firstChildElement( QStringLiteral(
"symbol" ) );
893 std::unique_ptr< QgsLineSymbol >
lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
897 foundLineSymbol =
true;
900 QDomElement divisionSymbolElem = itemElem.firstChildElement( QStringLiteral(
"divisionLineSymbol" ) );
901 if ( !divisionSymbolElem.isNull() )
903 QDomElement symbolElem = divisionSymbolElem.firstChildElement( QStringLiteral(
"symbol" ) );
904 std::unique_ptr< QgsLineSymbol >
lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
910 else if ( foundLineSymbol )
914 QDomElement subdivisionSymbolElem = itemElem.firstChildElement( QStringLiteral(
"subdivisionLineSymbol" ) );
915 if ( !subdivisionSymbolElem.isNull() )
917 QDomElement symbolElem = subdivisionSymbolElem.firstChildElement( QStringLiteral(
"symbol" ) );
918 std::unique_ptr< QgsLineSymbol >
lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
924 else if ( foundLineSymbol )
929 if ( !foundLineSymbol )
932 std::unique_ptr< QgsLineSymbol >
lineSymbol = qgis::make_unique< QgsLineSymbol >();
933 std::unique_ptr< QgsSimpleLineSymbolLayer > lineSymbolLayer = qgis::make_unique< QgsSimpleLineSymbolLayer >();
934 lineSymbolLayer->setWidth( itemElem.attribute( QStringLiteral(
"outlineWidth" ), QStringLiteral(
"0.3" ) ).toDouble() );
940 QDomNodeList strokeColorList = itemElem.elementsByTagName( QStringLiteral(
"strokeColor" ) );
941 if ( !strokeColorList.isEmpty() )
943 QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
944 bool redOk, greenOk, blueOk, alphaOk;
945 int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
947 strokeRed = strokeColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
948 strokeGreen = strokeColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
949 strokeBlue = strokeColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
950 strokeAlpha = strokeColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
952 if ( redOk && greenOk && blueOk && alphaOk )
954 lineSymbolLayer->setColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) );
959 lineSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral(
"penColor" ), QStringLiteral(
"#000000" ) ) ) );
975 mSettings.
setUnitLabel( itemElem.attribute( QStringLiteral(
"unitLabel" ) ) );
977 QDomNodeList textFormatNodeList = itemElem.elementsByTagName( QStringLiteral(
"text-style" ) );
978 if ( !textFormatNodeList.isEmpty() )
980 QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
988 f.fromString( itemElem.attribute( QStringLiteral(
"font" ), QString() ) );
991 if ( f.pointSizeF() > 0 )
996 else if ( f.pixelSize() > 0 )
1003 QDomNodeList numericFormatNodeList = itemElem.elementsByTagName( QStringLiteral(
"numericFormat" ) );
1004 if ( !numericFormatNodeList.isEmpty() )
1006 QDomElement numericFormatElem = numericFormatNodeList.at( 0 ).toElement();
1010 QDomElement fillSymbol1Elem = itemElem.firstChildElement( QStringLiteral(
"fillSymbol1" ) );
1011 bool foundFillSymbol1 =
false;
1012 if ( !fillSymbol1Elem.isNull() )
1014 QDomElement symbolElem = fillSymbol1Elem.firstChildElement( QStringLiteral(
"symbol" ) );
1015 std::unique_ptr< QgsFillSymbol >
fillSymbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context ) );
1019 foundFillSymbol1 =
true;
1022 if ( !foundFillSymbol1 )
1025 std::unique_ptr< QgsFillSymbol >
fillSymbol = qgis::make_unique< QgsFillSymbol >();
1026 std::unique_ptr< QgsSimpleFillSymbolLayer > fillSymbolLayer = qgis::make_unique< QgsSimpleFillSymbolLayer >();
1027 fillSymbolLayer->setStrokeStyle( Qt::NoPen );
1030 QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral(
"fillColor" ) );
1031 if ( !fillColorList.isEmpty() )
1033 QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
1034 bool redOk, greenOk, blueOk, alphaOk;
1035 int fillRed, fillGreen, fillBlue, fillAlpha;
1037 fillRed = fillColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1038 fillGreen = fillColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1039 fillBlue = fillColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1040 fillAlpha = fillColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1042 if ( redOk && greenOk && blueOk && alphaOk )
1044 fillSymbolLayer->setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1049 fillSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral(
"brushColor" ), QStringLiteral(
"#000000" ) ) ) );
1061 QDomElement fillSymbol2Elem = itemElem.firstChildElement( QStringLiteral(
"fillSymbol2" ) );
1062 bool foundFillSymbol2 =
false;
1063 if ( !fillSymbol2Elem.isNull() )
1065 QDomElement symbolElem = fillSymbol2Elem.firstChildElement( QStringLiteral(
"symbol" ) );
1066 std::unique_ptr< QgsFillSymbol >
fillSymbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context ) );
1070 foundFillSymbol2 =
true;
1073 if ( !foundFillSymbol2 )
1076 std::unique_ptr< QgsFillSymbol >
fillSymbol = qgis::make_unique< QgsFillSymbol >();
1077 std::unique_ptr< QgsSimpleFillSymbolLayer > fillSymbolLayer = qgis::make_unique< QgsSimpleFillSymbolLayer >();
1078 fillSymbolLayer->setStrokeStyle( Qt::NoPen );
1082 QDomNodeList fillColor2List = itemElem.elementsByTagName( QStringLiteral(
"fillColor2" ) );
1083 if ( !fillColor2List.isEmpty() )
1085 QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
1086 bool redOk, greenOk, blueOk, alphaOk;
1087 int fillRed, fillGreen, fillBlue, fillAlpha;
1089 fillRed = fillColor2Elem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1090 fillGreen = fillColor2Elem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1091 fillBlue = fillColor2Elem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1092 fillAlpha = fillColor2Elem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1094 if ( redOk && greenOk && blueOk && alphaOk )
1096 fillSymbolLayer->setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1101 fillSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral(
"brush2Color" ), QStringLiteral(
"#ffffff" ) ) ) );
1115 QDomNodeList textColorList = itemElem.elementsByTagName( QStringLiteral(
"textColor" ) );
1116 if ( !textColorList.isEmpty() )
1118 QDomElement textColorElem = textColorList.at( 0 ).toElement();
1119 bool redOk, greenOk, blueOk, alphaOk;
1120 int textRed, textGreen, textBlue, textAlpha;
1122 textRed = textColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1123 textGreen = textColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1124 textBlue = textColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1125 textAlpha = textColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1127 if ( redOk && greenOk && blueOk && alphaOk )
1129 mSettings.
textFormat().
setColor( QColor( textRed, textGreen, textBlue, textAlpha ) );
1132 else if ( itemElem.hasAttribute( QStringLiteral(
"fontColor" ) ) )
1135 c.setNamedColor( itemElem.attribute( QStringLiteral(
"fontColor" ), QStringLiteral(
"#000000" ) ) );
1140 setStyle( itemElem.attribute( QStringLiteral(
"style" ), QString() ) );
1145 if ( itemElem.attribute( QStringLiteral(
"unitType" ) ).isEmpty() )
1148 switch ( itemElem.attribute( QStringLiteral(
"units" ) ).toInt() )
1176 disconnectCurrentMap();
1178 mMapUuid = itemElem.attribute( QStringLiteral(
"mapUuid" ) );
1185 if (
mLayout && !mMapUuid.isEmpty() )
1187 disconnectCurrentMap();
1188 mMap = qobject_cast< QgsLayoutItemMap * >(
mLayout->itemByUuid( mMapUuid,
true ) );
1192 connect( mMap, &QObject::destroyed,
this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
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.
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)
Helper to get a theme icon.
This class represents a coordinate reference system (CRS).
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
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.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
QgsUnitTypes::DistanceUnit lengthUnits() const
Returns the units of distance for length calculations made by this object.
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.
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.
void setLabelHorizontalPlacement(QgsScaleBarSettings::LabelHorizontalPlacement placement)
Sets the horizontal placement of text labels.
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.
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 setSegmentSizeMode(QgsScaleBarSettings::SegmentSizeMode mode)
Sets the size mode for scale bar segments.
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).
void setLabelVerticalPlacement(QgsScaleBarSettings::LabelVerticalPlacement placement)
Sets the vertical placement of text labels.
double unitsPerSegment() const
Returns the number of scalebar units per segment.
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.
void setUnits(QgsUnitTypes::DistanceUnit units)
Sets the distance units used by the scalebar.
QgsLineSymbol * subdivisionLineSymbol() const
Returns the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
QgsUnitTypes::DistanceUnit guessUnits() const
Attempts to guess the most reasonable unit choice for the scalebar, given the current linked map's sc...
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 setAlignment(QgsScaleBarSettings::Alignment alignment)
Sets the scalebar alignment.
void setAlternateFillSymbol(QgsFillSymbol *symbol)
Sets the secondary fill symbol used to render the scalebar (only used for some scalebar types).
void applyDefaultSize(QgsUnitTypes::DistanceUnit units=QgsUnitTypes::DistanceMeters)
Applies the default size to the scale bar (scale bar 1/5 of map item width)
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.
Q_DECL_DEPRECATED Qt::PenCapStyle lineCapStyle() const
Returns the cap 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 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 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.
QgsLineSymbol * lineSymbol() const
Returns the line symbol used to render the scalebar (only used for some scalebar types).
void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties) override
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
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.
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
void setSubdivisionLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
QgsUnitTypes::DistanceUnit units() const
Returns the distance units used by the scalebar.
QgsLayoutItemScaleBar(QgsLayout *layout)
Constructor for QgsLayoutItemScaleBar, with the specified parent layout.
Base class for graphical items within a QgsLayout.
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 void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
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
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.
@ ScalebarFillColor2
Scalebar secondary fill color (deprecated, use data defined properties on scalebar fill symbol 2 inst...
@ ScalebarLineWidth
Scalebar line width (deprecated, use data defined properties on scalebar line symbol instead)
@ AllProperties
All properties for item.
@ ScalebarFillColor
Scalebar fill color (deprecated, use data defined properties on scalebar fill symbol 1 instead)
@ ScalebarLineColor
Scalebar line color (deprecated, use data defined properties on scalebar line symbol instead)
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the object's property collection, used for data defined overrides.
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.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the size.
void setWidth(const double width)
Sets the width 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.
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.
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.
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Contains information about the context of a rendering 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.
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).
void setAlignment(Alignment alignment)
Sets the scalebar alignment.
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).
SegmentSizeMode segmentSizeMode() const
Returns the size mode for the scale bar segments.
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.
QgsUnitTypes::DistanceUnit units() const
Returns the distance units used by the scalebar.
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.
Q_DECL_DEPRECATED QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
void setLabelVerticalPlacement(LabelVerticalPlacement placement)
Sets the vertical placement of text labels.
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.
LabelHorizontalPlacement labelHorizontalPlacement() const
Returns the horizontal placement of text labels.
void setLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar (only used for some scalebar types).
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.
Alignment alignment() const
Returns the scalebar alignment.
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).
void setUnits(QgsUnitTypes::DistanceUnit units)
Sets the distance units used by the scalebar.
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.
Alignment
Scalebar alignment.
void setNumberOfSubdivisions(int subdivisions)
Sets the number of subdivisions for segments included in the right part of the scalebar (only used fo...
LabelVerticalPlacement labelVerticalPlacement() const
Returns the vertical placement of text labels.
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...
Q_DECL_DEPRECATED QColor lineColor() const
Returns the color used for lines in the scalebar.
LabelHorizontalPlacement
Label horizontal placement.
void setLabelBarSpace(double space)
Sets the spacing (in millimeters) between labels and the scalebar.
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.
LabelVerticalPlacement
Label vertical placement.
Q_DECL_DEPRECATED Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
void setLabelHorizontalPlacement(LabelHorizontalPlacement placement)
Sets the horizontal placement of text labels.
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.
QgsTextFormat & textFormat()
Returns the text format used for drawing text in 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.
SegmentSizeMode
Modes for setting size for scale bar segments.
@ SegmentSizeFitWidth
Scale bar segment size is calculated to fit a size range.
@ SegmentSizeFixed
Scale bar segment size is fixed to a map unit.
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.
void setSegmentSizeMode(SegmentSizeMode mode)
Sets the size mode for scale bar segments.
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.
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)
@ PropertyStrokeWidth
Stroke width.
@ PropertyFillColor
Fill color.
@ PropertyStrokeColor
Stroke color.
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 setOpacity(double opacity)
Sets the text's opacity.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the size of rendered text.
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.
DistanceUnit
Units of distance.
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
@ DistanceKilometers
Kilometers.
@ DistanceMiles
Terrestrial miles.
@ DistanceUnknownUnit
Unknown distance unit.
@ DistanceFeet
Imperial feet.
@ DistanceNauticalMiles
Nautical miles.
@ LayoutMillimeters
Millimeters.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
static Q_INVOKABLE QgsUnitTypes::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=nullptr)
Decodes a distance unit from a string.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static Q_INVOKABLE QString toAbbreviatedString(QgsUnitTypes::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
@ RenderPoints
Points (e.g., for font sizes)
@ RenderMillimeters
Millimeters.
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
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
const QgsCoordinateReferenceSystem & crs
Contains parameters regarding scalebar calculations.
Flags flags
Scalebar renderer flags.
QSizeF size
Destination size for scalebar.
double scale
Scale denominator.
double segmentWidth
The width, in millimeters, of each individual segment drawn.
Contains information relating to the style entity currently being visited.