17#ifndef QGSLAYOUTITEMMAP_H
18#define QGSLAYOUTITEMMAP_H
168 void layersAboutToBeRemoved(
const QList<QgsMapLayer *> &layers );
173 bool mClipToAtlasFeature =
false;
174 bool mRestrictToLayers =
false;
175 QList< QgsMapLayerRef > mLayersToClip;
177 bool mForceLabelsInsideFeature =
false;
178 bool mClipItemShape =
false;
320 bool mEnabled =
false;
322 bool mForceLabelsInsideClipPath =
false;
324 QPointer< QgsLayoutItem > mClipPathSource;
325 QString mClipPathUuid;
389 int type()
const override;
390 QIcon
icon()
const override;
423 void paint( QPainter *painter,
const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
override;
442 double scale() const;
543 QList<QgsMapLayer *> layers()
const;
554 void setLayers(
const QList<QgsMapLayer *> &layers );
578 void setLayerStyleOverrides(
const QMap<QString, QString> &overrides );
583 void storeCurrentLayerStyles();
600 void setFollowVisibilityPreset(
bool follow );
617 void setFollowVisibilityPresetName(
const QString &name );
619 void moveContent(
double dx,
double dy )
override;
620 void setMoveContentPreviewOffset(
double dx,
double dy )
override;
622 void zoomContent(
double factor, QPointF point )
override;
626 bool containsWmsLayer()
const;
628 bool requiresRasterization()
const override;
629 bool containsAdvancedEffects()
const override;
637 void setMapRotation(
double rotation );
676 void setAtlasDriven(
bool enabled );
780 double mapUnitsToLayoutUnits()
const;
791 void finalizeRestoreFromXml()
override;
799 QList<QgsMapLayer *> layersToRender(
const QgsExpressionContext *context =
nullptr,
bool includeInvalidLayers =
false )
const;
882 QTransform layoutToMapCoordsTransform()
const;
905 void setZRangeEnabled(
bool enabled );
915 bool zRangeEnabled()
const;
942 double estimatedFrameBleed()
const override;
947 bool writePropertiesToElement( QDomElement &element, QDomDocument &document,
const QgsReadWriteContext &context )
const override;
948 bool readPropertiesFromElement(
const QDomElement &element,
const QDomDocument &document,
const QgsReadWriteContext &context )
override;
949 QPainterPath framePath()
const override;
955 QRectF boundingRect()
const override;
958 QPolygonF transformedMapPolygon()
const;
961 QPointF mapToItemCoords( QPointF mapCoords )
const;
1029 void layersAboutToBeRemoved(
const QList<QgsMapLayer *> &
layers );
1031 void painterJobFinished();
1033 void shapeChanged();
1035 void mapThemeChanged(
const QString &theme );
1038 void currentMapThemeRenamed(
const QString &theme,
const QString &newTheme );
1041 void recreateCachedImageInBackground();
1043 void updateAtlasFeature();
1051 std::unique_ptr< QgsLayoutItemMapGridStack > mGridStack;
1052 std::unique_ptr< QgsLayoutItemMapOverviewStack > mOverviewStack;
1074 std::unique_ptr< QImage > mCacheFinalImage;
1075 std::unique_ptr< QImage > mCacheRenderingImage;
1076 bool mUpdatesEnabled =
true;
1079 bool mCacheInvalidated =
true;
1082 int mNumCachedLayers;
1085 bool mDrawing =
false;
1087 QTimer *mBackgroundUpdateTimer =
nullptr;
1088 double mPreviewScaleFactor = 0;
1089 double mPreviewDevicePixelRatio = 1.0;
1091 bool mDrawingPreview =
false;
1094 double mXOffset = 0.0;
1096 double mYOffset = 0.0;
1098 double mLastRenderedImageOffsetX = 0.0;
1099 double mLastRenderedImageOffsetY = 0.0;
1102 double mMapRotation = 0;
1108 double mEvaluatedMapRotation = 0;
1110 bool mZRangeEnabled =
false;
1114 bool mKeepLayerSet =
false;
1117 QList< QgsMapLayerRef > mLayers;
1119 bool mKeepLayerStyles =
false;
1121 QMap<QString, QString> mLayerStyleOverrides;
1124 mutable QString mCachedLayerStyleOverridesPresetName;
1126 mutable QMap<QString, QString> mCachedPresetLayerStyleOverrides;
1133 bool mFollowVisibilityPreset =
false;
1139 QString mFollowVisibilityPresetName;
1142 QString mLastEvaluatedThemeName;
1151 void drawMap( QPainter *painter,
const QgsRectangle &
extent, QSizeF size,
double dpi );
1154 void connectUpdateSlot();
1157 void syncLayerSet();
1172 QRectF mCurrentRectangle;
1174 bool mDrawAnnotations =
true;
1177 bool mAtlasDriven =
false;
1181 double mAtlasMargin = 0.10;
1183 std::unique_ptr< QPainter > mPainter;
1184 std::unique_ptr< QgsMapRendererCustomPainterJob > mPainterJob;
1185 bool mPainterCancelWait =
false;
1190 QStringList mBlockingLabelItemUuids;
1191 QList< QPointer< QgsLayoutItem > > mBlockingLabelItems;
1196 QList< QgsRenderedFeatureHandlerInterface * > mRenderedFeatureHandlers;
1198 std::unique_ptr< QgsMapRendererStagedRenderJob > mStagedRendererJob;
1200 std::unique_ptr< QgsLabelingResults > mPreviewLabelingResults;
1201 std::unique_ptr< QgsLabelingResults > mExportLabelingResults;
1206 void updateToolTip();
1208 QString themeToRender(
const QgsExpressionContext &context )
const;
1211 QMap<QString, QString> layerStyleOverridesToRender(
const QgsExpressionContext &context )
const;
1214 QgsRectangle transformedExtent()
const;
1217 void mapPolygon(
const QgsRectangle &extent, QPolygonF &poly )
const;
1224 void transformShift(
double &xShift,
double &yShift )
const;
1226 void drawAnnotations( QPainter *painter );
1227 void drawAnnotation(
const QgsAnnotation *item, QgsRenderContext &context );
1228 QPointF layoutMapPosForItem(
const QgsAnnotation *item )
const;
1230 void drawMapFrame( QPainter *p );
1231 void drawMapBackground( QPainter *p );
1247 bool shouldDrawPart( PartType part )
const;
1249 PartType mCurrentExportPart = NotLayered;
1250 QStringList mExportThemes;
1251 QStringList::iterator mExportThemeIt;
1253 QgsLayoutItemMapAtlasClippingSettings *mAtlasClippingSettings =
nullptr;
1254 QgsLayoutItemMapItemClipPathSettings *mItemClippingSettings =
nullptr;
1256 std::unique_ptr<QgsGroupedFeatureFilterProvider> mAtlasFeatureFilterProvider;
1262 void refreshMapExtents(
const QgsExpressionContext *context =
nullptr );
1264 void refreshLabelMargin(
bool updateItem );
1266 QgsRectangle computeAtlasRectangle();
1268 void createStagedRenderJob(
const QgsRectangle &extent,
const QSizeF size,
double dpi );
1270 QPolygonF calculateVisibleExtentPolygon(
bool includeClipping )
const;
1275 std::map<QString, std::unique_ptr<QgsGroupLayer>> mGroupLayers;
1280 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.