17#ifndef QGSLAYOUTITEMMAP_H
18#define QGSLAYOUTITEMMAP_H
167 void layersAboutToBeRemoved(
const QList<QgsMapLayer *> &layers );
171 bool mClipToAtlasFeature =
false;
172 bool mRestrictToLayers =
false;
173 QList< QgsMapLayerRef > mLayersToClip;
175 bool mForceLabelsInsideFeature =
false;
176 bool mClipItemShape =
false;
316 bool mEnabled =
false;
318 bool mForceLabelsInsideClipPath =
false;
320 QPointer< QgsLayoutItem > mClipPathSource;
321 QString mClipPathUuid;
382 int type()
const override;
383 QIcon
icon()
const override;
416 void paint( QPainter *painter,
const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
override;
435 double scale() const;
536 QList<QgsMapLayer *> layers()
const;
547 void setLayers(
const QList<QgsMapLayer *> &layers );
571 void setLayerStyleOverrides(
const QMap<QString, QString> &overrides );
576 void storeCurrentLayerStyles();
593 void setFollowVisibilityPreset(
bool follow );
610 void setFollowVisibilityPresetName(
const QString &name );
612 void moveContent(
double dx,
double dy )
override;
613 void setMoveContentPreviewOffset(
double dx,
double dy )
override;
615 void zoomContent(
double factor, QPointF point )
override;
619 bool containsWmsLayer()
const;
621 bool requiresRasterization()
const override;
622 bool containsAdvancedEffects()
const override;
630 void setMapRotation(
double rotation );
669 void setAtlasDriven(
bool enabled );
773 double mapUnitsToLayoutUnits()
const;
784 void finalizeRestoreFromXml()
override;
792 QList<QgsMapLayer *> layersToRender(
const QgsExpressionContext *context =
nullptr,
bool includeInvalidLayers =
false )
const;
875 QTransform layoutToMapCoordsTransform()
const;
898 void setZRangeEnabled(
bool enabled );
908 bool zRangeEnabled()
const;
935 double estimatedFrameBleed()
const override;
939 bool writePropertiesToElement( QDomElement &element, QDomDocument &document,
const QgsReadWriteContext &context )
const override;
940 bool readPropertiesFromElement(
const QDomElement &element,
const QDomDocument &document,
const QgsReadWriteContext &context )
override;
941 QPainterPath framePath()
const override;
947 QRectF boundingRect()
const override;
950 QPolygonF transformedMapPolygon()
const;
953 QPointF mapToItemCoords( QPointF mapCoords )
const;
1021 void layersAboutToBeRemoved(
const QList<QgsMapLayer *> &
layers );
1023 void painterJobFinished();
1025 void shapeChanged();
1027 void mapThemeChanged(
const QString &theme );
1030 void currentMapThemeRenamed(
const QString &theme,
const QString &newTheme );
1033 void recreateCachedImageInBackground();
1035 void updateAtlasFeature();
1043 std::unique_ptr< QgsLayoutItemMapGridStack > mGridStack;
1044 std::unique_ptr< QgsLayoutItemMapOverviewStack > mOverviewStack;
1066 std::unique_ptr< QImage > mCacheFinalImage;
1067 std::unique_ptr< QImage > mCacheRenderingImage;
1068 bool mUpdatesEnabled =
true;
1071 bool mCacheInvalidated =
true;
1074 int mNumCachedLayers;
1077 bool mDrawing =
false;
1079 QTimer *mBackgroundUpdateTimer =
nullptr;
1080 double mPreviewScaleFactor = 0;
1081 double mPreviewDevicePixelRatio = 1.0;
1083 bool mDrawingPreview =
false;
1086 double mXOffset = 0.0;
1088 double mYOffset = 0.0;
1090 double mLastRenderedImageOffsetX = 0.0;
1091 double mLastRenderedImageOffsetY = 0.0;
1094 double mMapRotation = 0;
1100 double mEvaluatedMapRotation = 0;
1102 bool mZRangeEnabled =
false;
1106 bool mKeepLayerSet =
false;
1109 QList< QgsMapLayerRef > mLayers;
1111 bool mKeepLayerStyles =
false;
1113 QMap<QString, QString> mLayerStyleOverrides;
1116 mutable QString mCachedLayerStyleOverridesPresetName;
1118 mutable QMap<QString, QString> mCachedPresetLayerStyleOverrides;
1125 bool mFollowVisibilityPreset =
false;
1131 QString mFollowVisibilityPresetName;
1134 QString mLastEvaluatedThemeName;
1143 void drawMap( QPainter *painter,
const QgsRectangle &
extent, QSizeF size,
double dpi );
1146 void connectUpdateSlot();
1149 void syncLayerSet();
1164 QRectF mCurrentRectangle;
1166 bool mDrawAnnotations =
true;
1169 bool mAtlasDriven =
false;
1173 double mAtlasMargin = 0.10;
1175 std::unique_ptr< QPainter > mPainter;
1176 std::unique_ptr< QgsMapRendererCustomPainterJob > mPainterJob;
1177 bool mPainterCancelWait =
false;
1182 QStringList mBlockingLabelItemUuids;
1183 QList< QPointer< QgsLayoutItem > > mBlockingLabelItems;
1188 QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
1190 std::unique_ptr< QgsMapRendererStagedRenderJob > mStagedRendererJob;
1192 std::unique_ptr< QgsLabelingResults > mPreviewLabelingResults;
1193 std::unique_ptr< QgsLabelingResults > mExportLabelingResults;
1198 void updateToolTip();
1200 QString themeToRender(
const QgsExpressionContext &context )
const;
1203 QMap<QString, QString> layerStyleOverridesToRender(
const QgsExpressionContext &context )
const;
1206 QgsRectangle transformedExtent()
const;
1209 void mapPolygon(
const QgsRectangle &extent, QPolygonF &poly )
const;
1216 void transformShift(
double &xShift,
double &yShift )
const;
1218 void drawAnnotations( QPainter *painter );
1219 void drawAnnotation(
const QgsAnnotation *item, QgsRenderContext &context );
1220 QPointF layoutMapPosForItem(
const QgsAnnotation *item )
const;
1222 void drawMapFrame( QPainter *p );
1223 void drawMapBackground( QPainter *p );
1239 bool shouldDrawPart( PartType part )
const;
1241 PartType mCurrentExportPart = NotLayered;
1242 QStringList mExportThemes;
1243 QStringList::iterator mExportThemeIt;
1245 QgsLayoutItemMapAtlasClippingSettings *mAtlasClippingSettings =
nullptr;
1246 QgsLayoutItemMapItemClipPathSettings *mItemClippingSettings =
nullptr;
1248 std::unique_ptr<QgsGroupedFeatureFilterProvider> mAtlasFeatureFilterProvider;
1254 void refreshMapExtents(
const QgsExpressionContext *context =
nullptr );
1256 void refreshLabelMargin(
bool updateItem );
1258 QgsRectangle computeAtlasRectangle();
1260 void createStagedRenderJob(
const QgsRectangle &extent,
const QSizeF size,
double dpi );
1262 QPolygonF calculateVisibleExtentPolygon(
bool includeClipping )
const;
1267 std::map<QString, std::unique_ptr<QgsGroupLayer>> mGroupLayers;
1272 bool hasCustomFramePath()
const;
Abstract base class for annotation items which are drawn over a map.
Represents a coordinate reference system (CRS).
QgsRange which stores a range of double values.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A geometry is the spatial representation of a feature.
A filter filter provider grouping several filter providers.
Stores computed placement from labeling engine.
Contains settings relating to clipping a layout map by the current atlas feature.
void setFeatureClippingType(QgsMapClippingRegion::FeatureClippingType type)
Sets the feature clipping type to apply when clipping to the current atlas feature.
bool restrictToLayers() const
Returns true if clipping should be restricted to a subset of layers.
QgsLayoutItemMapAtlasClippingSettings(QgsLayoutItemMap *map=nullptr)
Constructor for QgsLayoutItemMapAtlasClippingSettings, with the specified map parent.
bool readXml(const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context)
Sets the setting's state from a DOM document, where element is the DOM node corresponding to a 'Layou...
bool clipItemShape() const
Returns true if the map item shape will be clipped to the atlas feature geometry.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores settings in a DOM element, where element is the DOM element corresponding to a 'LayoutMap' tag...
void setRestrictToLayers(bool enabled)
Sets whether clipping should be restricted to a subset of layers.
void setLayersToClip(const QList< QgsMapLayer * > &layers)
Sets the list of map layers to clip to the atlas feature.
QList< QgsMapLayer * > layersToClip() const
Returns the list of map layers to clip to the atlas feature.
void setEnabled(bool enabled)
Sets whether the map content should be clipped to the current atlas feature.
void changed()
Emitted when the atlas clipping settings are changed.
void setClipItemShape(bool clipItemShape)
Sets whether the map item shape will be clipped to the atlas feature geometry.
bool forceLabelsInsideFeature() const
Returns true if labels should only be placed inside the atlas feature geometry.
bool enabled() const
Returns true if the map content should be clipped to the current atlas feature.
void setForceLabelsInsideFeature(bool forceInside)
Sets whether labels should only be placed inside the atlas feature geometry.
QgsMapClippingRegion::FeatureClippingType featureClippingType() const
Returns the feature clipping type to apply when clipping to the current atlas feature.
A collection of grids which is drawn above the map content in a QgsLayoutItemMap.
An individual grid which is drawn above the map content in a QgsLayoutItemMap.
Contains settings relating to clipping a layout map by another layout item.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores settings in a DOM element, where element is the DOM element corresponding to a 'LayoutMap' tag...
void setForceLabelsInsideClipPath(bool forceInside)
Sets whether labels should only be placed inside the clip path geometry.
void setSourceItem(QgsLayoutItem *item)
Sets the source item which will provide the clipping path for the map.
QgsLayoutItemMapItemClipPathSettings(QgsLayoutItemMap *map=nullptr)
Constructor for QgsLayoutItemMapItemClipPathSettings, with the specified map parent.
bool readXml(const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context)
Sets the setting's state from a DOM document, where element is the DOM node corresponding to a 'Layou...
QgsGeometry clipPathInMapItemCoordinates() const
Returns the clipping path geometry, in the map item's coordinate space.
QgsGeometry clippedMapExtent() const
Returns the geometry to use for clipping the parent map, in the map item's CRS.
QgsLayoutItem * sourceItem()
Returns the source item which will provide the clipping path for the map, or nullptr if no item is se...
void setEnabled(bool enabled)
Sets whether the map content should be clipped to the associated item.
bool forceLabelsInsideClipPath() const
Returns true if labels should only be placed inside the clip path geometry.
void finalizeRestoreFromXml()
To be called after all pending items have been restored from XML.
QgsMapClippingRegion::FeatureClippingType featureClippingType() const
Returns the feature clipping type to apply when clipping to the associated item.
bool enabled() const
Returns true if the map content should be clipped to the associated item.
QgsMapClippingRegion toMapClippingRegion() const
Returns the clip path as a map clipping region.
void changed()
Emitted when the item clipping settings are changed.
void setFeatureClippingType(QgsMapClippingRegion::FeatureClippingType type)
Sets the feature clipping type to apply when clipping to the associated item.
bool isActive() const
Returns true if the item clipping is enabled and set to a valid source item.
A collection of overviews which are drawn above the map content in a QgsLayoutItemMap.
An individual overview which is drawn above the map content in a QgsLayoutItemMap,...
Layout graphical items for displaying a map.
bool nextExportPart() override
Moves to the next export part for a multi-layered export item, during a multi-layered export.
void extentChanged()
Emitted when the map's extent changes.
QIcon icon() const override
Returns the item's icon.
void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties) override
void preparedForAtlas()
Emitted when the map has been prepared for atlas rendering, just before actual rendering.
QgsMapRendererJob::Errors renderingErrors() const
Returns map rendering errors.
bool keepLayerSet() const
Returns whether a stored layer set should be used or the current layer set from the project associate...
QgsMapSettings mapSettings(const QgsRectangle &extent, QSizeF size, double dpi, bool includeLayerSettings) const
Returns map settings that will be used for drawing of the map.
void setKeepLayerSet(bool enabled)
Sets whether the stored layer set should be used or the current layer set of the associated project.
AtlasScalingMode
Scaling modes used for the serial rendering (atlas).
@ Predefined
A scale is chosen from the predefined scales.
@ Auto
The extent is adjusted so that each feature is fully visible.
@ Fixed
The current scale of the map is used for each feature of the atlas.
Q_DECL_DEPRECATED int numberExportLayers() const override
void layerStyleOverridesChanged()
Emitted when layer style overrides are changed... a means to let associated legend items know they sh...
void updateBoundingRect()
Updates the bounding rect of this item. Call this function before doing any changes related to annota...
friend class QgsGeospatialPdfRenderedFeatureHandler
void mapRotationChanged(double newRotation)
Emitted when the map's rotation changes.
QgsCoordinateReferenceSystem presetCrs() const
Returns the map's preset coordinate reference system.
int type() const override
bool isDrawing() const
True if a draw is already in progress.
QString followVisibilityPresetName() const
Preset name that decides which layers and layer styles are used for map rendering.
void previewRefreshed()
Emitted whenever the item's map preview has been refreshed.
friend class QgsLayoutItemMapOverview
void setDrawAnnotations(bool draw)
Sets whether annotations are drawn within the map.
void setExtent(const QgsRectangle &extent)
Sets a new extent for the map.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
QFlags< MapItemFlag > MapItemFlags
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
bool followVisibilityPreset() const
Returns whether the map should follow a map theme.
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation.
friend class QgsLayoutExporter
QgsLayoutItemMap(QgsLayout *layout)
Constructor for QgsLayoutItemMap, with the specified parent layout.
void setMapFlags(QgsLayoutItemMap::MapItemFlags flags)
Sets the map item's flags, which control how the map content is drawn.
void crsChanged()
Emitted when the map's coordinate reference system is changed.
static QgsLayoutItemMap * create(QgsLayout *layout)
Returns a new map item for the specified layout.
QgsLayoutItemMapOverviewStack * overviews()
Returns the map item's overview stack, which is used to control how overviews are drawn over the map'...
QString displayName() const override
Gets item display name.
bool atlasDriven() const
Returns whether the map extent is set to follow the current atlas feature.
bool keepLayerStyles() const
Returns whether current styles of layers should be overridden by previously stored styles.
void stopLayeredExport() override
Stops a multi-layer export operation.
QMap< QString, QString > layerStyleOverrides() const
Returns stored overrides of styles for layers.
AtlasScalingMode atlasScalingMode() const
Returns the current atlas scaling mode.
void setAtlasScalingMode(AtlasScalingMode mode)
Sets the current atlas scaling mode.
void startLayeredExport() override
Starts a multi-layer export operation.
void setScale(double scale, bool forceUpdate=true)
Sets new map scale and changes only the map extent.
QgsLayoutItemMap::MapItemFlags mapFlags() const
Returns the map item's flags, which control how the map content is drawn.
void themeChanged(const QString &theme)
Emitted when the map's associated theme is changed.
QgsLayoutItem::ExportLayerDetail exportLayerDetails() const override
Returns the details for the specified current export layer.
void zoomToExtent(const QgsRectangle &extent)
Zooms the map so that the specified extent is fully visible within the map item.
double scale() const
Returns the map scale.
MapItemFlag
Various flags that affect drawing of map items.
@ ShowPartialLabels
Whether to draw labels which are partially outside of the map view.
@ ShowUnplacedLabels
Whether to render unplaced labels in the map view.
friend class QgsCompositionConverter
bool drawAnnotations() const
Returns whether annotations are drawn within 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...
void invalidateCache() override
QgsRectangle extent() const
Returns the current map extent.
void setFrameStrokeWidth(QgsLayoutMeasurement width) override
Sets the frame stroke width.
friend class TestQgsLayoutMap
friend class QgsLayoutItemMapGrid
QgsLayoutItemMapAtlasClippingSettings * atlasClippingSettings()
Returns the map's atlas clipping settings.
QgsLayoutItem::Flags itemFlags() const override
Returns the item's flags, which indicate how the item behaves.
QList< QgsMapLayer * > layers() const
Returns the stored layer set.
void setAtlasMargin(double margin)
Sets the margin size (percentage) used when the map is in atlas mode.
void setKeepLayerStyles(bool enabled)
Sets whether current styles of layers should be overridden by previously stored styles.
friend class QgsLayoutItemLegend
static const QgsSettingsEntryBool * settingForceRasterMasks
Settings entry - Whether to force rasterized clipping masks, regardless of output format.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
QgsLayoutItemMapItemClipPathSettings * itemClippingSettings()
Returns the map's item based clip path settings.
void assignFreeId()
Sets the map id() to a number not yet used in the layout.
ExportLayerBehavior exportLayerBehavior() const override
Returns the behavior of this item during exporting to layered exports (e.g.
Contains settings and helpers relating to a render of a QgsLayoutItem.
Base class for graphical items within a QgsLayout.
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
ExportLayerBehavior
Behavior of item when exporting to layered outputs.
Provides a method of storing measurements for use in QGIS layouts using a variety of different measur...
const QgsLayout * layout() const
Returns the layout the object is attached to.
DataDefinedProperty
Data defined properties for different item types.
@ AllProperties
All properties for item.
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value,...
@ EvaluatedValue
Return the current evaluated value for the property.
A map clipping region (in map coordinates and CRS).
FeatureClippingType
Feature clipping behavior, which controls how features from vector layers will be clipped.
@ ClipPainterOnly
Applying clipping on the painter only (i.e. feature boundaries will be unchanged, but may be invisibl...
QList< QgsMapRendererJob::Error > Errors
Contains configuration for rendering maps.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
An interface for classes which provide custom handlers for features rendered as part of a map render ...
A boolean settings entry.
An interface for classes which can visit style entity (e.g.
QgsTemporalRangeObject(bool enabled=false)
Constructor QgsTemporalRangeObject.
#define SIP_ENUM_BASETYPE(type)
Contains details of a particular export layer relating to a layout item.