34 QVariantMap properties;
35 properties.insert( QStringLiteral(
"size" ), QStringLiteral(
"4" ) );
65 void QgsLayoutItemMarker::refreshSymbol()
67 if (
auto *lLayout =
layout() )
71 std::unique_ptr< QgsMarkerSymbol > sym( mShapeStyleSymbol->clone() );
72 sym->setAngle( sym->angle() + mNorthArrowRotation );
73 sym->startRender( rc );
74 QRectF bounds = sym->bounds( QPointF( 0, 0 ), rc );
75 sym->stopRender( rc );
76 mPoint = QPointF( -bounds.left() * 25.4 / lLayout->renderContext().dpi(),
77 -bounds.top() * 25.4 / lLayout->renderContext().dpi() );
78 bounds.translate( mPoint );
81 mFixedSize =
mLayout->renderContext().measurementConverter().convert( newSizeMm,
sizeWithUnits().units() );
92 void QgsLayoutItemMarker::updateBoundingRect()
94 QRectF rectangle = rect();
97 rectangle.adjust( -5, -5, 5, 5 );
98 if ( rectangle != mCurrentRectangle )
100 prepareGeometryChange();
101 mCurrentRectangle = rectangle;
105 void QgsLayoutItemMarker::northArrowRotationChanged(
double rotation )
107 mNorthArrowRotation = rotation;
116 mShapeStyleSymbol.reset(
symbol );
122 return mShapeStyleSymbol.get();
159 return mCurrentRectangle;
169 if ( mShapeStyleSymbol )
182 painter->setPen( Qt::NoPen );
183 painter->setBrush( Qt::NoBrush );
187 QPointF shapePoint = mPoint * scale;
189 std::unique_ptr< QgsMarkerSymbol > sym( mShapeStyleSymbol->clone() );
190 sym->setAngle( sym->angle() + mNorthArrowRotation );
192 sym->renderPoint( shapePoint,
nullptr, context.
renderContext() );
199 element.appendChild( shapeStyleElem );
202 element.setAttribute( QStringLiteral(
"arrowRotation" ), QString::number( mNorthArrowRotation ) );
205 element.setAttribute( QStringLiteral(
"mapUuid" ), QString() );
209 element.setAttribute( QStringLiteral(
"mapUuid" ), mNorthArrowHandler->
linkedMap()->
uuid() );
211 element.setAttribute( QStringLiteral(
"northMode" ), mNorthArrowHandler->
northMode() );
212 element.setAttribute( QStringLiteral(
"northOffset" ), mNorthArrowHandler->
northOffset() );
219 QDomElement shapeStyleSymbolElem = element.firstChildElement( QStringLiteral(
"symbol" ) );
220 if ( !shapeStyleSymbolElem.isNull() )
222 mShapeStyleSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( shapeStyleSymbolElem, context ) );
226 if ( !
qgsDoubleNear( element.attribute( QStringLiteral(
"arrowRotation" ), QStringLiteral(
"0" ) ).toDouble(), 0.0 ) )
228 mNorthArrowRotation = element.attribute( QStringLiteral(
"arrowRotation" ), QStringLiteral(
"0" ) ).toDouble();
233 mNorthArrowHandler->
setNorthOffset( element.attribute( QStringLiteral(
"northOffset" ), QStringLiteral(
"0" ) ).toDouble() );
236 mRotationMapUuid = element.attribute( QStringLiteral(
"mapUuid" ) );
245 if ( !
mLayout || mRotationMapUuid.isEmpty() )
251 mNorthArrowHandler->
setLinkedMap( qobject_cast< QgsLayoutItemMap * >(
mLayout->itemByUuid( mRotationMapUuid,
true ) ) );
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Layout graphical items for displaying a map.
A layout item for showing marker symbols.
~QgsLayoutItemMarker() override
double northOffset() const
Returns the offset added to the marker's rotation from a map's North.
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
QIcon icon() const override
Returns the item's icon.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map object for rotation.
QgsLayoutNorthArrowHandler::NorthMode northMode() const
Returns the mode used to align the marker to a map's North.
QgsLayoutItemMarker(QgsLayout *layout)
Constructor for QgsLayoutItemMarker, with the specified parent layout.
QgsLayoutSize fixedSize() const override
Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized.
void setNorthOffset(double offset)
Sets the offset added to the marker's rotation from a map's North.
int type() const override
void setNorthMode(QgsLayoutNorthArrowHandler::NorthMode mode)
Sets the mode used to align the marker to a map's North.
static QgsLayoutItemMarker * create(QgsLayout *layout)
Returns a new marker item for the specified layout.
QgsLayoutItemMap * linkedMap() const
Returns the linked rotation map, if set.
void setSymbol(QgsMarkerSymbol *symbol)
Sets the marker symbol used to draw the shape.
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
QRectF boundingRect() const override
QgsMarkerSymbol * symbol()
Returns the marker symbol used to draw the shape.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
@ LayoutMarker
Marker item.
Contains settings and helpers relating to a render of a QgsLayoutItem.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Base class for graphical items within a QgsLayout.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
virtual void setFrameEnabled(bool drawFrame)
Sets whether this item has a frame drawn around it or not.
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.
void sizePositionChanged()
Emitted when the item's size or position changes.
virtual QString uuid() const
Returns the item identification string.
void frameChanged()
Emitted if the item's frame style changes.
void setReferencePoint(ReferencePoint point)
Sets the reference point for positioning of the layout item.
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
An object which handles north-arrow type behavior for layout items.
void setNorthOffset(double offset)
Sets the offset added to the arrows's rotation from a map's North.
NorthMode northMode() const
Returns the mode used to calculate the arrow rotation.
QgsLayoutItemMap * linkedMap() const
Returns the linked rotation map, if set.
void arrowRotationChanged(double newRotation)
Emitted on arrow rotation change.
NorthMode
Method for syncing rotation to a map's North direction.
void setNorthMode(NorthMode mode)
Sets the mode used to calculate the arrow rotation.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the linked map item.
double northOffset() const
Returns the offset added to the arrows's rotation from a map's North.
const QgsLayout * layout() const
Returns the layout the object is attached to.
void changed()
Emitted when the object's properties change.
QPointer< QgsLayout > mLayout
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
A marker symbol type, for rendering Point and MultiPoint geometries.
static QgsMarkerSymbol * createSimple(const QVariantMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
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 symbol entity for QgsStyle databases.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
@ LayoutMillimeters
Millimeters.
@ RenderMillimeters
Millimeters.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Contains information relating to the style entity currently being visited.