QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
35 QVariantMap properties;
36 properties.insert( QStringLiteral(
"size" ), QStringLiteral(
"4" ) );
66 void QgsLayoutItemMarker::refreshSymbol()
68 if (
auto *lLayout =
layout() )
72 std::unique_ptr< QgsMarkerSymbol > sym( mShapeStyleSymbol->clone() );
73 sym->setAngle( sym->angle() + mNorthArrowRotation );
74 sym->startRender( rc );
75 QRectF bounds = sym->bounds( QPointF( 0, 0 ), rc );
76 sym->stopRender( rc );
77 mPoint = QPointF( -bounds.left() * 25.4 / lLayout->renderContext().dpi(),
78 -bounds.top() * 25.4 / lLayout->renderContext().dpi() );
79 bounds.translate( mPoint );
82 mFixedSize =
mLayout->renderContext().measurementConverter().convert( newSizeMm,
sizeWithUnits().units() );
93 void QgsLayoutItemMarker::updateBoundingRect()
95 QRectF rectangle = rect();
98 rectangle.adjust( -5, -5, 5, 5 );
99 if ( rectangle != mCurrentRectangle )
101 prepareGeometryChange();
102 mCurrentRectangle = rectangle;
106 void QgsLayoutItemMarker::northArrowRotationChanged(
double rotation )
108 mNorthArrowRotation = rotation;
117 mShapeStyleSymbol.reset(
symbol );
123 return mShapeStyleSymbol.get();
160 return mCurrentRectangle;
170 if ( mShapeStyleSymbol )
183 painter->setPen( Qt::NoPen );
184 painter->setBrush( Qt::NoBrush );
188 const QPointF shapePoint = mPoint * scale;
190 std::unique_ptr< QgsMarkerSymbol > sym( mShapeStyleSymbol->clone() );
191 sym->setAngle( sym->angle() + mNorthArrowRotation );
193 sym->renderPoint( shapePoint,
nullptr, context.
renderContext() );
200 element.appendChild( shapeStyleElem );
203 element.setAttribute( QStringLiteral(
"arrowRotation" ), QString::number( mNorthArrowRotation ) );
206 element.setAttribute( QStringLiteral(
"mapUuid" ), QString() );
210 element.setAttribute( QStringLiteral(
"mapUuid" ), mNorthArrowHandler->
linkedMap()->
uuid() );
212 element.setAttribute( QStringLiteral(
"northMode" ), mNorthArrowHandler->
northMode() );
213 element.setAttribute( QStringLiteral(
"northOffset" ), mNorthArrowHandler->
northOffset() );
220 const QDomElement shapeStyleSymbolElem = element.firstChildElement( QStringLiteral(
"symbol" ) );
221 if ( !shapeStyleSymbolElem.isNull() )
223 mShapeStyleSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( shapeStyleSymbolElem, context ) );
227 if ( !
qgsDoubleNear( element.attribute( QStringLiteral(
"arrowRotation" ), QStringLiteral(
"0" ) ).toDouble(), 0.0 ) )
229 mNorthArrowRotation = element.attribute( QStringLiteral(
"arrowRotation" ), QStringLiteral(
"0" ) ).toDouble();
234 mNorthArrowHandler->
setNorthOffset( element.attribute( QStringLiteral(
"northOffset" ), QStringLiteral(
"0" ) ).toDouble() );
237 mRotationMapUuid = element.attribute( QStringLiteral(
"mapUuid" ) );
246 if ( !
mLayout || mRotationMapUuid.isEmpty() )
252 mNorthArrowHandler->
setLinkedMap( qobject_cast< QgsLayoutItemMap * >(
mLayout->itemByUuid( mRotationMapUuid,
true ) ) );
const QgsLayout * layout() const
Returns the layout the object is attached to.
A layout item for showing marker symbols.
void sizePositionChanged()
Emitted when the item's size or position changes.
virtual void setFrameEnabled(bool drawFrame)
Sets whether this item has a frame drawn around it or not.
The class is used as a container of context for various read/write operations on other objects.
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
A symbol entity for QgsStyle databases.
QgsLayoutItemMap * linkedMap() const
Returns the linked rotation map, if set.
~QgsLayoutItemMarker() override
Contains settings and helpers relating to a render of a QgsLayoutItem.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
void setNorthOffset(double offset)
Sets the offset added to the marker's rotation from a map's North.
@ RenderMillimeters
Millimeters.
QgsLayoutNorthArrowHandler::NorthMode northMode() const
Returns the mode used to align the marker to a map's North.
void changed()
Emitted when the object's properties change.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
Contains information relating to the style entity currently being visited.
QgsLayoutItemMap * linkedMap() const
Returns the linked rotation map, if set.
double northOffset() const
Returns the offset added to the marker's rotation from a map's North.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
NorthMode northMode() const
Returns the mode used to calculate the arrow rotation.
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
static QgsLayoutItemMarker * create(QgsLayout *layout)
Returns a new marker item for the specified layout.
QRectF boundingRect() const override
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map object for rotation.
A marker symbol type, for rendering Point and MultiPoint geometries.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void frameChanged()
Emitted if the item's frame style changes.
void setNorthOffset(double offset)
Sets the offset added to the arrows's rotation from a map's North.
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
QgsMarkerSymbol * symbol()
Returns the marker symbol used to draw the shape.
QgsLayoutSize fixedSize() const override
Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the linked map item.
void arrowRotationChanged(double newRotation)
Emitted on arrow rotation change.
Base class for graphical items within a QgsLayout.
void setNorthMode(NorthMode mode)
Sets the mode used to calculate the arrow rotation.
An object which handles north-arrow type behavior for layout items.
NorthMode
Method for syncing rotation to a map's North direction.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
Layout graphical items for displaying a map.
int type() const override
void setNorthMode(QgsLayoutNorthArrowHandler::NorthMode mode)
Sets the mode used to align the marker to a map's North.
void setReferencePoint(ReferencePoint point)
Sets the reference point for positioning of the layout item.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
virtual QString uuid() const
Returns the item identification string.
QPointer< QgsLayout > mLayout
QgsLayoutItemMarker(QgsLayout *layout)
Constructor for QgsLayoutItemMarker, with the specified parent layout.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
virtual QString displayName() const
Gets item display name.
@ LayoutMarker
Marker item.
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
void setSymbol(QgsMarkerSymbol *symbol)
Sets the marker symbol used to draw the shape.
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
double northOffset() const
Returns the offset added to the arrows's rotation from a map's North.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
@ LayoutMillimeters
Millimeters.
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
QPainter * painter()
Returns the destination QPainter for the render operation.
QIcon icon() const override
Returns the item's icon.
static QgsMarkerSymbol * createSimple(const QVariantMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.