30#include "moc_qgslayoutitemmarker.cpp"
32using namespace Qt::StringLiterals;
41 QVariantMap properties;
42 properties.insert( u
"size"_s, u
"4"_s );
72void QgsLayoutItemMarker::refreshSymbol()
74 if (
auto *lLayout =
layout() )
78 std::unique_ptr< QgsMarkerSymbol > sym( mShapeStyleSymbol->clone() );
79 sym->setAngle( sym->angle() + mNorthArrowRotation );
80 sym->startRender( rc );
81 QRectF bounds = sym->bounds( QPointF( 0, 0 ), rc );
82 sym->stopRender( rc );
83 mPoint = QPointF( -bounds.left() * 25.4 / lLayout->renderContext().dpi(),
84 -bounds.top() * 25.4 / lLayout->renderContext().dpi() );
85 bounds.translate( mPoint );
88 mFixedSize =
mLayout->renderContext().measurementConverter().convert( newSizeMm,
sizeWithUnits().units() );
99void QgsLayoutItemMarker::updateBoundingRect()
101 QRectF rectangle = rect();
104 rectangle.adjust( -5, -5, 5, 5 );
105 if ( rectangle != mCurrentRectangle )
107 prepareGeometryChange();
108 mCurrentRectangle = rectangle;
112void QgsLayoutItemMarker::northArrowRotationChanged(
double rotation )
114 mNorthArrowRotation = rotation;
123 mShapeStyleSymbol.reset(
symbol );
129 return mShapeStyleSymbol.get();
134 mNorthArrowHandler->setLinkedMap( map );
139 return mNorthArrowHandler->linkedMap();
144 return mNorthArrowHandler->northMode();
150 mNorthArrowHandler->setNorthMode( mode );
156 return mNorthArrowHandler->northOffset();
161 mNorthArrowHandler->setNorthOffset( offset );
166 return mCurrentRectangle;
176 if ( mShapeStyleSymbol )
189 painter->setPen( Qt::NoPen );
190 painter->setBrush( Qt::NoBrush );
194 const QPointF shapePoint = mPoint * scale;
196 std::unique_ptr< QgsMarkerSymbol > sym( mShapeStyleSymbol->clone() );
197 sym->setAngle( sym->angle() + mNorthArrowRotation );
199 sym->renderPoint( shapePoint,
nullptr, context.
renderContext() );
206 element.appendChild( shapeStyleElem );
209 element.setAttribute( u
"arrowRotation"_s, QString::number( mNorthArrowRotation ) );
210 if ( !mNorthArrowHandler->linkedMap() )
212 element.setAttribute( u
"mapUuid"_s, QString() );
216 element.setAttribute( u
"mapUuid"_s, mNorthArrowHandler->linkedMap()->uuid() );
218 element.setAttribute( u
"northMode"_s, mNorthArrowHandler->northMode() );
219 element.setAttribute( u
"northOffset"_s, mNorthArrowHandler->northOffset() );
226 const QDomElement shapeStyleSymbolElem = element.firstChildElement( u
"symbol"_s );
227 if ( !shapeStyleSymbolElem.isNull() )
233 if ( !
qgsDoubleNear( element.attribute( u
"arrowRotation"_s, u
"0"_s ).toDouble(), 0.0 ) )
235 mNorthArrowRotation = element.attribute( u
"arrowRotation"_s, u
"0"_s ).toDouble();
240 mNorthArrowHandler->setNorthOffset( element.attribute( u
"northOffset"_s, u
"0"_s ).toDouble() );
242 mNorthArrowHandler->setLinkedMap(
nullptr );
243 mRotationMapUuid = element.attribute( u
"mapUuid"_s );
252 if ( !
mLayout || mRotationMapUuid.isEmpty() )
254 mNorthArrowHandler->setLinkedMap(
nullptr );
258 mNorthArrowHandler->setLinkedMap( qobject_cast< QgsLayoutItemMap * >(
mLayout->itemByUuid( mRotationMapUuid,
true ) ) );
@ Millimeters
Millimeters.
@ Millimeters
Millimeters.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
~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.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
friend class QgsLayoutItemMap
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 arrowRotationChanged(double newRotation)
Emitted on arrow rotation change.
NorthMode
Method for syncing rotation to a map's North direction.
const QgsLayout * layout() const
Returns the layout the object is attached to.
void changed()
Emitted when the object's properties change.
QPointer< QgsLayout > mLayout
Provides a method of storing sizes, consisting of a width and height, for use in QGIS layouts.
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
A marker symbol type, for rendering Point and MultiPoint geometries.
static std::unique_ptr< QgsMarkerSymbol > createSimple(const QVariantMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
A container for the context for various read/write operations on objects.
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.
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 std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
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.