17 #ifndef QGSLAYOUTITEMMAP_H 18 #define QGSLAYOUTITEMMAP_H 20 #include "qgis_core.h" 72 ShowPartialLabels = 1 << 0,
82 int type()
const override;
83 QIcon
icon()
const override;
84 QgsLayoutItem::Flags
itemFlags()
const override;
91 QgsLayoutItemMap::MapItemFlags mapFlags()
const;
98 void setMapFlags( QgsLayoutItemMap::MapItemFlags flags );
116 void paint( QPainter *painter,
const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
override;
125 double scale()
const;
134 void setScale(
double scale,
bool forceUpdate =
true );
169 QPolygonF visibleExtentPolygon()
const;
226 QList<QgsMapLayer *> layers()
const;
234 void setLayers(
const QList<QgsMapLayer *> &layers );
258 void setLayerStyleOverrides(
const QMap<QString, QString> &overrides );
263 void storeCurrentLayerStyles();
298 void zoomContent(
double factor, QPointF point )
override;
302 bool containsWmsLayer()
const;
313 void setMapRotation(
double rotation );
352 void setAtlasDriven(
bool enabled );
456 double mapUnitsToLayoutUnits()
const;
530 QRectF boundingRect()
const override;
533 QPolygonF transformedMapPolygon()
const;
536 QPointF mapToItemCoords( QPointF mapCoords )
const;
550 void extentChanged();
557 void mapRotationChanged(
double newRotation );
560 void preparedForAtlas();
566 void layerStyleOverridesChanged();
575 void updateBoundingRect();
580 void layersAboutToBeRemoved(
const QList<QgsMapLayer *> &layers );
582 void painterJobFinished();
586 void mapThemeChanged(
const QString &theme );
589 void recreateCachedImageInBackground();
593 QgsLayoutItemMap::MapItemFlags mMapFlags =
nullptr;
598 std::unique_ptr< QgsLayoutItemMapGridStack > mGridStack;
599 std::unique_ptr< QgsLayoutItemMapOverviewStack > mOverviewStack;
621 std::unique_ptr< QImage > mCacheFinalImage;
622 std::unique_ptr< QImage > mCacheRenderingImage;
623 bool mUpdatesEnabled =
true;
626 bool mCacheInvalidated =
true;
629 int mNumCachedLayers;
632 bool mDrawing =
false;
634 QTimer *mBackgroundUpdateTimer =
nullptr;
635 double mPreviewScaleFactor = 0;
637 bool mDrawingPreview =
false;
640 double mXOffset = 0.0;
642 double mYOffset = 0.0;
644 double mLastRenderedImageOffsetX = 0.0;
645 double mLastRenderedImageOffsetY = 0.0;
648 double mMapRotation = 0;
653 double mEvaluatedMapRotation = 0;
656 bool mKeepLayerSet =
false;
659 QList< QgsMapLayerRef > mLayers;
661 bool mKeepLayerStyles =
false;
663 QMap<QString, QString> mLayerStyleOverrides;
666 mutable QString mCachedLayerStyleOverridesPresetName;
668 mutable QMap<QString, QString> mCachedPresetLayerStyleOverrides;
674 bool mFollowVisibilityPreset =
false;
679 QString mFollowVisibilityPresetName;
688 void drawMap( QPainter *painter,
const QgsRectangle &extent, QSizeF size,
double dpi );
691 void connectUpdateSlot();
705 QTransform layoutToMapCoordsTransform()
const;
711 QList< QgsLabelBlockingRegion > createLabelBlockingRegions(
const QgsMapSettings &mapSettings )
const;
714 QRectF mCurrentRectangle;
716 bool mDrawAnnotations =
true;
719 bool mAtlasDriven =
false;
723 double mAtlasMargin = 0.10;
725 std::unique_ptr< QPainter > mPainter;
726 std::unique_ptr< QgsMapRendererCustomPainterJob > mPainterJob;
727 bool mPainterCancelWait =
false;
732 QStringList mBlockingLabelItemUuids;
733 QList< QPointer< QgsLayoutItem > > mBlockingLabelItems;
741 void updateToolTip();
744 QMap<QString, QString> layerStyleOverridesToRender(
const QgsExpressionContext &context )
const;
750 void mapPolygon(
const QgsRectangle &extent, QPolygonF &poly )
const;
757 void transformShift(
double &xShift,
double &yShift )
const;
759 void drawAnnotations( QPainter *painter );
761 QPointF layoutMapPosForItem(
const QgsAnnotation *item )
const;
763 void drawMapFrame( QPainter *p );
764 void drawMapBackground( QPainter *p );
777 bool shouldDrawPart( PartType part )
const;
785 void refreshLabelMargin(
bool updateItem );
787 void updateAtlasFeature();
794 friend class TestQgsLayoutMap;
799 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayoutItemMap::MapItemFlags )
801 #endif //QGSLAYOUTITEMMAP_H The class is used as a container of context for various read/write operations on other objects...
bool isDrawing() const
True if a draw is already in progress.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
bool followVisibilityPreset() const
Returns whether the map should follow a map theme.
virtual QIcon icon() const
Returns the item's icon.
void setFollowVisibilityPresetName(const QString &name)
Sets preset name for map rendering.
A rectangle specified with double values.
AtlasScalingMode atlasScalingMode() const
Returns the current atlas scaling mode.
Base class for graphical items within a QgsLayout.
An individual overview which is drawn above the map content in a QgsLayoutItemMap, and shows the extent of another QgsLayoutItemMap.
int type() const override
Returns a unique graphics item type identifier.
virtual bool containsAdvancedEffects() const
Returns true if the item contains contents with blend modes or transparency effects which can only be...
void setKeepLayerStyles(bool enabled)
Sets whether current styles of layers should be overridden by previously stored styles.
bool keepLayerStyles() const
Returns whether current styles of layers should be overridden by previously stored styles...
A collection of overviews which are drawn above the map content in a QgsLayoutItemMap.
virtual void setFrameStrokeWidth(QgsLayoutMeasurement width)
Sets the frame stroke width.
bool drawAnnotations() const
Returns whether annotations are drawn within the map.
void setKeepLayerSet(bool enabled)
Sets whether the stored layer set should be used or the current layer set of the associated project...
const QgsCoordinateReferenceSystem & crs
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...
Abstract base class for annotation items which are drawn over a map.
The QgsMapSettings class contains configuration for rendering of the map.
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
virtual void invalidateCache()
Forces a deferred update of any cached image the item uses.
Layout graphical items for displaying a map.
A collection of grids which is drawn above the map content in a QgsLayoutItemMap. ...
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Handles preparing a paint surface for the layout item and painting the item's content.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsMapRendererJob::Errors renderingErrors() const
Returns map rendering errors.
virtual int numberExportLayers() const
Returns the number of layers that this item requires for exporting during layered exports (e...
MapItemFlag
Various flags that affect drawing of map items.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
void setAtlasScalingMode(AtlasScalingMode mode)
Sets the current atlas scaling mode.
virtual bool requiresRasterization() const
Returns true if the item is drawn in such a way that forces the whole layout to be rasterized when ex...
virtual Flags itemFlags() const
Returns the item's flags, which indicate how the item behaves.
An individual grid which is drawn above the map content in a QgsLayoutItemMap.
bool keepLayerSet() const
Returns whether a stored layer set should be used or the current layer set from the project associate...
Contains settings and helpers relating to a render of a QgsLayoutItem.
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
void setAtlasMargin(double margin)
Sets the margin size (percentage) used when the map is in atlas mode.
virtual QString displayName() const
Gets item display name.
void setFollowVisibilityPreset(bool follow)
Sets whether the map should follow a map theme.
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
Return the current evaluated value for the property.
Contains information about the context of a rendering operation.
QgsCoordinateReferenceSystem presetCrs() const
Returns the map's preset coordinate reference system.
QList< QgsMapRendererJob::Error > Errors
void setDrawAnnotations(bool draw)
Sets whether annotations are drawn within the map.
virtual void setMoveContentPreviewOffset(double dx, double dy)
Sets temporary offset for the item, by a specified dx and dy in layout units.
The current scale of the map is used for each feature of the atlas.
virtual void moveContent(double dx, double dy)
Moves the content of the item, by a specified dx and dy in layout units.
This class represents a coordinate reference system (CRS).
virtual void zoomContent(double factor, QPointF point)
Zooms content of item.
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item's contents using the specified item render context.
bool atlasDriven() const
Returns whether the map extent is set to follow the current atlas feature.
AtlasScalingMode
Scaling modes used for the serial rendering (atlas)
A layout item subclass for map legends.
QString followVisibilityPresetName() const
Preset name that decides which layers and layer styles are used for map rendering.
DataDefinedProperty
Data defined properties for different item types.
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
QgsLayoutItemMapOverviewStack * overviews()
Returns the map item's overview stack, which is used to control how overviews are drawn over the map'...
QgsLayoutItemMapGridStack * grids()
Returns the map item's grid stack, which is used to control how grids are drawn over the map's conten...
A scale is chosen from the predefined scales.
QMap< QString, QString > layerStyleOverrides() const
Returns stored overrides of styles for layers.