36 #include <QDomDocument> 37 #include <QDomElement> 38 #include <QFontMetricsF> 75 mStyle->draw( context.
renderContext(), mSettings, createScaleContext() );
97 refreshSegmentMillimeters();
109 refreshSegmentMillimeters();
121 refreshSegmentMillimeters();
133 refreshSegmentMillimeters();
173 disconnectCurrentMap();
183 connect( mMap, &QObject::destroyed,
this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
185 refreshSegmentMillimeters();
189 void QgsLayoutItemScaleBar::disconnectCurrentMap()
197 disconnect( mMap, &QObject::destroyed,
this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
205 bool forceUpdate =
false;
209 QBrush b = mSettings.
brush();
216 QBrush b = mSettings.
brush2();
223 QPen p = mSettings.
pen();
230 QPen p = mSettings.
pen();
247 double s = std::pow( 10.0, std::floor( std::log10( a ) ) ) / d;
248 return std::ceil( a / s ) * s;
254 double s = std::pow( 10.0, std::floor( std::log10( a ) ) ) / d;
255 return std::floor( a / s ) * s;
258 void QgsLayoutItemScaleBar::refreshSegmentMillimeters()
263 QRectF composerItemRect = mMap->rect();
268 mSegmentMillimeters = composerItemRect.width() / mapWidth() * mSettings.
unitsPerSegment();
274 mSegmentMillimeters = 0;
280 double minUnitsPerSeg = ( mSettings.
minimumBarWidth() * mapWidth() ) / ( nSegments * composerItemRect.width() );
281 double maxUnitsPerSeg = ( mSettings.
maximumBarWidth() * mapWidth() ) / ( nSegments * composerItemRect.width() );
291 while ( lowerNiceUnitsPerSeg > maxUnitsPerSeg && upperNiceUnitsPerSeg < minUnitsPerSeg )
299 mSettings.
setUnitsPerSegment( upperNiceUnitsPerSeg < minUnitsPerSeg ? lowerNiceUnitsPerSeg : upperNiceUnitsPerSeg );
300 mSegmentMillimeters = composerItemRect.width() / mapWidth() * mSettings.
unitsPerSegment();
306 double QgsLayoutItemScaleBar::mapWidth()
const 316 return mapExtent.
width();
335 scaleContext.
size = rect().size();
337 scaleContext.
scale = mMap ? mMap->
scale() : 1.0;
351 refreshSegmentMillimeters();
383 mStyle = qgis::make_unique< QgsSingleBoxScaleBarRenderer >();
390 QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
393 if ( !defaultFontString.isEmpty() )
395 f.setFamily( defaultFontString );
424 double widthInSelectedUnits = mapWidth();
425 double initialUnitsPerSegment = widthInSelectedUnits / 10.0;
430 if ( initialUnitsPerSegment > 1000.0 )
438 if ( initialUnitsPerSegment > 5419.95 )
456 double upperMagnitudeMultiplier = 1.0;
457 double widthInSelectedUnits = mapWidth();
458 double initialUnitsPerSegment = widthInSelectedUnits / 10.0;
462 upperMagnitudeMultiplier = 1;
464 double segmentWidth = initialUnitsPerSegment / upperMagnitudeMultiplier;
465 int segmentMagnitude = std::floor( std::log10( segmentWidth ) );
466 double unitsPerSegment = upperMagnitudeMultiplier * ( std::pow( 10.0, segmentMagnitude ) );
467 double multiplier = std::floor( ( widthInSelectedUnits / ( unitsPerSegment * 10.0 ) ) / 2.5 ) * 2.5;
469 if ( multiplier > 0 )
471 unitsPerSegment = unitsPerSegment * multiplier;
480 refreshSegmentMillimeters();
490 double widthMM = mStyle->calculateBoxSize( mSettings, createScaleContext() ).width();
501 if ( mStyle && mStyle->name() != QLatin1String(
"Numeric" ) )
505 QgsLayoutItem::update();
508 void QgsLayoutItemScaleBar::updateScale()
510 refreshSegmentMillimeters();
518 if ( styleName == QLatin1String(
"Single Box" ) )
520 mStyle = qgis::make_unique< QgsSingleBoxScaleBarRenderer >();
522 else if ( styleName == QLatin1String(
"Double Box" ) )
524 mStyle = qgis::make_unique< QgsDoubleBoxScaleBarRenderer >();
526 else if ( styleName == QLatin1String(
"Line Ticks Middle" ) || styleName == QLatin1String(
"Line Ticks Down" ) || styleName == QLatin1String(
"Line Ticks Up" ) )
528 std::unique_ptr< QgsTicksScaleBarRenderer > tickStyle = qgis::make_unique< QgsTicksScaleBarRenderer >();
529 if ( styleName == QLatin1String(
"Line Ticks Middle" ) )
533 else if ( styleName == QLatin1String(
"Line Ticks Down" ) )
537 else if ( styleName == QLatin1String(
"Line Ticks Up" ) )
541 mStyle = std::move( tickStyle );
543 else if ( styleName == QLatin1String(
"Numeric" ) )
545 mStyle = qgis::make_unique< QgsNumericScaleBarRenderer >();
555 return mStyle->name();
592 composerScaleBarElem.setAttribute( QStringLiteral(
"height" ), QString::number( mSettings.
height() ) );
593 composerScaleBarElem.setAttribute( QStringLiteral(
"labelBarSpace" ), QString::number( mSettings.
labelBarSpace() ) );
594 composerScaleBarElem.setAttribute( QStringLiteral(
"boxContentSpace" ), QString::number( mSettings.
boxContentSpace() ) );
595 composerScaleBarElem.setAttribute( QStringLiteral(
"numSegments" ), mSettings.
numberOfSegments() );
596 composerScaleBarElem.setAttribute( QStringLiteral(
"numSegmentsLeft" ), mSettings.
numberOfSegmentsLeft() );
597 composerScaleBarElem.setAttribute( QStringLiteral(
"numUnitsPerSegment" ), QString::number( mSettings.
unitsPerSegment() ) );
598 composerScaleBarElem.setAttribute( QStringLiteral(
"segmentSizeMode" ), mSettings.
segmentSizeMode() );
599 composerScaleBarElem.setAttribute( QStringLiteral(
"minBarWidth" ), mSettings.
minimumBarWidth() );
600 composerScaleBarElem.setAttribute( QStringLiteral(
"maxBarWidth" ), mSettings.
maximumBarWidth() );
601 composerScaleBarElem.setAttribute( QStringLiteral(
"segmentMillimeters" ), QString::number( mSegmentMillimeters ) );
602 composerScaleBarElem.setAttribute( QStringLiteral(
"numMapUnitsPerScaleBarUnit" ), QString::number( mSettings.
mapUnitsPerScaleBarUnit() ) );
605 composerScaleBarElem.appendChild( textElem );
607 composerScaleBarElem.setAttribute( QStringLiteral(
"outlineWidth" ), QString::number( mSettings.
lineWidth() ) );
608 composerScaleBarElem.setAttribute( QStringLiteral(
"unitLabel" ), mSettings.
unitLabel() );
616 composerScaleBarElem.setAttribute( QStringLiteral(
"style" ), mStyle->name() );
622 composerScaleBarElem.setAttribute( QStringLiteral(
"mapUuid" ), mMap->
uuid() );
628 QDomElement fillColorElem = doc.createElement( QStringLiteral(
"fillColor" ) );
629 fillColorElem.setAttribute( QStringLiteral(
"red" ), QString::number( mSettings.
fillColor().red() ) );
630 fillColorElem.setAttribute( QStringLiteral(
"green" ), QString::number( mSettings.
fillColor().green() ) );
631 fillColorElem.setAttribute( QStringLiteral(
"blue" ), QString::number( mSettings.
fillColor().blue() ) );
632 fillColorElem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mSettings.
fillColor().alpha() ) );
633 composerScaleBarElem.appendChild( fillColorElem );
636 QDomElement fillColor2Elem = doc.createElement( QStringLiteral(
"fillColor2" ) );
637 fillColor2Elem.setAttribute( QStringLiteral(
"red" ), QString::number( mSettings.
fillColor2().red() ) );
638 fillColor2Elem.setAttribute( QStringLiteral(
"green" ), QString::number( mSettings.
fillColor2().green() ) );
639 fillColor2Elem.setAttribute( QStringLiteral(
"blue" ), QString::number( mSettings.
fillColor2().blue() ) );
640 fillColor2Elem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mSettings.
fillColor2().alpha() ) );
641 composerScaleBarElem.appendChild( fillColor2Elem );
644 QDomElement strokeColorElem = doc.createElement( QStringLiteral(
"strokeColor" ) );
645 strokeColorElem.setAttribute( QStringLiteral(
"red" ), QString::number( mSettings.
lineColor().red() ) );
646 strokeColorElem.setAttribute( QStringLiteral(
"green" ), QString::number( mSettings.
lineColor().green() ) );
647 strokeColorElem.setAttribute( QStringLiteral(
"blue" ), QString::number( mSettings.
lineColor().blue() ) );
648 strokeColorElem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mSettings.
lineColor().alpha() ) );
649 composerScaleBarElem.appendChild( strokeColorElem );
652 composerScaleBarElem.setAttribute( QStringLiteral(
"alignment" ), QString::number( static_cast< int >( mSettings.
alignment() ) ) );
659 mSettings.
setHeight( itemElem.attribute( QStringLiteral(
"height" ), QStringLiteral(
"5.0" ) ).toDouble() );
660 mSettings.
setLabelBarSpace( itemElem.attribute( QStringLiteral(
"labelBarSpace" ), QStringLiteral(
"3.0" ) ).toDouble() );
661 mSettings.
setBoxContentSpace( itemElem.attribute( QStringLiteral(
"boxContentSpace" ), QStringLiteral(
"1.0" ) ).toDouble() );
662 mSettings.
setNumberOfSegments( itemElem.attribute( QStringLiteral(
"numSegments" ), QStringLiteral(
"2" ) ).toInt() );
663 mSettings.
setNumberOfSegmentsLeft( itemElem.attribute( QStringLiteral(
"numSegmentsLeft" ), QStringLiteral(
"0" ) ).toInt() );
664 mSettings.
setUnitsPerSegment( itemElem.attribute( QStringLiteral(
"numUnitsPerSegment" ), QStringLiteral(
"1.0" ) ).toDouble() );
665 mSettings.
setSegmentSizeMode( static_cast<QgsScaleBarSettings::SegmentSizeMode>( itemElem.attribute( QStringLiteral(
"segmentSizeMode" ), QStringLiteral(
"0" ) ).toInt() ) );
666 mSettings.
setMinimumBarWidth( itemElem.attribute( QStringLiteral(
"minBarWidth" ), QStringLiteral(
"50" ) ).toDouble() );
667 mSettings.
setMaximumBarWidth( itemElem.attribute( QStringLiteral(
"maxBarWidth" ), QStringLiteral(
"150" ) ).toDouble() );
668 mSegmentMillimeters = itemElem.attribute( QStringLiteral(
"segmentMillimeters" ), QStringLiteral(
"0.0" ) ).toDouble();
669 mSettings.
setMapUnitsPerScaleBarUnit( itemElem.attribute( QStringLiteral(
"numMapUnitsPerScaleBarUnit" ), QStringLiteral(
"1.0" ) ).toDouble() );
670 mSettings.
setLineWidth( itemElem.attribute( QStringLiteral(
"outlineWidth" ), QStringLiteral(
"0.3" ) ).toDouble() );
671 mSettings.
setUnitLabel( itemElem.attribute( QStringLiteral(
"unitLabel" ) ) );
675 QDomNodeList textFormatNodeList = itemElem.elementsByTagName( QStringLiteral(
"text-style" ) );
676 if ( !textFormatNodeList.isEmpty() )
678 QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
686 f.fromString( itemElem.attribute( QStringLiteral(
"font" ), QLatin1String(
"" ) ) );
689 if ( f.pointSizeF() > 0 )
694 else if ( f.pixelSize() > 0 )
703 QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral(
"fillColor" ) );
704 if ( !fillColorList.isEmpty() )
706 QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
707 bool redOk, greenOk, blueOk, alphaOk;
708 int fillRed, fillGreen, fillBlue, fillAlpha;
710 fillRed = fillColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
711 fillGreen = fillColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
712 fillBlue = fillColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
713 fillAlpha = fillColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
715 if ( redOk && greenOk && blueOk && alphaOk )
717 mSettings.
setFillColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
722 mSettings.
setFillColor( QColor( itemElem.attribute( QStringLiteral(
"brushColor" ), QStringLiteral(
"#000000" ) ) ) );
726 QDomNodeList fillColor2List = itemElem.elementsByTagName( QStringLiteral(
"fillColor2" ) );
727 if ( !fillColor2List.isEmpty() )
729 QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
730 bool redOk, greenOk, blueOk, alphaOk;
731 int fillRed, fillGreen, fillBlue, fillAlpha;
733 fillRed = fillColor2Elem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
734 fillGreen = fillColor2Elem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
735 fillBlue = fillColor2Elem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
736 fillAlpha = fillColor2Elem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
738 if ( redOk && greenOk && blueOk && alphaOk )
740 mSettings.
setFillColor2( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
745 mSettings.
setFillColor2( QColor( itemElem.attribute( QStringLiteral(
"brush2Color" ), QStringLiteral(
"#ffffff" ) ) ) );
749 QDomNodeList strokeColorList = itemElem.elementsByTagName( QStringLiteral(
"strokeColor" ) );
750 if ( !strokeColorList.isEmpty() )
752 QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
753 bool redOk, greenOk, blueOk, alphaOk;
754 int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
756 strokeRed = strokeColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
757 strokeGreen = strokeColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
758 strokeBlue = strokeColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
759 strokeAlpha = strokeColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
761 if ( redOk && greenOk && blueOk && alphaOk )
763 mSettings.
setLineColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) );
764 QPen p = mSettings.
pen();
771 mSettings.
setLineColor( QColor( itemElem.attribute( QStringLiteral(
"penColor" ), QStringLiteral(
"#000000" ) ) ) );
772 QPen p = mSettings.
pen();
778 QDomNodeList textColorList = itemElem.elementsByTagName( QStringLiteral(
"textColor" ) );
779 if ( !textColorList.isEmpty() )
781 QDomElement textColorElem = textColorList.at( 0 ).toElement();
782 bool redOk, greenOk, blueOk, alphaOk;
783 int textRed, textGreen, textBlue, textAlpha;
785 textRed = textColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
786 textGreen = textColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
787 textBlue = textColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
788 textAlpha = textColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
790 if ( redOk && greenOk && blueOk && alphaOk )
795 else if ( itemElem.hasAttribute( QStringLiteral(
"fontColor" ) ) )
798 c.setNamedColor( itemElem.attribute( QStringLiteral(
"fontColor" ), QStringLiteral(
"#000000" ) ) );
803 QString styleString = itemElem.attribute( QStringLiteral(
"style" ), QLatin1String(
"" ) );
804 setStyle( styleString.toLocal8Bit().data() );
806 if ( itemElem.attribute( QStringLiteral(
"unitType" ) ).isEmpty() )
809 switch ( itemElem.attribute( QStringLiteral(
"units" ) ).toInt() )
830 mSettings.
setAlignment( static_cast< QgsScaleBarSettings::Alignment >( itemElem.attribute( QStringLiteral(
"alignment" ), QStringLiteral(
"0" ) ).toInt() ) );
833 disconnectCurrentMap();
835 mMapUuid = itemElem.attribute( QStringLiteral(
"mapUuid" ) );
842 if (
mLayout && !mMapUuid.isEmpty() )
844 disconnectCurrentMap();
849 connect( mMap, &QObject::destroyed,
this, &QgsLayoutItemScaleBar::disconnectCurrentMap );
QgsUnitTypes::DistanceUnit guessUnits() const
Attempts to guess the most reasonable unit choice for the scalebar, given the current linked map's sc...
QgsUnitTypes::DistanceUnit lengthUnits() const
Returns the units of distance for length calculations made by this object.
The class is used as a container of context for various read/write operations on other objects...
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...
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void setMinimumBarWidth(double width)
Sets the minimum width (in millimeters) for scale bar segments.
A rectangle specified with double values.
double mapUnitsPerScaleBarUnit() const
Returns the number of map units per scale bar unit used by the scalebar.
QBrush brush() const
Returns the primary brush used for filling the scalebar.
QString style() const
Returns the scale bar style name.
void setOpacity(double opacity)
Sets the text's opacity.
void setLineColor(const QColor &color)
Sets the color used for lines in the scalebar.
void setLineJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the lines in the scalebar.
double opacity() const
Returns the text's opacity.
Base class for graphical items within a QgsLayout.
QgsLayoutSize minimumSize() const override
Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely r...
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QString unitLabel() const
Returns the label for units.
Q_DECL_DEPRECATED QFont font() const
Returns the font used for drawing text in the scalebar.
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...
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...
This class is a composition of two QSettings instances:
QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
double segmentWidth
The width, in millimeters, of each individual segment drawn.
Alignment alignment() const
Returns the scalebar alignment.
void setPen(const QPen &pen)
Sets the pen used for drawing outlines in the scalebar.
Q_DECL_DEPRECATED void setFontColor(const QColor &color)
Sets the color used for drawing text in the scalebar.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QColor fillColor2() const
Returns the secondary color used for fills in the scalebar.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map item linked to the scalebar.
A class to represent a 2D point.
void extentChanged()
Is emitted when the map's extent changes.
SegmentSizeMode segmentSizeMode() const
Returns the size mode for the scale bar segments.
void setBoxContentSpace(double space)
Sets the space (margin) between the scalebar box and content in millimeters.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
void setLineCapStyle(Qt::PenCapStyle style)
Sets the cap style used when drawing the lines in the scalebar.
void setFont(const QFont &font)
Sets the font used for rendering text.
double lineWidth() const
Returns the line width in millimeters for lines in the scalebar.
#define Q_NOWARN_DEPRECATED_PUSH
QColor color() const
Returns the color that text will be rendered in.
Alignment
Scalebar alignment.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void update()
Adjusts the scale bar box size and updates the item.
QgsUnitTypes::DistanceUnit mapUnits
void setAlignment(QgsScaleBarSettings::Alignment alignment)
Sets the scalebar alignment.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
QColor lineColor() const
Returns the color used for lines in the scalebar.
static Q_INVOKABLE QgsUnitTypes::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=nullptr)
Decodes a distance unit from a string.
void setSegmentSizeMode(QgsScaleBarSettings::SegmentSizeMode mode)
Sets the size mode for scale bar segments.
void setStyle(const QString &name)
Sets the scale bar style by name.
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...
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
QColor fillColor() const
Returns the color used for fills in the scalebar.
int type() const override
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
void refreshItemSize()
Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes...
double height() const
Returns the scalebar height (in millimeters).
void setMaximumBarWidth(double maxWidth)
Sets the maximum width (in millimeters) for scale bar segments.
void setFillColor(const QColor &color)
Sets the color used for fills in the scalebar.
QgsRectangle extent() const
Returns the current map extent.
Layout graphical items for displaying a map.
static Q_INVOKABLE QString toAbbreviatedString(QgsUnitTypes::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
int numberOfSegments() const
Returns the number of segments included in the scalebar.
double scale
Scale denominator.
void setSize(double size)
Sets the size for rendered text.
Scalebar secondary fill color.
QgsPropertyCollection mDataDefinedProperties
const QgsLayout * layout() const
Returns the layout the object is attached to.
void setNumberOfSegments(int segments)
Sets the number of segments included in the scalebar.
double minimumBarWidth() const
Returns the minimum width (in millimeters) for scale bar segments.
void setLineCapStyle(Qt::PenCapStyle style)
Sets the cap style used when drawing the lines in the scalebar.
void resizeToMinimumWidth()
Resizes the scale bar to its minimum width, without changing the height.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
void setMapUnitsPerScaleBarUnit(double units)
Sets the number of map units per scale bar unit used by the scalebar.
QSizeF size
Destination size for scalebar.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
void setAlignment(Alignment alignment)
Sets the scalebar alignment.
QgsUnitTypes::DistanceUnit units() const
Returns the distance units used by the scalebar.
double width() const
Returns the width of the rectangle.
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
double boxContentSpace() const
Returns the spacing (margin) between the scalebar box and content in millimeters. ...
void setMinimumBarWidth(double minWidth)
Sets the minimum width (in millimeters) for scale bar segments.
double labelBarSpace() const
Returns the spacing (in millimeters) between labels and the scalebar.
QPointer< QgsLayout > mLayout
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setMaximumBarWidth(double width)
Sets the maximum width (in millimeters) for scale bar segments.
Degrees, for planar geographic CRS distance measurements.
void setBoxContentSpace(double space)
Sets the space (margin) between the scalebar box and content in millimeters.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the size of rendered text.
void setUnitsPerSegment(double units)
Sets the number of scalebar units per segment.
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.
void setSegmentSizeMode(SegmentSizeMode mode)
Sets the size mode for scale bar segments.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the size.
static Qt::PenCapStyle decodePenCapStyle(const QString &str)
double unitsPerSegment() const
Returns the number of scalebar units per segment.
void setFillColor2(const QColor &color)
Sets the secondary color used for fills in the scalebar.
void setUnitLabel(const QString &label)
Sets the label for units.
SegmentSizeMode
Modes for setting size for scale bar segments.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Scale bar segment size is fixed to a map unit.
QIcon icon() const override
Returns the item's icon.
double maximumBarWidth() const
Returns the maximum width (in millimeters) for scale bar segments.
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
QgsTextFormat & textFormat()
Returns the text format used for drawing text in the scalebar.
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Contains settings and helpers relating to a render of a QgsLayoutItem.
DistanceUnit
Units of distance.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
void setHeight(double height)
Sets the scalebar height (in millimeters).
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for drawing text in the scalebar.
#define Q_NOWARN_DEPRECATED_POP
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
QgsLayoutItemScaleBar(QgsLayout *layout)
Constructor for QgsLayoutItemScaleBar, with the specified parent layout.
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
void setUnits(QgsUnitTypes::DistanceUnit units)
Sets the distance units used by the scalebar.
void setLineJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the lines in the scalebar.
double scale() const
Returns the map scale.
void setLineWidth(double width)
Sets the line width in millimeters for lines in the scalebar.
virtual QString uuid() const
Returns the item identification string.
This class represents a coordinate reference system (CRS).
void setLabelBarSpace(double space)
Sets the spacing (in millimeters) between labels and the scalebar.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
void applyDefaultSettings()
Applies the default scalebar settings to the scale bar.
void setBrush2(const QBrush &brush)
Sets the secondary brush used for filling the scalebar.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
A layout item subclass for scale bars.
void setNumberOfSegmentsLeft(int segments)
Sets the number of segments included in the left part of the scalebar.
double unitsPerSegment() const
Returns the number of scalebar units per segment.
Q_DECL_DEPRECATED QColor fontColor() const
Returns the color used for drawing text in the scalebar.
Qt::PenCapStyle lineCapStyle() const
Returns the cap style used for drawing lines in the scalebar.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
void setNumberOfSegmentsLeft(int segments)
Sets the number of segments included in the left part of the scalebar.
QBrush brush2() const
Returns the secondary brush for the scalebar.
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for drawing text in the scalebar.
static QString encodePenCapStyle(Qt::PenCapStyle style)
Container for all settings relating to text rendering.
double prevNiceNumber(double a, double d=1)
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Qt::PenJoinStyle lineJoinStyle() const
Returns the join style used for drawing lines in the scalebar.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
QgsTextFormat textFormat() const
Returns the text format used for drawing text in the scalebar.
int numberOfSegmentsLeft() const
Returns the number of segments included in the left part of the scalebar.
void setUnits(QgsUnitTypes::DistanceUnit units)
Sets the distance units used by the scalebar.
void changed()
Emitted when the object's properties change.
DataDefinedProperty
Data defined properties for different item types.
void setUnitsPerSegment(double units)
Sets the number of scalebar units per segment.
double nextNiceNumber(double a, double d=1)
void setBrush(const QBrush &brush)
Sets the primary brush used for filling the scalebar.
QFont font() const
Returns the font used for rendering text.
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
void setUnitLabel(const QString &label)
Sets the label for units.
double measureLine(const QVector< QgsPointXY > &points) const
Measures the length of a line with multiple segments.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
void applyDefaultSize(QgsUnitTypes::DistanceUnit units=QgsUnitTypes::DistanceMeters)
Applies the default size to the scale bar (scale bar 1/5 of map item width)
void setWidth(const double width)
Sets the width for the size.
void setNumberOfSegments(int segments)
Sets the number of segments included in the scalebar.
Render ticks crossing line.
static QgsLayoutItemScaleBar * create(QgsLayout *layout)
Returns a new scale bar item for the specified layout.
QgsUnitTypes::DistanceUnit units() const
Returns the distance units used by the scalebar.
Contains parameters regarding scalebar calculations.