49#include <QApplication>
52#include <QStyleOptionGraphicsItem>
55#include "moc_qgslayoutitemmap.cpp"
64 mBackgroundUpdateTimer =
new QTimer(
this );
65 mBackgroundUpdateTimer->setSingleShot(
true );
66 connect( mBackgroundUpdateTimer, &QTimer::timeout,
this, &QgsLayoutItemMap::recreateCachedImageInBackground );
70 setCacheMode( QGraphicsItem::NoCache );
77 mGridStack = std::make_unique< QgsLayoutItemMapGridStack >(
this );
78 mOverviewStack = std::make_unique< QgsLayoutItemMapOverviewStack >(
this );
93 crs.updateDefinition();
111 mPainterJob->cancel();
136 QList<QgsLayoutItemMap *> mapsList;
137 mLayout->layoutItems( mapsList );
146 if ( map->mMapId == mMapId )
149 maxId = std::max( maxId, map->mMapId );
154 mLayout->itemsModel()->updateItemDisplayName(
this );
166 return tr(
"Map %1" ).arg( mMapId );
178 mCachedLayerStyleOverridesPresetName.clear();
182 updateAtlasFeature();
187 if ( rect().isEmpty() || !
mLayout )
192 calculator.
setDpi( 25.4 );
195 calculator.
setMethod( project->scaleMethod() );
203 double currentScaleDenominator =
scale();
210 double scaleRatio = scaleDenominator / currentScaleDenominator;
211 mExtent.scale( scaleRatio );
213 if ( mAtlasDriven && mAtlasScalingMode ==
Fixed )
220 calculator.
setDpi( 25.4 );
226 const double newScale = calculator.
calculate( mExtent, rect().width() );
229 scaleRatio = scaleDenominator / newScale;
230 mExtent.scale( scaleRatio );
255 if ( mExtent.isFinite() && !mExtent.isEmpty() )
257 const QRectF currentRect = rect();
258 const double newHeight = mExtent.width() == 0 ? 0
259 : currentRect.width() * mExtent.height() / mExtent.width();
271 double currentWidthHeightRatio = 1.0;
272 if ( !currentExtent.
isEmpty() )
273 currentWidthHeightRatio = currentExtent.
width() / currentExtent.
height();
275 currentWidthHeightRatio = rect().width() / rect().height();
277 if ( currentWidthHeightRatio != 0 && ! std::isnan( currentWidthHeightRatio ) && !newExtent.
isEmpty() )
279 double newWidthHeightRatio = newExtent.
width() / newExtent.
height();
281 if ( currentWidthHeightRatio < newWidthHeightRatio )
284 double newHeight = newExtent.
width() / currentWidthHeightRatio;
285 double deltaHeight = newHeight - newExtent.
height();
292 double newWidth = currentWidthHeightRatio * newExtent.
height();
293 double deltaWidth = newWidth - newExtent.
width();
299 if ( mExtent == newExtent )
318QPolygonF QgsLayoutItemMap::calculateVisibleExtentPolygon(
bool includeClipping )
const
321 mapPolygon( mExtent, poly );
323 if ( includeClipping )
330 poly = poly.intersected( geom.asQPolygonF() );
334 if ( mItemClippingSettings->isActive() )
336 const QgsGeometry geom = mItemClippingSettings->clippedMapExtent();
349 return calculateVisibleExtentPolygon(
true );
354 if ( mCrs.isValid() )
357 return mLayout->project()->crs();
372 return _qgis_listRefToRaw( mLayers );
377 mGroupLayers.clear();
379 QList<QgsMapLayer *> layersCopy {
layers };
384 for (
auto it = layersCopy.begin(); it != layersCopy.end(); ++it )
386 if (
const QgsGroupLayer *groupLayer = qobject_cast<QgsGroupLayer *>( *it ) )
388 auto existingIt = mGroupLayers.find( groupLayer->id() );
389 if ( existingIt != mGroupLayers.end( ) )
391 *it = ( *existingIt ).second.get();
395 std::unique_ptr<QgsGroupLayer> groupLayerClone { groupLayer->clone() };
396 mGroupLayers[ groupLayer->id() ] = std::move( groupLayerClone );
397 *it = mGroupLayers[ groupLayer->id() ].get();
401 mLayers = _qgis_listRawToRef( layersCopy );
406 if ( overrides == mLayerStyleOverrides )
409 mLayerStyleOverrides = overrides;
416 mLayerStyleOverrides.clear();
423 mLayerStyleOverrides.insert( layer->id(), style.
xmlData() );
430 if ( mFollowVisibilityPreset == follow )
433 mFollowVisibilityPreset = follow;
435 if ( !mFollowVisibilityPresetName.isEmpty() )
436 emit
themeChanged( mFollowVisibilityPreset ? mFollowVisibilityPresetName : QString() );
441 if ( name == mFollowVisibilityPresetName )
444 mFollowVisibilityPresetName = name;
445 if ( mFollowVisibilityPreset )
451 mLastRenderedImageOffsetX -= dx;
452 mLastRenderedImageOffsetY -= dy;
455 transformShift( dx, dy );
456 mExtent.setXMinimum( mExtent.xMinimum() + dx );
457 mExtent.setXMaximum( mExtent.xMaximum() + dx );
458 mExtent.setYMinimum( mExtent.yMinimum() + dy );
459 mExtent.setYMaximum( mExtent.yMaximum() + dy );
478 double mapX = mExtent.xMinimum() + ( point.x() / rect().width() ) * ( mExtent.xMaximum() - mExtent.xMinimum() );
479 double mapY = mExtent.yMinimum() + ( 1 - ( point.y() / rect().height() ) ) * ( mExtent.yMaximum() - mExtent.yMinimum() );
482 double centerX = ( mExtent.xMaximum() + mExtent.xMinimum() ) / 2;
483 double centerY = ( mExtent.yMaximum() + mExtent.yMinimum() ) / 2;
485 centerX = mapX + ( centerX - mapX ) * ( 1.0 / factor );
486 centerY = mapY + ( centerY - mapY ) * ( 1.0 / factor );
488 double newIntervalX, newIntervalY;
492 newIntervalX = ( mExtent.xMaximum() - mExtent.xMinimum() ) / factor;
493 newIntervalY = ( mExtent.yMaximum() - mExtent.yMinimum() ) / factor;
500 mExtent.setXMaximum( centerX + newIntervalX / 2 );
501 mExtent.setXMinimum( centerX - newIntervalX / 2 );
502 mExtent.setYMaximum( centerY + newIntervalY / 2 );
503 mExtent.setYMinimum( centerY - newIntervalY / 2 );
505 if ( mAtlasDriven && mAtlasScalingMode ==
Fixed )
512 calculator.
setDpi( 25.4 );
517 const double newScale = calculator.
calculate( mExtent, rect().width() );
520 const double scaleRatio =
scale() / newScale ;
521 mExtent.scale( scaleRatio );
538 if ( layer->dataProvider() && layer->providerType() == QLatin1String(
"wms" ) )
548 if (
blendMode() != QPainter::CompositionMode_SourceOver )
567 auto containsAdvancedEffectsIgnoreItemOpacity = [
this]()->
bool
577 if ( mOverviewStack->containsAdvancedEffects() )
585 if ( mGridStack->containsAdvancedEffects() )
598 if ( !containsAdvancedEffectsIgnoreItemOpacity() )
619 if ( mOverviewStack->containsAdvancedEffects() )
627 if ( mGridStack->containsAdvancedEffects() )
642 mMapRotation = rotation;
643 mEvaluatedMapRotation = mMapRotation;
656 mAtlasDriven = enabled;
673 double margin = mAtlasMargin;
681 margin = ddMargin / 100;
693 if ( mGridStack->size() < 1 )
696 mGridStack->addGrid(
grid );
698 return mGridStack->grid( 0 );
703 if ( mOverviewStack->size() < 1 )
706 mOverviewStack->addOverview(
overview );
708 return mOverviewStack->overview( 0 );
718 for (
int i = 0; i < mGridStack->size(); ++i )
721 if (
grid->mEvaluatedEnabled )
724 frameBleed = std::max( frameBleed,
grid->mEvaluatedGridFrameWidth +
grid->mEvaluatedGridFrameMargin +
grid->mEvaluatedGridFrameLineThickness / 2.0 );
740 mapElem.setAttribute( QStringLiteral(
"keepLayerSet" ), QStringLiteral(
"true" ) );
744 mapElem.setAttribute( QStringLiteral(
"keepLayerSet" ), QStringLiteral(
"false" ) );
747 if ( mDrawAnnotations )
749 mapElem.setAttribute( QStringLiteral(
"drawCanvasItems" ), QStringLiteral(
"true" ) );
753 mapElem.setAttribute( QStringLiteral(
"drawCanvasItems" ), QStringLiteral(
"false" ) );
757 QDomElement extentElem = doc.createElement( QStringLiteral(
"Extent" ) );
758 extentElem.setAttribute( QStringLiteral(
"xmin" ),
qgsDoubleToString( mExtent.xMinimum() ) );
759 extentElem.setAttribute( QStringLiteral(
"xmax" ),
qgsDoubleToString( mExtent.xMaximum() ) );
760 extentElem.setAttribute( QStringLiteral(
"ymin" ),
qgsDoubleToString( mExtent.yMinimum() ) );
761 extentElem.setAttribute( QStringLiteral(
"ymax" ),
qgsDoubleToString( mExtent.yMaximum() ) );
762 mapElem.appendChild( extentElem );
764 if ( mCrs.isValid() )
766 QDomElement crsElem = doc.createElement( QStringLiteral(
"crs" ) );
767 mCrs.writeXml( crsElem, doc );
768 mapElem.appendChild( crsElem );
772 mapElem.setAttribute( QStringLiteral(
"followPreset" ), mFollowVisibilityPreset ? QStringLiteral(
"true" ) : QStringLiteral(
"false" ) );
773 mapElem.setAttribute( QStringLiteral(
"followPresetName" ), mFollowVisibilityPresetName );
776 mapElem.setAttribute( QStringLiteral(
"mapRotation" ), QString::number( mMapRotation ) );
779 QDomElement layerSetElem = doc.createElement( QStringLiteral(
"LayerSet" ) );
784 QDomElement layerElem = doc.createElement( QStringLiteral(
"Layer" ) );
786 const auto it = std::find_if( mGroupLayers.cbegin(), mGroupLayers.cend(), [ &layerRef ](
const std::pair<
const QString, std::unique_ptr<QgsGroupLayer>> &groupLayer ) ->
bool
788 return groupLayer.second.get() == layerRef.get();
791 if ( it != mGroupLayers.end() )
797 layerId = layerRef.layerId;
800 QDomText layerIdText = doc.createTextNode( layerId );
801 layerElem.appendChild( layerIdText );
803 layerElem.setAttribute( QStringLiteral(
"name" ), layerRef.name );
804 layerElem.setAttribute( QStringLiteral(
"source" ), layerRef.source );
805 layerElem.setAttribute( QStringLiteral(
"provider" ), layerRef.provider );
807 if ( it != mGroupLayers.end() )
809 const auto childLayers { it->second->childLayers() };
810 QDomElement childLayersElement = doc.createElement( QStringLiteral(
"childLayers" ) );
811 for (
const QgsMapLayer *childLayer : std::as_const( childLayers ) )
813 QDomElement childElement = doc.createElement( QStringLiteral(
"child" ) );
814 childElement.setAttribute( QStringLiteral(
"layerid" ), childLayer->id() );
815 childLayersElement.appendChild( childElement );
817 layerElem.appendChild( childLayersElement );
819 layerSetElem.appendChild( layerElem );
821 mapElem.appendChild( layerSetElem );
824 if ( mKeepLayerStyles )
826 QDomElement stylesElem = doc.createElement( QStringLiteral(
"LayerStyles" ) );
827 for (
auto styleIt = mLayerStyleOverrides.constBegin(); styleIt != mLayerStyleOverrides.constEnd(); ++styleIt )
829 QDomElement styleElem = doc.createElement( QStringLiteral(
"LayerStyle" ) );
834 styleElem.setAttribute( QStringLiteral(
"layerid" ), ref.
layerId );
835 styleElem.setAttribute( QStringLiteral(
"name" ), ref.
name );
836 styleElem.setAttribute( QStringLiteral(
"source" ), ref.
source );
837 styleElem.setAttribute( QStringLiteral(
"provider" ), ref.
provider );
841 stylesElem.appendChild( styleElem );
843 mapElem.appendChild( stylesElem );
847 mGridStack->writeXml( mapElem, doc, context );
850 mOverviewStack->writeXml( mapElem, doc, context );
853 QDomElement atlasElem = doc.createElement( QStringLiteral(
"AtlasMap" ) );
854 atlasElem.setAttribute( QStringLiteral(
"atlasDriven" ), mAtlasDriven );
855 atlasElem.setAttribute( QStringLiteral(
"scalingMode" ), mAtlasScalingMode );
856 atlasElem.setAttribute( QStringLiteral(
"margin" ),
qgsDoubleToString( mAtlasMargin ) );
857 mapElem.appendChild( atlasElem );
859 mapElem.setAttribute( QStringLiteral(
"labelMargin" ), mLabelMargin.encodeMeasurement() );
860 mapElem.setAttribute( QStringLiteral(
"mapFlags" ),
static_cast< int>( mMapFlags ) );
862 QDomElement labelBlockingItemsElem = doc.createElement( QStringLiteral(
"labelBlockingItems" ) );
863 for (
const auto &item : std::as_const( mBlockingLabelItems ) )
868 QDomElement blockingItemElem = doc.createElement( QStringLiteral(
"item" ) );
869 blockingItemElem.setAttribute( QStringLiteral(
"uuid" ), item->uuid() );
870 labelBlockingItemsElem.appendChild( blockingItemElem );
872 mapElem.appendChild( labelBlockingItemsElem );
875 mapElem.setAttribute( QStringLiteral(
"isTemporal" ),
isTemporal() ? 1 : 0 );
878 mapElem.setAttribute( QStringLiteral(
"temporalRangeBegin" ),
temporalRange().begin().toString( Qt::ISODate ) );
879 mapElem.setAttribute( QStringLiteral(
"temporalRangeEnd" ),
temporalRange().end().toString( Qt::ISODate ) );
882 mapElem.setAttribute( QStringLiteral(
"enableZRange" ), mZRangeEnabled ? 1 : 0 );
883 if ( mZRange.lower() != std::numeric_limits< double >::lowest() )
884 mapElem.setAttribute( QStringLiteral(
"zRangeLower" ),
qgsDoubleToString( mZRange.lower() ) );
885 if ( mZRange.upper() != std::numeric_limits< double >::max() )
886 mapElem.setAttribute( QStringLiteral(
"zRangeUpper" ),
qgsDoubleToString( mZRange.upper() ) );
888 mAtlasClippingSettings->writeXml( mapElem, doc, context );
889 mItemClippingSettings->writeXml( mapElem, doc, context );
896 mUpdatesEnabled =
false;
899 QDomNodeList extentNodeList = itemElem.elementsByTagName( QStringLiteral(
"Extent" ) );
900 if ( !extentNodeList.isEmpty() )
902 QDomElement extentElem = extentNodeList.at( 0 ).toElement();
903 double xmin, xmax, ymin, ymax;
904 xmin = extentElem.attribute( QStringLiteral(
"xmin" ) ).toDouble();
905 xmax = extentElem.attribute( QStringLiteral(
"xmax" ) ).toDouble();
906 ymin = extentElem.attribute( QStringLiteral(
"ymin" ) ).toDouble();
907 ymax = extentElem.attribute( QStringLiteral(
"ymax" ) ).toDouble();
911 QDomNodeList crsNodeList = itemElem.elementsByTagName( QStringLiteral(
"crs" ) );
913 if ( !crsNodeList.isEmpty() )
915 QDomElement crsElem = crsNodeList.at( 0 ).toElement();
916 crs.readXml( crsElem );
921 mMapRotation = itemElem.attribute( QStringLiteral(
"mapRotation" ), QStringLiteral(
"0" ) ).toDouble();
922 mEvaluatedMapRotation = mMapRotation;
925 mFollowVisibilityPreset = itemElem.attribute( QStringLiteral(
"followPreset" ) ).compare( QLatin1String(
"true" ) ) == 0;
926 mFollowVisibilityPresetName = itemElem.attribute( QStringLiteral(
"followPresetName" ) );
929 QString keepLayerSetFlag = itemElem.attribute( QStringLiteral(
"keepLayerSet" ) );
930 if ( keepLayerSetFlag.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
932 mKeepLayerSet =
true;
936 mKeepLayerSet =
false;
939 QString drawCanvasItemsFlag = itemElem.attribute( QStringLiteral(
"drawCanvasItems" ), QStringLiteral(
"true" ) );
940 if ( drawCanvasItemsFlag.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
942 mDrawAnnotations =
true;
946 mDrawAnnotations =
false;
949 mLayerStyleOverrides.clear();
951 QList<QgsMapLayerRef> layerSet;
952 QDomNodeList layerSetNodeList = itemElem.elementsByTagName( QStringLiteral(
"LayerSet" ) );
953 if ( !layerSetNodeList.isEmpty() )
955 QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
956 QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( QStringLiteral(
"Layer" ) );
957 layerSet.reserve( layerIdNodeList.size() );
958 for (
int i = 0; i < layerIdNodeList.size(); ++i )
960 QDomElement layerElem = layerIdNodeList.at( i ).toElement();
961 QString layerId = layerElem.text();
962 QString layerName = layerElem.attribute( QStringLiteral(
"name" ) );
963 QString layerSource = layerElem.attribute( QStringLiteral(
"source" ) );
964 QString layerProvider = layerElem.attribute( QStringLiteral(
"provider" ) );
966 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
974 setLayers( _qgis_listRefToRaw( layerSet ) );
977 if ( !layerSetNodeList.isEmpty() )
979 QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
980 QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( QStringLiteral(
"Layer" ) );
981 for (
int i = 0; i < layerIdNodeList.size(); ++i )
983 QDomElement layerElem = layerIdNodeList.at( i ).toElement();
984 const QString layerId = layerElem.text();
985 const auto it = mGroupLayers.find( layerId );
986 if ( it != mGroupLayers.cend() )
988 QList<QgsMapLayerRef> childSet;
989 const QDomNodeList childLayersElements = layerElem.elementsByTagName( QStringLiteral(
"childLayers" ) );
990 const QDomNodeList children = childLayersElements.at( 0 ).childNodes();
991 for (
int i = 0; i < children.size(); ++i )
993 const QDomElement childElement = children.at( i ).toElement();
994 const QString
id = childElement.attribute( QStringLiteral(
"layerid" ) );
998 childSet.push_back( layerRef );
1001 it->second->setChildLayers( _qgis_listRefToRaw( childSet ) );
1008 QDomNodeList layerStylesNodeList = itemElem.elementsByTagName( QStringLiteral(
"LayerStyles" ) );
1009 mKeepLayerStyles = !layerStylesNodeList.isEmpty();
1010 if ( mKeepLayerStyles )
1012 QDomElement layerStylesElem = layerStylesNodeList.at( 0 ).toElement();
1013 QDomNodeList layerStyleNodeList = layerStylesElem.elementsByTagName( QStringLiteral(
"LayerStyle" ) );
1014 for (
int i = 0; i < layerStyleNodeList.size(); ++i )
1016 const QDomElement &layerStyleElement = layerStyleNodeList.at( i ).toElement();
1017 QString layerId = layerStyleElement.attribute( QStringLiteral(
"layerid" ) );
1018 QString layerName = layerStyleElement.attribute( QStringLiteral(
"name" ) );
1019 QString layerSource = layerStyleElement.attribute( QStringLiteral(
"source" ) );
1020 QString layerProvider = layerStyleElement.attribute( QStringLiteral(
"provider" ) );
1021 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
1025 style.
readXml( layerStyleElement );
1031 mNumCachedLayers = 0;
1032 mCacheInvalidated =
true;
1035 mOverviewStack->readXml( itemElem, doc, context );
1038 mGridStack->readXml( itemElem, doc, context );
1041 QDomNodeList atlasNodeList = itemElem.elementsByTagName( QStringLiteral(
"AtlasMap" ) );
1042 if ( !atlasNodeList.isEmpty() )
1044 QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1045 mAtlasDriven = ( atlasElem.attribute( QStringLiteral(
"atlasDriven" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
1046 if ( atlasElem.hasAttribute( QStringLiteral(
"fixedScale" ) ) )
1048 mAtlasScalingMode = ( atlasElem.attribute( QStringLiteral(
"fixedScale" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) ) ?
Fixed :
Auto;
1050 else if ( atlasElem.hasAttribute( QStringLiteral(
"scalingMode" ) ) )
1052 mAtlasScalingMode =
static_cast<AtlasScalingMode>( atlasElem.attribute( QStringLiteral(
"scalingMode" ) ).toInt() );
1054 mAtlasMargin = atlasElem.attribute( QStringLiteral(
"margin" ), QStringLiteral(
"0.1" ) ).toDouble();
1059 mMapFlags =
static_cast< MapItemFlags>( itemElem.attribute( QStringLiteral(
"mapFlags" ),
nullptr ).toInt() );
1062 mBlockingLabelItems.clear();
1063 mBlockingLabelItemUuids.clear();
1064 QDomNodeList labelBlockingNodeList = itemElem.elementsByTagName( QStringLiteral(
"labelBlockingItems" ) );
1065 if ( !labelBlockingNodeList.isEmpty() )
1067 QDomElement blockingItems = labelBlockingNodeList.at( 0 ).toElement();
1068 QDomNodeList labelBlockingNodeList = blockingItems.childNodes();
1069 for (
int i = 0; i < labelBlockingNodeList.size(); ++i )
1071 const QDomElement &itemBlockingElement = labelBlockingNodeList.at( i ).toElement();
1072 const QString itemUuid = itemBlockingElement.attribute( QStringLiteral(
"uuid" ) );
1073 mBlockingLabelItemUuids << itemUuid;
1077 mAtlasClippingSettings->readXml( itemElem, doc, context );
1078 mItemClippingSettings->readXml( itemElem, doc, context );
1083 setIsTemporal( itemElem.attribute( QStringLiteral(
"isTemporal" ) ).toInt() );
1086 const QDateTime begin = QDateTime::fromString( itemElem.attribute( QStringLiteral(
"temporalRangeBegin" ) ), Qt::ISODate );
1087 const QDateTime end = QDateTime::fromString( itemElem.attribute( QStringLiteral(
"temporalRangeEnd" ) ), Qt::ISODate );
1091 mZRangeEnabled = itemElem.attribute( QStringLiteral(
"enableZRange" ) ).toInt();
1093 double zLower = itemElem.attribute( QStringLiteral(
"zRangeLower" ) ).toDouble( &ok );
1096 zLower = std::numeric_limits< double >::lowest();
1098 double zUpper = itemElem.attribute( QStringLiteral(
"zRangeUpper" ) ).toDouble( &ok );
1101 zUpper = std::numeric_limits< double >::max();
1105 mUpdatesEnabled =
true;
1109bool QgsLayoutItemMap::hasCustomFramePath()
const
1120 return mItemClippingSettings->isActive();
1125 QPainterPath customFramePath;
1126 if ( mAtlasClippingSettings->enabled() && mAtlasClippingSettings->clipItemShape() )
1131 QPolygonF visibleExtent = calculateVisibleExtentPolygon(
false );
1132 QPolygonF rectPoly = QPolygonF( QRectF( 0, 0, rect().width(), rect().height() ) );
1135 visibleExtent.pop_back();
1136 rectPoly.pop_back();
1139 QTransform transform;
1140 QTransform::quadToQuad( visibleExtent, rectPoly, transform );
1150 if ( mItemClippingSettings->isActive() )
1152 const QgsGeometry g = mItemClippingSettings->clipPathInMapItemCoordinates();
1155 if ( !customFramePath.isEmpty() )
1158 customFramePath.closeSubpath();
1172 if ( !
mLayout || !painter || !painter->device() || !mUpdatesEnabled )
1181 QRectF thisPaintRect = rect();
1187 if (
mLayout->renderContext().isPreviewRender() )
1189 bool renderInProgress =
false;
1190 mPreviewDevicePixelRatio = painter->device()->devicePixelRatioF();
1193 painter->setClipRect( thisPaintRect );
1194 if ( !mCacheFinalImage || mCacheFinalImage->isNull() )
1197 painter->setBrush( QBrush( QColor( 125, 125, 125, 125 ) ) );
1198 painter->drawRect( thisPaintRect );
1199 painter->setBrush( Qt::NoBrush );
1201 messageFont.setPointSize( 12 );
1202 painter->setFont( messageFont );
1203 painter->setPen( QColor( 255, 255, 255, 255 ) );
1204 painter->drawText( thisPaintRect, Qt::AlignCenter | Qt::AlignHCenter, tr(
"Rendering map" ) );
1205 if ( mPainterJob && mCacheInvalidated && !mDrawingPreview )
1209 mBackgroundUpdateTimer->start( 100 );
1211 else if ( !mPainterJob && !mDrawingPreview )
1215 mBackgroundUpdateTimer->start( 100 );
1217 renderInProgress =
true;
1221 if ( mCacheInvalidated && !mDrawingPreview )
1225 mBackgroundUpdateTimer->start( 100 );
1226 renderInProgress =
true;
1231 double imagePixelWidth = mCacheFinalImage->width();
1232 double scale = rect().width() / imagePixelWidth * mCacheFinalImage->devicePixelRatio();
1236 painter->translate( mLastRenderedImageOffsetX + mXOffset, mLastRenderedImageOffsetY + mYOffset );
1237 painter->setCompositionMode( blendModeForRender() );
1239 painter->drawImage( 0, 0, *mCacheFinalImage );
1244 painter->setClipRect( thisPaintRect, Qt::NoClip );
1246 mOverviewStack->drawItems( painter,
false );
1247 mGridStack->drawItems( painter );
1249 drawMapFrame( painter );
1251 if ( renderInProgress )
1262 QPaintDevice *paintDevice = painter->device();
1270 painter->setRenderHint( QPainter::LosslessImageRendering,
true );
1275 && ( !
mLayout || !forceVector ) )
1280 int widthInPixels =
static_cast< int >( std::round(
boundingRect().width() * layoutUnitsInInches * destinationDpi ) );
1281 int heightInPixels =
static_cast< int >( std::round(
boundingRect().height() * layoutUnitsInInches * destinationDpi ) );
1282 QImage image = QImage( widthInPixels, heightInPixels, QImage::Format_ARGB32 );
1284 image.fill( Qt::transparent );
1285 image.setDotsPerMeterX(
static_cast< int >( std::round( 1000 * destinationDpi / 25.4 ) ) );
1286 image.setDotsPerMeterY(
static_cast< int >( std::round( 1000 * destinationDpi / 25.4 ) ) );
1287 double dotsPerMM = destinationDpi / 25.4;
1288 QPainter p( &image );
1291 QRect imagePaintRect(
static_cast< int >( std::round( tl.x() * dotsPerMM ) ),
1292 static_cast< int >( std::round( tl.y() * dotsPerMM ) ),
1293 static_cast< int >( std::round( thisPaintRect.width() * dotsPerMM ) ),
1294 static_cast< int >( std::round( thisPaintRect.height() * dotsPerMM ) ) );
1295 p.setClipRect( imagePaintRect );
1297 p.translate( imagePaintRect.topLeft() );
1301 if ( shouldDrawPart( Background ) )
1303 p.scale( dotsPerMM, dotsPerMM );
1304 drawMapBackground( &p );
1305 p.scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
1308 drawMap( &p, cExtent, imagePaintRect.size(), image.logicalDpiX() );
1313 p.scale( dotsPerMM, dotsPerMM );
1315 if ( shouldDrawPart( OverviewMapExtent ) )
1317 mOverviewStack->drawItems( &p,
false );
1319 if ( shouldDrawPart( Grid ) )
1321 mGridStack->drawItems( &p );
1326 painter->setCompositionMode( blendModeForRender() );
1327 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
1328 painter->drawImage( QPointF( -tl.x()* dotsPerMM, -tl.y() * dotsPerMM ), image );
1329 painter->scale( dotsPerMM, dotsPerMM );
1334 if ( shouldDrawPart( Background ) )
1336 drawMapBackground( painter );
1340 painter->setClipRect( thisPaintRect );
1345 painter->translate( mXOffset, mYOffset );
1347 double dotsPerMM = paintDevice->logicalDpiX() / 25.4;
1349 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
1351 if ( mCurrentExportPart != NotLayered )
1353 if ( !mStagedRendererJob )
1355 createStagedRenderJob( cExtent, size, paintDevice->logicalDpiX() );
1358 mStagedRendererJob->renderCurrentPart( painter );
1362 drawMap( painter, cExtent, size, paintDevice->logicalDpiX() );
1366 painter->setClipRect( thisPaintRect, Qt::NoClip );
1368 if ( shouldDrawPart( OverviewMapExtent ) )
1370 mOverviewStack->drawItems( painter,
false );
1372 if ( shouldDrawPart( Grid ) )
1374 mGridStack->drawItems( painter );
1379 if ( shouldDrawPart( Frame ) )
1381 drawMapFrame( painter );
1392 + ( layerCount + ( layerCount ? 1 : 0 ) )
1393 + ( mGridStack->hasEnabledItems() ? 1 : 0 )
1394 + ( mOverviewStack->hasEnabledItems() ? 1 : 0 )
1400 mCurrentExportPart = Start;
1402 mExportThemes = !mFollowVisibilityPreset ?
mLayout->renderContext().exportThemes() : QStringList();
1403 mExportThemeIt = mExportThemes.begin();
1408 mCurrentExportPart = NotLayered;
1409 mExportThemes.clear();
1410 mExportThemeIt = mExportThemes.begin();
1415 switch ( mCurrentExportPart )
1420 mCurrentExportPart = Background;
1426 mCurrentExportPart = Layer;
1430 if ( mStagedRendererJob )
1432 if ( mStagedRendererJob->nextPart() )
1436 mExportLabelingResults.reset( mStagedRendererJob->takeLabelingResults() );
1437 mStagedRendererJob.reset();
1441 if ( mExportThemeIt != mExportThemes.end() && ++mExportThemeIt != mExportThemes.end() )
1447 if ( mGridStack->hasEnabledItems() )
1449 mCurrentExportPart = Grid;
1455 for (
int i = 0; i < mOverviewStack->size(); ++i )
1460 mCurrentExportPart = OverviewMapExtent;
1466 case OverviewMapExtent:
1469 mCurrentExportPart = Frame;
1476 if ( isSelected() && !
mLayout->renderContext().isPreviewRender() )
1478 mCurrentExportPart = SelectionBoxes;
1483 case SelectionBoxes:
1484 mCurrentExportPart = End;
1505 switch ( mCurrentExportPart )
1515 if ( !mExportThemes.empty() && mExportThemeIt != mExportThemes.end() )
1518 if ( mStagedRendererJob )
1520 switch ( mStagedRendererJob->currentStage() )
1524 detail.
mapLayerId = mStagedRendererJob->currentLayerId();
1525 detail.
compositionMode = mStagedRendererJob->currentLayerCompositionMode();
1526 detail.
opacity = mStagedRendererJob->currentLayerOpacity();
1532 detail.
name = QStringLiteral(
"%1: %2" ).arg(
displayName(), layer->name() );
1534 else if (
mLayout->project()->mainAnnotationLayer()->id() == detail.
mapLayerId )
1540 detail.
name = QStringLiteral(
"%1: %2" ).arg(
displayName(), tr(
"Annotations" ) );
1545 const QList<QgsLayoutItemMapOverview *> res = mOverviewStack->asList();
1551 if ( item->mapLayer() && detail.
mapLayerId == item->mapLayer()->id() )
1554 detail.
name = QStringLiteral(
"%1 (%2): %3" ).arg(
displayName(), detail.
mapTheme, item->mapLayer()->name() );
1556 detail.
name = QStringLiteral(
"%1: %2" ).arg(
displayName(), item->mapLayer()->name() );
1565 detail.
mapLayerId = mStagedRendererJob->currentLayerId();
1571 detail.
name = tr(
"%1: %2 (Labels)" ).arg(
displayName(), layer->name() );
1606 case OverviewMapExtent:
1614 case SelectionBoxes:
1629void QgsLayoutItemMap::drawMap( QPainter *painter,
const QgsRectangle &extent, QSizeF size,
double dpi )
1643 if ( shouldDrawPart( OverviewMapExtent ) )
1645 ms.setLayers( mOverviewStack->modifyMapLayerList( ms.layers() ) );
1648 QgsMapRendererCustomPainterJob job( ms, painter );
1649#ifdef HAVE_SERVER_PYTHON_PLUGINS
1650 job.setFeatureFilterProvider(
mLayout->renderContext().featureFilterProvider() );
1653 QgsGroupedFeatureFilterProvider jobFeatureFilter;
1656 jobFeatureFilter.
addProvider( mAtlasFeatureFilterProvider.get() );
1657 if ( job.featureFilterProvider() )
1659 jobFeatureFilter.
addProvider( job.featureFilterProvider() );
1661 job.setFeatureFilterProvider( &jobFeatureFilter );
1667 job.renderSynchronously();
1669 mExportLabelingResults.reset( job.takeLabelingResults() );
1671 mRenderingErrors = job.errors();
1675 mRenderingErrors.append( QgsMapRendererJob::Error( QString(), QStringLiteral(
"Invalid layer(s)" ) ) );
1679void QgsLayoutItemMap::recreateCachedImageInBackground()
1684 QgsMapRendererCustomPainterJob *oldJob = mPainterJob.release();
1685 QPainter *oldPainter = mPainter.release();
1686 QImage *oldImage = mCacheRenderingImage.release();
1689 oldJob->deleteLater();
1697 mCacheRenderingImage.reset(
nullptr );
1701 Q_ASSERT( !mPainterJob );
1702 Q_ASSERT( !mPainter );
1703 Q_ASSERT( !mCacheRenderingImage );
1705 QgsRectangle ext =
extent();
1709 int w =
static_cast< int >( std::round( widthLayoutUnits * mPreviewScaleFactor ) );
1710 int h =
static_cast< int >( std::round( heightLayoutUnits * mPreviewScaleFactor ) );
1713 if ( w > 5000 || h > 5000 )
1718 h =
static_cast< int>( std::round( w * heightLayoutUnits / widthLayoutUnits ) );
1723 w =
static_cast< int >( std::round( h * widthLayoutUnits / heightLayoutUnits ) );
1727 if ( w <= 0 || h <= 0 )
1730 mCacheRenderingImage = std::make_unique<QImage>( w * mPreviewDevicePixelRatio, h * mPreviewDevicePixelRatio, QImage::Format_ARGB32 );
1733 mCacheRenderingImage->setDotsPerMeterX(
static_cast< int >( std::round( 1000 * w / widthLayoutUnits ) ) );
1734 mCacheRenderingImage->setDotsPerMeterY(
static_cast< int >( std::round( 1000 * h / heightLayoutUnits ) ) );
1735 mCacheRenderingImage->setDevicePixelRatio( mPreviewDevicePixelRatio );
1738 mCacheRenderingImage->fill( QColor( 255, 255, 255, 0 ).rgba() );
1743 if ( hasCustomFramePath() )
1745 QPainter p( mCacheRenderingImage.get() );
1747 p.setPen( Qt::NoPen );
1749 p.scale( mCacheRenderingImage->width() / widthLayoutUnits, mCacheRenderingImage->height() / heightLayoutUnits );
1759 mCacheInvalidated =
false;
1760 mPainter = std::make_unique<QPainter>( mCacheRenderingImage.get() );
1761 QgsMapSettings settings(
mapSettings( ext, QSizeF( w, h ), mCacheRenderingImage->logicalDpiX(),
true ) );
1763 if ( shouldDrawPart( OverviewMapExtent ) )
1765 settings.setLayers( mOverviewStack->modifyMapLayerList( settings.layers() ) );
1768 mPainterJob = std::make_unique<QgsMapRendererCustomPainterJob>( settings, mPainter.get() );
1771 mPainterJob->setFeatureFilterProvider( mAtlasFeatureFilterProvider.get() );
1774 mPainterJob->start();
1786 mDrawingPreview =
false;
1809 if (
layout()->renderContext().isPreviewRender() )
1812 jobMapSettings.
setDevicePixelRatio( mPainter ? mPainter->device()->devicePixelRatioF() : 1.0 );
1815 jobMapSettings.
setRotation( mEvaluatedMapRotation );
1823 if ( includeLayerSettings )
1828 if ( !
mLayout->project()->mainAnnotationLayer()->isEmpty() )
1831 layers.insert( 0,
mLayout->project()->mainAnnotationLayer() );
1838 if ( !
mLayout->renderContext().isPreviewRender() )
1886 if ( mEvaluatedLabelMargin.length() > 0 )
1889 visiblePoly.append( visiblePoly.at( 0 ) );
1890 const double layoutLabelMargin =
mLayout->convertToLayoutUnits( mEvaluatedLabelMargin );
1891 const double layoutLabelMarginInMapUnits = layoutLabelMargin / rect().width() * jobMapSettings.
extent().
width();
1893 mapBoundaryGeom = mapBoundaryGeom.
buffer( -layoutLabelMarginInMapUnits, 0 );
1894 labelBoundary = mapBoundaryGeom;
1897 if ( !mBlockingLabelItems.isEmpty() )
1910 if ( mZRangeEnabled )
1915 if ( mAtlasClippingSettings->enabled() &&
mLayout->reportContext().feature().isValid() )
1919 region.
setFeatureClip( mAtlasClippingSettings->featureClippingType() );
1924 if ( mAtlasClippingSettings->forceLabelsInsideFeature() )
1926 if ( !labelBoundary.
isEmpty() )
1928 labelBoundary = clipGeom.
intersection( labelBoundary );
1932 labelBoundary = clipGeom;
1937 if ( mItemClippingSettings->isActive() )
1939 const QgsGeometry clipGeom = mItemClippingSettings->clippedMapExtent();
1942 jobMapSettings.
addClippingRegion( mItemClippingSettings->toMapClippingRegion() );
1944 if ( mItemClippingSettings->forceLabelsInsideClipPath() )
1946 const double layoutLabelMargin =
mLayout->convertToLayoutUnits( mEvaluatedLabelMargin );
1947 const double layoutLabelMarginInMapUnits = layoutLabelMargin / rect().width() * jobMapSettings.
extent().
width();
1949 mapBoundaryGeom = mapBoundaryGeom.
buffer( -layoutLabelMarginInMapUnits, 0 );
1950 if ( !labelBoundary.
isEmpty() )
1952 labelBoundary = mapBoundaryGeom.
intersection( labelBoundary );
1956 labelBoundary = mapBoundaryGeom;
1962 if ( !labelBoundary.
isNull() )
1965 return jobMapSettings;
1972 mBlockingLabelItems.clear();
1973 for (
const QString &
uuid : std::as_const( mBlockingLabelItemUuids ) )
1982 mOverviewStack->finalizeRestoreFromXml();
1983 mGridStack->finalizeRestoreFromXml();
1984 mItemClippingSettings->finalizeRestoreFromXml();
1995 return mCurrentRectangle;
2009 const double mapScale =
scale();
2033 QVariantList layersIds;
2043 const QList<QgsMapLayer *> layersInMap =
layersToRender( &context );
2045 layersIds.reserve( layersInMap.count() );
2046 layers.reserve( layersInMap.count() );
2049 layersIds << layer->id();
2055 scope->
addFunction( QStringLiteral(
"is_layer_visible" ),
new QgsExpressionContextUtils::GetLayerVisibility( layersInMap,
scale() ) );
2077 if ( extentWidth <= 0 )
2081 return rect().width() / extentWidth;
2086 double dx = mXOffset;
2087 double dy = mYOffset;
2088 transformShift( dx, dy );
2089 QPolygonF poly = calculateVisibleExtentPolygon(
false );
2090 poly.translate( -dx, -dy );
2096 if ( !mBlockingLabelItems.contains( item ) )
2097 mBlockingLabelItems.append( item );
2104 mBlockingLabelItems.removeAll( item );
2111 return mBlockingLabelItems.contains( item );
2116 return mPreviewLabelingResults.get();
2125 if ( mOverviewStack )
2127 for (
int i = 0; i < mOverviewStack->size(); ++i )
2129 if ( mOverviewStack->item( i )->accept( visitor ) )
2136 for (
int i = 0; i < mGridStack->size(); ++i )
2138 if ( mGridStack->item( i )->accept( visitor ) )
2151 mRenderedFeatureHandlers.append( handler );
2156 mRenderedFeatureHandlers.removeAll( handler );
2162 if ( mapPoly.empty() )
2164 return QPointF( 0, 0 );
2169 double dx = mapCoords.x() - rotationPoint.
x();
2170 double dy = mapCoords.y() - rotationPoint.
y();
2172 QgsPointXY backRotatedCoords( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
2175 double xItem = rect().width() * ( backRotatedCoords.
x() - unrotatedExtent.
xMinimum() ) / unrotatedExtent.
width();
2176 double yItem = rect().height() * ( 1 - ( backRotatedCoords.
y() - unrotatedExtent.
yMinimum() ) / unrotatedExtent.
height() );
2177 return QPointF( xItem, yItem );
2191 mapPolygon( newExtent, poly );
2192 QRectF bRect = poly.boundingRect();
2193 extent.setXMinimum( bRect.left() );
2194 extent.setXMaximum( bRect.right() );
2195 extent.setYMinimum( bRect.top() );
2196 extent.setYMaximum( bRect.bottom() );
2206 mCacheInvalidated =
true;
2212 QRectF rectangle = rect();
2213 double frameExtension =
frameEnabled() ? pen().widthF() / 2.0 : 0.0;
2215 double topExtension = 0.0;
2216 double rightExtension = 0.0;
2217 double bottomExtension = 0.0;
2218 double leftExtension = 0.0;
2221 mGridStack->calculateMaxGridExtension( topExtension, rightExtension, bottomExtension, leftExtension );
2223 topExtension = std::max( topExtension, frameExtension );
2224 rightExtension = std::max( rightExtension, frameExtension );
2225 bottomExtension = std::max( bottomExtension, frameExtension );
2226 leftExtension = std::max( leftExtension, frameExtension );
2228 rectangle.setLeft( rectangle.left() - leftExtension );
2229 rectangle.setRight( rectangle.right() + rightExtension );
2230 rectangle.setTop( rectangle.top() - topExtension );
2231 rectangle.setBottom( rectangle.bottom() + bottomExtension );
2232 if ( rectangle != mCurrentRectangle )
2234 prepareGeometryChange();
2235 mCurrentRectangle = rectangle;
2263 refreshMapExtents( &context );
2265 if ( mExtent != beforeExtent )
2272 refreshLabelMargin(
false );
2276 const QString previousTheme = mLastEvaluatedThemeName.isEmpty() ? mFollowVisibilityPresetName : mLastEvaluatedThemeName;
2278 if ( mLastEvaluatedThemeName != previousTheme )
2297 double zLower = mZRange.lower();
2298 double zUpper = mZRange.upper();
2309 mCacheInvalidated =
true;
2314void QgsLayoutItemMap::layersAboutToBeRemoved(
const QList<QgsMapLayer *> &layers )
2317 if ( !mLayers.isEmpty() || mLayerStyleOverrides.isEmpty() )
2321 mLayerStyleOverrides.remove( layer->id() );
2323 _qgis_removeLayers( mLayers,
layers );
2326 for ( QgsMapLayer *layer : std::as_const(
layers ) )
2329 if ( mGroupLayers.erase( layer->id() ) == 0 )
2332 for (
auto it = mGroupLayers.begin(); it != mGroupLayers.end(); ++it )
2334 QgsGroupLayer *groupLayer = it->second.get();
2335 if ( groupLayer->
childLayers().contains( layer ) )
2337 QList<QgsMapLayer *> childLayers { groupLayer->
childLayers() };
2338 childLayers.removeAll( layer );
2346void QgsLayoutItemMap::painterJobFinished()
2349 mPreviewLabelingResults.reset( mPainterJob->takeLabelingResults() );
2350 mPainterJob.reset(
nullptr );
2351 mPainter.reset(
nullptr );
2352 mCacheFinalImage = std::move( mCacheRenderingImage );
2353 mLastRenderedImageOffsetX = 0;
2354 mLastRenderedImageOffsetY = 0;
2360void QgsLayoutItemMap::shapeChanged()
2363 QgsPointXY oldCenter = mExtent.center();
2365 double w = rect().width();
2366 double h = rect().height();
2369 double newWidth = mExtent.width();
2371 double newHeight = newWidth * h / w;
2376 refreshMapExtents();
2383void QgsLayoutItemMap::mapThemeChanged(
const QString &theme )
2385 if ( theme == mCachedLayerStyleOverridesPresetName )
2386 mCachedLayerStyleOverridesPresetName.clear();
2389void QgsLayoutItemMap::currentMapThemeRenamed(
const QString &theme,
const QString &newTheme )
2391 if ( theme == mFollowVisibilityPresetName )
2393 mFollowVisibilityPresetName = newTheme;
2397void QgsLayoutItemMap::connectUpdateSlot()
2400 QgsProject *project =
mLayout->project();
2405 this, &QgsLayoutItemMap::layersAboutToBeRemoved );
2409 if ( layers().isEmpty() )
2418 if ( !mCrs.isValid() )
2438 if ( mAtlasScalingMode == Predefined )
2439 updateAtlasFeature();
2445 QPolygonF thisExtent = calculateVisibleExtentPolygon(
false );
2446 QTransform mapTransform;
2447 QPolygonF thisRectPoly = QPolygonF( QRectF( 0, 0, rect().width(), rect().height() ) );
2449 thisRectPoly.pop_back();
2450 thisExtent.pop_back();
2452 QPolygonF thisItemPolyInLayout = mapToScene( thisRectPoly );
2455 QTransform::quadToQuad( thisItemPolyInLayout, thisExtent, mapTransform );
2456 return mapTransform;
2461 mZRangeEnabled = enabled;
2466 return mZRangeEnabled;
2479QList<QgsLabelBlockingRegion> QgsLayoutItemMap::createLabelBlockingRegions(
const QgsMapSettings & )
const
2482 QList< QgsLabelBlockingRegion > blockers;
2483 blockers.reserve( mBlockingLabelItems.count() );
2484 for (
const auto &item : std::as_const( mBlockingLabelItems ) )
2491 if ( item->property(
"wasVisible" ).isValid() )
2493 if ( !item->property(
"wasVisible" ).toBool() )
2496 else if ( !item->isVisible() )
2499 QPolygonF itemRectInMapCoordinates = mapTransform.map( item->mapToScene( item->rect() ) );
2500 itemRectInMapCoordinates.append( itemRectInMapCoordinates.at( 0 ) );
2502 blockers << QgsLabelBlockingRegion( blockingRegion );
2509 return mLabelMargin;
2514 mLabelMargin = margin;
2515 refreshLabelMargin(
false );
2518void QgsLayoutItemMap::updateToolTip()
2527 if ( mFollowVisibilityPreset )
2529 presetName = mFollowVisibilityPresetName;
2533 else if ( !mExportThemes.empty() && mExportThemeIt != mExportThemes.end() )
2534 presetName = *mExportThemeIt;
2545 QList<QgsMapLayer *> renderLayers;
2547 QString presetName = themeToRender( *evalContext );
2548 if ( !presetName.isEmpty() )
2550 if (
mLayout->project()->mapThemeCollection()->hasMapTheme( presetName ) )
2551 renderLayers =
mLayout->project()->mapThemeCollection()->mapThemeVisibleLayers( presetName );
2553 renderLayers =
mLayout->project()->mapThemeCollection()->masterVisibleLayers();
2555 else if ( !
layers().isEmpty() )
2561 renderLayers =
mLayout->project()->mapThemeCollection()->masterVisibleLayers();
2568 renderLayers.clear();
2570 const QStringList layerNames = ddLayers.split(
'|' );
2572 for (
const QString &name : layerNames )
2574 const QList< QgsMapLayer * > matchingLayers =
mLayout->project()->mapLayersByName( name );
2577 renderLayers << layer;
2586 int removeAt = renderLayers.indexOf(
mLayout->reportContext().layer() );
2587 if ( removeAt != -1 )
2589 renderLayers.removeAt( removeAt );
2594 if ( !includeInvalidLayers )
2596 renderLayers.erase( std::remove_if( renderLayers.begin(), renderLayers.end(), [](
QgsMapLayer * layer )
2598 return !layer || !layer->isValid();
2599 } ), renderLayers.end() );
2602 return renderLayers;
2605QMap<QString, QString> QgsLayoutItemMap::layerStyleOverridesToRender(
const QgsExpressionContext &context )
const
2607 QString presetName = themeToRender( context );
2608 if ( !presetName.isEmpty() )
2610 if (
mLayout->project()->mapThemeCollection()->hasMapTheme( presetName ) )
2612 if ( presetName != mCachedLayerStyleOverridesPresetName )
2615 mCachedPresetLayerStyleOverrides =
mLayout->project()->mapThemeCollection()->mapThemeStyleOverrides( presetName );
2616 mCachedLayerStyleOverridesPresetName = presetName;
2619 return mCachedPresetLayerStyleOverrides;
2622 return QMap<QString, QString>();
2624 else if ( mFollowVisibilityPreset )
2626 QString presetName = mFollowVisibilityPresetName;
2629 if (
mLayout->project()->mapThemeCollection()->hasMapTheme( presetName ) )
2631 if ( presetName.isEmpty() || presetName != mCachedLayerStyleOverridesPresetName )
2634 mCachedPresetLayerStyleOverrides =
mLayout->project()->mapThemeCollection()->mapThemeStyleOverrides( presetName );
2635 mCachedLayerStyleOverridesPresetName = presetName;
2638 return mCachedPresetLayerStyleOverrides;
2641 return QMap<QString, QString>();
2643 else if ( mKeepLayerStyles )
2645 return mLayerStyleOverrides;
2649 return QMap<QString, QString>();
2653QgsRectangle QgsLayoutItemMap::transformedExtent()
const
2655 double dx = mXOffset;
2656 double dy = mYOffset;
2657 transformShift( dx, dy );
2658 return QgsRectangle( mExtent.xMinimum() - dx, mExtent.yMinimum() - dy, mExtent.xMaximum() - dx, mExtent.yMaximum() - dy );
2661void QgsLayoutItemMap::mapPolygon(
const QgsRectangle &extent, QPolygonF &poly )
const
2666 poly << QPointF(
extent.xMinimum(),
extent.yMaximum() );
2667 poly << QPointF(
extent.xMaximum(),
extent.yMaximum() );
2668 poly << QPointF(
extent.xMaximum(),
extent.yMinimum() );
2669 poly << QPointF(
extent.xMinimum(),
extent.yMinimum() );
2671 poly << QPointF( poly.at( 0 ) );
2676 QgsPointXY rotationPoint( (
extent.xMaximum() +
extent.xMinimum() ) / 2.0, (
extent.yMaximum() +
extent.yMinimum() ) / 2.0 );
2680 dx = rotationPoint.x() -
extent.xMinimum();
2681 dy = rotationPoint.y() -
extent.yMaximum();
2683 poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2686 dx = rotationPoint.x() -
extent.xMaximum();
2687 dy = rotationPoint.y() -
extent.yMaximum();
2689 poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2692 dx = rotationPoint.x() -
extent.xMaximum();
2693 dy = rotationPoint.y() -
extent.yMinimum();
2695 poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2698 dx = rotationPoint.x() -
extent.xMinimum();
2699 dy = rotationPoint.y() -
extent.yMinimum();
2701 poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2704 poly << QPointF( poly.at( 0 ) );
2707void QgsLayoutItemMap::transformShift(
double &xShift,
double &yShift )
const
2710 double dxScaled = xShift * mmToMapUnits;
2711 double dyScaled = - yShift * mmToMapUnits;
2726 const QList< QgsAnnotation * > annotations =
mLayout->project()->annotationManager()->annotations();
2727 if ( annotations.isEmpty() )
2736 for ( QgsAnnotation *annotation : annotations )
2738 if ( !annotation || !annotation->isVisible() )
2742 if ( annotation->mapLayer() && !
layers.contains( annotation->mapLayer() ) )
2745 drawAnnotation( annotation, rc );
2756 QgsScopedQPainterState painterState( context.
painter() );
2759 double itemX, itemY;
2762 QPointF mapPos = layoutMapPosForItem( annotation );
2771 context.
painter()->translate( itemX, itemY );
2774 double dotsPerMM = context.
painter()->device()->logicalDpiX() / 25.4;
2775 context.
painter()->scale( 1 / dotsPerMM, 1 / dotsPerMM );
2777 annotation->
render( context );
2780QPointF QgsLayoutItemMap::layoutMapPosForItem(
const QgsAnnotation *annotation )
const
2783 return QPointF( 0, 0 );
2790 QgsCoordinateReferenceSystem annotationCrs = annotation->
mapPositionCrs();
2792 if ( annotationCrs !=
crs() )
2795 QgsCoordinateTransform t( annotationCrs,
crs(),
mLayout->project() );
2799 t.transformInPlace( mapX, mapY, z );
2801 catch (
const QgsCsException & )
2809void QgsLayoutItemMap::drawMapFrame( QPainter *p )
2820void QgsLayoutItemMap::drawMapBackground( QPainter *p )
2831bool QgsLayoutItemMap::shouldDrawPart( QgsLayoutItemMap::PartType part )
const
2833 if ( mCurrentExportPart == NotLayered )
2851 return mCurrentExportPart == Layer;
2854 return mCurrentExportPart == Grid && mGridStack->hasEnabledItems();
2856 case OverviewMapExtent:
2857 return mCurrentExportPart == OverviewMapExtent && mOverviewStack->hasEnabledItems();
2862 case SelectionBoxes:
2863 return mCurrentExportPart == SelectionBoxes && isSelected();
2874 QgsExpressionContext scopedContext;
2879 const QgsExpressionContext *evalContext = context ? context : &scopedContext;
2883 QgsRectangle newExtent =
extent();
2884 bool useDdXMin =
false;
2885 bool useDdXMax =
false;
2886 bool useDdYMin =
false;
2887 bool useDdYMax =
false;
2918 if ( newExtent != mExtent )
2924 double currentWidthHeightRatio = mExtent.width() / mExtent.height();
2925 double newWidthHeightRatio = newExtent.
width() / newExtent.
height();
2927 if ( currentWidthHeightRatio < newWidthHeightRatio )
2930 double newHeight = newExtent.
width() / currentWidthHeightRatio;
2931 double deltaHeight = newHeight - newExtent.
height();
2938 double newWidth = currentWidthHeightRatio * newExtent.
height();
2939 double deltaWidth = newWidth - newExtent.
width();
2944 mExtent = newExtent;
2954 newExtent = mExtent;
2957 if ( useDdXMax || useDdXMin || useDdYMax || useDdYMin )
2961 if ( useDdXMin && !useDdXMax )
2963 double xMax = mExtent.xMaximum() - ( mExtent.xMinimum() - minXD );
2967 else if ( !useDdXMin && useDdXMax )
2969 double xMin = mExtent.xMinimum() - ( mExtent.xMaximum() - maxXD );
2973 if ( useDdYMin && !useDdYMax )
2975 double yMax = mExtent.yMaximum() - ( mExtent.yMinimum() - minYD );
2979 else if ( !useDdYMin && useDdYMax )
2981 double yMin = mExtent.yMinimum() - ( mExtent.yMaximum() - maxYD );
2986 if ( newExtent != mExtent )
2988 mExtent = newExtent;
3005void QgsLayoutItemMap::refreshLabelMargin(
bool updateItem )
3010 mEvaluatedLabelMargin.setUnits( mLabelMargin.units() );
3018void QgsLayoutItemMap::updateAtlasFeature()
3020 if ( !
mLayout->reportContext().layer() || !
mLayout->reportContext().feature().isValid() )
3023 QgsFeatureExpressionFilterProvider *filter =
new QgsFeatureExpressionFilterProvider();
3024 filter->
setFilter(
mLayout->reportContext().layer()->id(), QgsExpression( QStringLiteral(
"@id = %1" ).arg(
mLayout->reportContext().feature().id() ) ) );
3025 mAtlasFeatureFilterProvider = std::make_unique<QgsGroupedFeatureFilterProvider>( );
3026 mAtlasFeatureFilterProvider->addProvider( filter );
3031 QgsRectangle bounds = computeAtlasRectangle();
3039 QgsRectangle newExtent = bounds;
3040 QgsRectangle originalExtent = mExtent;
3045 if ( mAtlasScalingMode ==
Fixed || mAtlasScalingMode ==
Predefined || isPointLayer )
3047 QgsScaleCalculator calc;
3050 if ( QgsProject *project =
mLayout->project() )
3054 double originalScale = calc.
calculate( originalExtent, rect().width() );
3055 double geomCenterX = ( xa1 + xa2 ) / 2.0;
3056 double geomCenterY = ( ya1 + ya2 ) / 2.0;
3057 QVector<qreal> scales;
3059 if ( !
mLayout->reportContext().predefinedScales().empty() )
3060 scales =
mLayout->reportContext().predefinedScales();
3062 scales =
mLayout->renderContext().predefinedScales();
3064 if ( mAtlasScalingMode ==
Fixed || scales.isEmpty() || ( isPointLayer && mAtlasScalingMode !=
Predefined ) )
3067 double xMin = geomCenterX - originalExtent.
width() / 2.0;
3068 double yMin = geomCenterY - originalExtent.
height() / 2.0;
3069 newExtent = QgsRectangle( xMin,
3071 xMin + originalExtent.
width(),
3072 yMin + originalExtent.
height() );
3076 double newScale = calc.
calculate( newExtent, rect().width() );
3079 newExtent.
scale( originalScale / newScale );
3085 double newWidth = originalExtent.
width();
3086 double newHeight = originalExtent.
height();
3087 for (
int i = 0; i < scales.size(); i++ )
3089 double ratio = scales[i] / originalScale;
3090 newWidth = originalExtent.
width() * ratio;
3091 newHeight = originalExtent.
height() * ratio;
3094 double xMin = geomCenterX - newWidth / 2.0;
3095 double yMin = geomCenterY - newHeight / 2.0;
3096 newExtent = QgsRectangle( xMin,
3103 const double newScale = calc.
calculate( newExtent, rect().width() );
3107 newExtent.
scale( scales[i] / newScale );
3117 else if ( mAtlasScalingMode ==
Auto )
3121 double geomRatio = bounds.
width() / bounds.
height();
3122 double mapRatio = originalExtent.
width() / originalExtent.
height();
3125 if ( geomRatio < mapRatio )
3128 double adjWidth = ( mapRatio * bounds.
height() - bounds.
width() ) / 2.0;
3133 else if ( geomRatio > mapRatio )
3136 double adjHeight = ( bounds.
width() / mapRatio - bounds.
height() ) / 2.0;
3140 newExtent = QgsRectangle( xa1, ya1, xa2, ya2 );
3142 const double evaluatedAtlasMargin =
atlasMargin();
3143 if ( evaluatedAtlasMargin > 0.0 )
3145 newExtent.
scale( 1 + evaluatedAtlasMargin );
3159 QgsGeometry g =
mLayout->reportContext().currentGeometry(
crs() );
3171 double dx = std::max( std::abs( prevCenter.
x() - bounds.
xMinimum() ),
3172 std::abs( prevCenter.
x() - bounds.
xMaximum() ) );
3173 double dy = std::max( std::abs( prevCenter.
y() - bounds.
yMinimum() ),
3174 std::abs( prevCenter.
y() - bounds.
yMaximum() ) );
3176 return QgsRectangle( center.
x() - dx, center.
y() - dy,
3177 center.
x() + dx, center.
y() + dy );
3185void QgsLayoutItemMap::createStagedRenderJob(
const QgsRectangle &extent,
const QSizeF size,
double dpi )
3188 settings.
setLayers( mOverviewStack->modifyMapLayerList( settings.
layers() ) );
3190 mStagedRendererJob = std::make_unique< QgsMapRendererStagedRenderJob >( settings,
3194 mStagedRendererJob->start();
3207 if ( mMap->layout() && mMap->layout()->project() )
3209 connect( mMap->layout()->project(), static_cast < void ( QgsProject::* )( const QList<QgsMapLayer *>& layers ) > ( &QgsProject::layersWillBeRemoved ),
3210 this, &QgsLayoutItemMapAtlasClippingSettings::layersAboutToBeRemoved );
3216 return mClipToAtlasFeature;
3221 if (
enabled == mClipToAtlasFeature )
3224 mClipToAtlasFeature =
enabled;
3230 return mFeatureClippingType;
3235 if ( mFeatureClippingType == type )
3238 mFeatureClippingType = type;
3244 return mForceLabelsInsideFeature;
3249 if ( forceInside == mForceLabelsInsideFeature )
3252 mForceLabelsInsideFeature = forceInside;
3258 return mClipItemShape;
3272 return mRestrictToLayers;
3277 if ( mRestrictToLayers ==
enabled )
3286 return _qgis_listRefToRaw( mLayersToClip );
3297 QDomElement settingsElem = document.createElement( QStringLiteral(
"atlasClippingSettings" ) );
3298 settingsElem.setAttribute( QStringLiteral(
"enabled" ), mClipToAtlasFeature ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
3299 settingsElem.setAttribute( QStringLiteral(
"forceLabelsInside" ), mForceLabelsInsideFeature ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
3300 if ( mClipItemShape )
3302 settingsElem.setAttribute( QStringLiteral(
"clipItemShape" ), QStringLiteral(
"1" ) );
3304 settingsElem.setAttribute( QStringLiteral(
"clippingType" ), QString::number(
static_cast<int>( mFeatureClippingType ) ) );
3305 settingsElem.setAttribute( QStringLiteral(
"restrictLayers" ), mRestrictToLayers ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
3308 QDomElement layerSetElem = document.createElement( QStringLiteral(
"layersToClip" ) );
3313 QDomElement layerElem = document.createElement( QStringLiteral(
"Layer" ) );
3314 QDomText layerIdText = document.createTextNode( layerRef.layerId );
3315 layerElem.appendChild( layerIdText );
3317 layerElem.setAttribute( QStringLiteral(
"name" ), layerRef.name );
3318 layerElem.setAttribute( QStringLiteral(
"source" ), layerRef.source );
3319 layerElem.setAttribute( QStringLiteral(
"provider" ), layerRef.provider );
3321 layerSetElem.appendChild( layerElem );
3323 settingsElem.appendChild( layerSetElem );
3325 element.appendChild( settingsElem );
3331 const QDomElement settingsElem = element.firstChildElement( QStringLiteral(
"atlasClippingSettings" ) );
3333 mClipToAtlasFeature = settingsElem.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"0" ) ).toInt();
3334 mForceLabelsInsideFeature = settingsElem.attribute( QStringLiteral(
"forceLabelsInside" ), QStringLiteral(
"0" ) ).toInt();
3335 mClipItemShape = settingsElem.attribute( QStringLiteral(
"clipItemShape" ), QStringLiteral(
"0" ) ).toInt();
3337 mRestrictToLayers = settingsElem.attribute( QStringLiteral(
"restrictLayers" ), QStringLiteral(
"0" ) ).toInt();
3339 mLayersToClip.clear();
3340 QDomNodeList layerSetNodeList = settingsElem.elementsByTagName( QStringLiteral(
"layersToClip" ) );
3341 if ( !layerSetNodeList.isEmpty() )
3343 QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
3344 QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( QStringLiteral(
"Layer" ) );
3345 mLayersToClip.reserve( layerIdNodeList.size() );
3346 for (
int i = 0; i < layerIdNodeList.size(); ++i )
3348 QDomElement layerElem = layerIdNodeList.at( i ).toElement();
3349 QString layerId = layerElem.text();
3350 QString layerName = layerElem.attribute( QStringLiteral(
"name" ) );
3351 QString layerSource = layerElem.attribute( QStringLiteral(
"source" ) );
3352 QString layerProvider = layerElem.attribute( QStringLiteral(
"provider" ) );
3354 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
3355 if ( mMap->layout() && mMap->layout()->project() )
3357 mLayersToClip << ref;
3364void QgsLayoutItemMapAtlasClippingSettings::layersAboutToBeRemoved(
const QList<QgsMapLayer *> &layers )
3366 if ( !mLayersToClip.isEmpty() )
3368 _qgis_removeLayers( mLayersToClip, layers );
3383 return mEnabled && mClipPathSource;
3398 if ( mClipPathSource )
3401 mClipPathSource->refresh();
3410 QgsGeometry clipGeom( mClipPathSource->clipPath() );
3411 clipGeom.
transform( mMap->layoutToMapCoordsTransform() );
3421 QgsGeometry clipGeom( mClipPathSource->clipPath() );
3422 clipGeom.
transform( mMap->sceneTransform().inverted() );
3437 if ( mClipPathSource == item )
3440 if ( mClipPathSource )
3449 mClipPathSource = item;
3451 if ( mClipPathSource )
3460 mClipPathSource->refresh();
3474 return mClipPathSource;
3479 return mFeatureClippingType;
3484 if ( mFeatureClippingType == type )
3487 mFeatureClippingType = type;
3493 return mForceLabelsInsideClipPath;
3498 if ( forceInside == mForceLabelsInsideClipPath )
3501 mForceLabelsInsideClipPath = forceInside;
3507 QDomElement settingsElem = document.createElement( QStringLiteral(
"itemClippingSettings" ) );
3508 settingsElem.setAttribute( QStringLiteral(
"enabled" ), mEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
3509 settingsElem.setAttribute( QStringLiteral(
"forceLabelsInside" ), mForceLabelsInsideClipPath ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
3510 settingsElem.setAttribute( QStringLiteral(
"clippingType" ), QString::number(
static_cast<int>( mFeatureClippingType ) ) );
3511 if ( mClipPathSource )
3512 settingsElem.setAttribute( QStringLiteral(
"clipSource" ), mClipPathSource->uuid() );
3514 settingsElem.setAttribute( QStringLiteral(
"clipSource" ), QString() );
3516 element.appendChild( settingsElem );
3522 const QDomElement settingsElem = element.firstChildElement( QStringLiteral(
"itemClippingSettings" ) );
3524 mEnabled = settingsElem.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"0" ) ).toInt();
3525 mForceLabelsInsideClipPath = settingsElem.attribute( QStringLiteral(
"forceLabelsInside" ), QStringLiteral(
"0" ) ).toInt();
3527 mClipPathUuid = settingsElem.attribute( QStringLiteral(
"clipSource" ) );
3534 if ( !mClipPathUuid.isEmpty() )
@ Default
Allow raster-based rendering in situations where it is required for correct rendering or where it wil...
@ PreferVector
Prefer vector-based rendering, when the result will still be visually near-identical to a raster-base...
@ ForceVector
Always force vector-based rendering, even when the result will be visually different to a raster-base...
QFlags< VectorRenderingSimplificationFlag > VectorRenderingSimplificationFlags
Simplification flags for vector feature rendering.
@ Millimeters
Millimeters.
@ NoSimplification
No simplification can be applied.
@ CollectUnplacedLabels
Whether unplaced labels should be collected in the labeling results (regardless of whether they are b...
@ DrawUnplacedLabels
Whether to render unplaced labels as an indicator/warning for users.
@ UsePartialCandidates
Whether to use also label candidates that are partially outside of the map view.
@ Export
Renderer used for printing or exporting to a file.
@ View
Renderer used for displaying on screen.
@ Preferred
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
@ DrawEditingInfo
Enable drawing of vertex markers for layers in editing mode.
@ UseRenderingOptimization
Enable vector simplification and other rendering optimizations.
@ RenderPartialOutput
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
@ ForceRasterMasks
Force symbol masking to be applied using a raster method. This is considerably faster when compared t...
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
@ AlwaysUseGlobalMasks
When applying clipping paths for selective masking, always use global ("entire map") paths,...
@ DrawSelection
Whether vector selections should be shown in the rendered map.
@ Antialiasing
Enable anti-aliasing for map rendering.
@ HighQualityImageTransforms
Enable high quality image transformations, which results in better appearance of scaled or rotated ra...
@ DisableTiledRasterLayerRenders
If set, then raster layers will not be drawn as separate tiles. This may improve the appearance in ex...
@ LimitCoverageLayerRenderToCurrentFeature
Limit coverage layer rendering to the current atlas feature.
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
@ AlwaysUseGlobalMasks
When applying clipping paths for selective masking, always use global ("entire map") paths,...
@ DrawSelection
Draw selection.
@ Antialiasing
Use antialiasing when drawing items.
@ RenderLabelsByMapLayer
When rendering map items to multi-layered exports, render labels belonging to different layers into s...
@ HideCoverageLayer
Hide coverage layer in outputs.
virtual QPainterPath asQPainterPath() const =0
Returns the geometry represented as a QPainterPath.
Abstract base class for annotation items which are drawn over a map.
QgsCoordinateReferenceSystem mapPositionCrs() const
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map po...
void render(QgsRenderContext &context) const
Renders the annotation to a target render context.
bool isVisible() const
Returns true if the annotation is visible and should be rendered.
QPointF relativePosition() const
Returns the relative position of the annotation, if it is not attached to a fixed map position.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsCoordinateReferenceSystemRegistry * coordinateReferenceSystemRegistry()
Returns the application's coordinate reference system (CRS) registry, which handles known CRS definit...
void userCrsChanged(const QString &id)
Emitted whenever an existing user CRS definition is changed.
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString toProj() const
Returns a Proj string representation of this CRS.
QString ellipsoidAcronym() const
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
QString projectionAcronym() const
Returns the projection acronym for the projection used by the CRS.
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
QgsProjOperation operation() const
Returns information about the PROJ operation associated with the coordinate reference system,...
Qgis::DistanceUnit mapUnits
QgsRange which stores a range of double values.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addFunction(const QString &name, QgsScopedExpressionFunction *function)
Adds a function to the scope.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
void setVariable(const QString &name, const QVariant &value, bool isStatic=false)
Convenience method for setting a variable in the context scope by name name and value.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setFilter(const QString &layerId, const QgsExpression &expression)
Set a filter for the given layer.
A geometry is the spatial representation of a feature.
QPolygonF asQPolygonF() const
Returns contents of the geometry as a QPolygonF.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
QgsGeometry intersection(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points shared by this geometry and other.
QgsGeometry buffer(double distance, int segments) const
Returns a buffer region around this geometry having the given width and with a specified number of se...
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Qgis::GeometryOperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
A map layer which consists of a set of child layers, where all component layers are rendered as a sin...
QList< QgsMapLayer * > childLayers() const
Returns the child layers contained by the group.
void setChildLayers(const QList< QgsMapLayer * > &layers)
Sets the child layers contained by the group.
QgsGroupedFeatureFilterProvider & addProvider(const QgsFeatureFilterProvider *provider)
Add another filter provider to the group.
A representation of the interval between two datetime values.
Stores global configuration for labeling engine.
void setFlag(Qgis::LabelingFlag f, bool enabled=true)
Sets whether a particual flag is enabled.
Stores computed placement from labeling engine.
void layerOrderChanged()
Emitted when the layer order has changed.
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.
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.
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
@ StackAboveMapLabels
Render above all map layers and labels.
StackingPosition stackingPosition() const
Returns the item's stacking position, which specifies where the in the map's stack the item should be...
bool enabled() const
Returns whether the item will be drawn.
Layout graphical items for displaying a map.
void setFollowVisibilityPreset(bool follow)
Sets whether the map should follow a map theme.
bool nextExportPart() override
Moves to the next export part for a multi-layered export item, during a multi-layered export.
void removeRenderedFeatureHandler(QgsRenderedFeatureHandlerInterface *handler)
Removes a previously added rendered feature handler.
void extentChanged()
Emitted when the map's extent changes.
QPointF mapToItemCoords(QPointF mapCoords) const
Transforms map coordinates to item coordinates (considering rotation and move offset).
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
~QgsLayoutItemMap() override
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.
void setFollowVisibilityPresetName(const QString &name)
Sets preset name for map rendering.
QTransform layoutToMapCoordsTransform() const
Creates a transform from layout coordinates to map coordinates.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
QgsMapSettings mapSettings(const QgsRectangle &extent, QSizeF size, double dpi, bool includeLayerSettings) const
Returns map settings that will be used for drawing of the map.
bool isLabelBlockingItem(QgsLayoutItem *item) const
Returns true if the specified item is a "label blocking item".
void storeCurrentLayerStyles()
Stores the current project layer styles into style overrides.
void setAtlasDriven(bool enabled)
Sets whether the map extent will follow the current atlas feature.
QgsLayoutMeasurement labelMargin() const
Returns the margin from the map edges in which no labels may be placed.
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.
bool requiresRasterization() const override
Returns true if the item is drawn in such a way that forces the whole layout to be rasterized when ex...
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...
void moveContent(double dx, double dy) override
Moves the content of the item, by a specified dx and dy in layout units.
void setZRangeEnabled(bool enabled)
Sets whether the z range is enabled (i.e.
QgsLayoutItemMapGrid * grid()
Returns the map item's first grid.
void mapRotationChanged(double newRotation)
Emitted when the map's rotation changes.
int type() const override
QList< QgsMapLayer * > layersToRender(const QgsExpressionContext *context=nullptr, bool includeInvalidLayers=false) const
Returns a list of the layers which will be rendered within this map item, considering any locked laye...
void previewRefreshed()
Emitted whenever the item's map preview has been refreshed.
friend class QgsLayoutItemMapOverview
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.
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation.
QgsRectangle requestedExtent() const
Calculates the extent to request and the yShift of the top-left point in case of rotation.
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 zoomContent(double factor, QPointF point) override
Zooms content of item.
void crsChanged()
Emitted when the map's coordinate reference system is changed.
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the stored layers set.
QPolygonF transformedMapPolygon() const
Returns extent that considers rotation and shift with mOffsetX / mOffsetY.
static QgsLayoutItemMap * create(QgsLayout *layout)
Returns a new map item for the specified layout.
QRectF boundingRect() const override
QString displayName() const override
Gets item display name.
bool atlasDriven() const
Returns whether the map extent is set to follow the current atlas feature.
void setZRange(const QgsDoubleRange &range)
Sets the map's z range, which is used to filter the map's content to only display features within the...
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Sets the stored overrides of styles for layers.
void stopLayeredExport() override
Stops a multi-layer export operation.
void addRenderedFeatureHandler(QgsRenderedFeatureHandlerInterface *handler)
Adds a rendered feature handler to use while rendering the map.
double estimatedFrameBleed() const override
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
QPainterPath framePath() const override
Returns the path to use when drawing the item's frame or background.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void startLayeredExport() override
Starts a multi-layer export operation.
bool containsWmsLayer() const
Returns true if the map contains a WMS layer.
void setScale(double scale, bool forceUpdate=true)
Sets new map scale and changes only the map extent.
double mapRotation(QgsLayoutObject::PropertyValueType valueType=QgsLayoutObject::EvaluatedValue) const
Returns the rotation used for drawing the map within the layout item, in degrees clockwise.
double mapUnitsToLayoutUnits() const
Returns the conversion factor from map units to layout units.
QgsLayoutItemMap::MapItemFlags mapFlags() const
Returns the map item's flags, which control how the map content is drawn.
bool zRangeEnabled() const
Returns whether the z range is enabled (i.e.
void setLabelMargin(const QgsLayoutMeasurement &margin)
Sets the margin from the map edges in which no labels may be placed.
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.
@ ShowPartialLabels
Whether to draw labels which are partially outside of the map view.
@ ShowUnplacedLabels
Whether to render unplaced labels in the map view.
bool drawAnnotations() const
Returns whether annotations are drawn within the map.
QgsDoubleRange zRange() const
Returns the map's z range, which is used to filter the map's content to only display features within ...
void removeLabelBlockingItem(QgsLayoutItem *item)
Removes the specified layout item from the map's "label blocking items".
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the map's preset crs (coordinate reference system).
void invalidateCache() override
QgsRectangle extent() const
Returns the current map extent.
QgsLayoutItemMapOverview * overview()
Returns the map item's first overview.
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
void setFrameStrokeWidth(QgsLayoutMeasurement width) override
Sets the frame stroke width.
bool containsAdvancedEffects() const override
Returns true if the item contains contents with blend modes or transparency effects which can only be...
friend class QgsLayoutItemMapGrid
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 setMoveContentPreviewOffset(double dx, double dy) override
Sets temporary offset for the item, by a specified dx and dy in layout units.
void setMapRotation(double rotation)
Sets the rotation for the map - this does not affect the layout item shape, only the way the map is d...
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.
double atlasMargin(QgsLayoutObject::PropertyValueType valueType=QgsLayoutObject::EvaluatedValue)
Returns the margin size (percentage) used when the map is in atlas mode.
void addLabelBlockingItem(QgsLayoutItem *item)
Sets the specified layout item as a "label blocking item" for this map.
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.
QgsLabelingResults * previewLabelingResults() const
Returns the labeling results of the most recent preview map render.
Contains settings and helpers relating to a render of a QgsLayoutItem.
Base class for graphical items within a QgsLayout.
virtual void drawFrame(QgsRenderContext &context)
Draws the frame around the item.
virtual QPainterPath framePath() const
Returns the path to use when drawing the item's frame or background.
QColor backgroundColor(bool useDataDefined=true) const
Returns the background color for this item.
void drawRefreshingOverlay(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle)
Draws a "refreshing" overlay icon on the item.
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
virtual void setFrameStrokeWidth(QgsLayoutMeasurement width)
Sets the frame stroke width.
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
void rotationChanged(double newRotation)
Emitted on item rotation change.
friend class QgsLayoutItemMap
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
virtual void drawBackground(QgsRenderContext &context)
Draws the background for the item.
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
@ FlagOverridesPaint
Item overrides the default layout item painting method.
@ FlagDisableSceneCaching
Item should not have QGraphicsItem caching enabled.
virtual bool containsAdvancedEffects() const
Returns true if the item contains contents with blend modes or transparency effects which can only be...
void sizePositionChanged()
Emitted when the item's size or position changes.
virtual QString uuid() const
Returns the item identification string.
QString id() const
Returns the item's ID name.
bool frameEnabled() const
Returns true if the item includes a frame.
ExportLayerBehavior
Behavior of item when exporting to layered outputs.
@ ItemContainsSubLayers
Item contains multiple sublayers which must be individually exported.
void clipPathChanged()
Emitted when the item's clipping path has changed.
bool hasBackground() const
Returns true if the item has a background.
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
void attemptSetSceneRect(const QRectF &rect, bool includesFrame=false)
Attempts to update the item's position and size to match the passed rect in layout coordinates.
virtual double estimatedFrameBleed() const
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
void backgroundTaskCountChanged(int count)
Emitted whenever the number of background tasks an item is executing changes.
Provides a method of storing measurements for use in QGIS layouts using a variety of different measur...
static QgsLayoutMeasurement decodeMeasurement(const QString &string)
Decodes a measurement from a string.
QgsPropertyCollection mDataDefinedProperties
const QgsLayout * layout() const
Returns the layout the object is attached to.
void changed()
Emitted when the object's properties change.
QPointer< QgsLayout > mLayout
DataDefinedProperty
Data defined properties for different item types.
@ MapYMin
Map extent y minimum.
@ MapZRangeUpper
Map frame Z-range lower value.
@ StartDateTime
Temporal range's start DateTime.
@ MapLayers
Map layer set.
@ MapZRangeLower
Map frame Z-range lower value.
@ MapRotation
Map rotation.
@ MapXMax
Map extent x maximum.
@ MapStylePreset
Layer and style map theme.
@ MapYMax
Map extent y maximum.
@ MapAtlasMargin
Map atlas margin.
@ EndDateTime
Temporal range's end DateTime.
@ MapXMin
Map extent x minimum.
@ MapLabelMargin
Map label margin.
@ 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.
void predefinedScalesChanged()
Emitted when the list of predefined scales changes.
static QgsRenderContext createRenderContextForMap(QgsLayoutItemMap *map, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout map and painter destination.
static void rotate(double angle, double &x, double &y)
Rotates a point / vector around the origin.
static Q_DECL_DEPRECATED double scaleFactorFromItemStyle(const QStyleOptionGraphicsItem *style)
Extracts the scale factor from an item style.
QgsLayoutItem * itemByUuid(const QString &uuid, bool includeTemplateUuids=false) const
Returns the layout item with matching uuid unique identifier, or nullptr if a matching item could not...
void refreshed()
Emitted when the layout has been refreshed and items should also be refreshed and updated.
A map clipping region (in map coordinates and CRS).
void setRestrictToLayers(bool enabled)
Sets whether clipping should be restricted to a subset of layers.
FeatureClippingType
Feature clipping behavior, which controls how features from vector layers will be clipped.
void setFeatureClip(FeatureClippingType type)
Sets the feature clipping type.
void setRestrictedLayers(const QList< QgsMapLayer * > &layers)
Sets a list of layers to restrict the clipping region effects to.
Stores style information (renderer, opacity, labeling, diagrams etc.) applicable to a map layer.
void readXml(const QDomElement &styleElement)
Read style configuration (for project file reading).
void readFromLayer(QgsMapLayer *layer)
Store layer's active style information in the instance.
void writeXml(QDomElement &styleElement) const
Write style configuration (for project file writing).
QString xmlData() const
Returns XML content of the style.
Base class for all map layer types.
void cancelWithoutBlocking() override
Triggers cancellation of the rendering job without blocking.
void finished()
emitted when asynchronous rendering is finished (or canceled).
@ RenderLabelsByMapLayer
Labels should be rendered in individual stages by map layer. This allows separation of labels belongi...
@ Finished
Rendering is finished.
@ Symbology
Rendering layer symbology.
@ Labels
Rendering labels.
static QStringList containsAdvancedEffects(const QgsMapSettings &mapSettings, EffectsCheckFlags flags=QgsMapSettingsUtils::EffectsCheckFlags())
Checks whether any of the layers attached to a map settings object contain advanced effects.
Contains configuration for rendering maps.
void setElevationShadingRenderer(const QgsElevationShadingRenderer &renderer)
Sets the shading renderer used to render shading on the entire map.
void addClippingRegion(const QgsMapClippingRegion ®ion)
Adds a new clipping region to the map settings.
QList< QgsMapLayer * > layers(bool expandGroupLayers=false) const
Returns the list of layers which will be rendered in the map.
void setSelectionColor(const QColor &color)
Sets the color that is used for drawing of selected vector features.
void setSimplifyMethod(const QgsVectorSimplifyMethod &method)
Sets the simplification setting to use when rendering vector layers.
QPolygonF visiblePolygon() const
Returns the visible area as a polygon (may be rotated).
void addRenderedFeatureHandler(QgsRenderedFeatureHandlerInterface *handler)
Adds a rendered feature handler to use while rendering the map settings.
void setTextRenderFormat(Qgis::TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of layers to render in the map.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
void setScaleMethod(Qgis::ScaleCalculationMethod method)
Sets the method to use for scale calculations for the map.
void setDpiTarget(double dpi)
Sets the target dpi (dots per inch) to be taken into consideration when rendering.
void setDevicePixelRatio(float dpr)
Sets the device pixel ratio.
void setZRange(const QgsDoubleRange &range)
Sets the range of z-values which will be visible in the map.
void setOutputDpi(double dpi)
Sets the dpi (dots per inch) used for conversion between real world units (e.g.
void setRendererUsage(Qgis::RendererUsage rendererUsage)
Sets the rendering usage.
void setRasterizedRenderingPolicy(Qgis::RasterizedRenderingPolicy policy)
Sets the policy controlling when rasterisation of content during renders is permitted.
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
void setMaskSettings(const QgsMaskRenderSettings &settings)
Sets the mask render settings, which control how masks are drawn and behave during the map render.
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Sets the map of map layer style overrides (key: layer ID, value: style name) where a different style ...
void setExtent(const QgsRectangle &rect, bool magnified=true)
Sets the coordinates of the rectangle which should be rendered.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets the global configuration of the labeling engine.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
void setLabelBoundaryGeometry(const QgsGeometry &boundary)
Sets the label boundary geometry, which restricts where in the rendered map labels are permitted to b...
void setLabelBlockingRegions(const QList< QgsLabelBlockingRegion > ®ions)
Sets a list of regions to avoid placing labels within.
void setOutputSize(QSize size)
Sets the size of the resulting map image, in pixels.
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
void setFlag(Qgis::MapSettingsFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected).
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Sets the destination crs (coordinate reference system) for the map render.
void mapThemeRenamed(const QString &name, const QString &newName)
Emitted when a map theme within the collection is renamed.
void mapThemeChanged(const QString &theme)
Emitted when a map theme changes definition.
QString description() const
Description.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the registry.
void crsChanged()
Emitted when the crs() of the project has changed.
QgsMapThemeCollection * mapThemeCollection
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.
Qgis::ScaleCalculationMethod scaleMethod
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
void setYMinimum(double y)
Set the minimum y value.
void setXMinimum(double x)
Set the minimum x value.
void setYMaximum(double y)
Set the maximum y value.
void setXMaximum(double x)
Set the maximum x value.
static QgsRectangle fromCenterAndSize(const QgsPointXY ¢er, double width, double height)
Creates a new rectangle, given the specified center point and width and height.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
QgsExpressionContext & expressionContext()
Gets the expression context.
void setRasterizedRenderingPolicy(Qgis::RasterizedRenderingPolicy policy)
Sets the policy controlling when rasterisation of content during renders is permitted.
Qgis::RasterizedRenderingPolicy rasterizedRenderingPolicy() const
Returns the policy controlling when rasterisation of content during renders is permitted.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
An interface for classes which provide custom handlers for features rendered as part of a map render ...
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
double calculate(const QgsRectangle &mapExtent, double canvasWidth) const
Calculate the scale denominator.
void setDpi(double dpi)
Sets the dpi (dots per inch) for the output resolution, to be used in scale calculations.
void setMapUnits(Qgis::DistanceUnit mapUnits)
Set the map units.
void setMethod(Qgis::ScaleCalculationMethod method)
Sets the method to use for map scale calculations.
Scoped object for saving and restoring a QPainter object's state.
A boolean settings entry.
static QgsSettingsTreeNode * sTreeLayout
An interface for classes which can visit style entity (e.g.
@ LayoutItem
Individual item in a print layout.
virtual bool visitExit(const QgsStyleEntityVisitorInterface::Node &node)
Called when the visitor stops visiting a node.
virtual bool visitEnter(const QgsStyleEntityVisitorInterface::Node &node)
Called when the visitor starts visiting a node.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
void setIsTemporal(bool enabled)
Sets whether the temporal range is enabled (i.e.
void setTemporalRange(const QgsDateTimeRange &range)
Sets the temporal range for the object.
T begin() const
Returns the beginning of the range.
T end() const
Returns the upper bound of the range.
static Q_INVOKABLE QString toString(Qgis::DistanceUnit unit)
Returns a translated string representing a distance unit.
static double scaleToZoom(double mapScale, double z0Scale=559082264.0287178)
Finds zoom level given map scale denominator.
static int scaleToZoomLevel(double mapScale, int sourceMinZoom, int sourceMaxZoom, double z0Scale=559082264.0287178)
Finds the best fitting zoom level given a map scale denominator and allowed zoom level range.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
#define Q_NOWARN_DEPRECATED_POP
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
_LayerRef< QgsMapLayer > QgsMapLayerRef
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Single variable definition for use within a QgsExpressionContextScope.
Contains details of a particular export layer relating to a layout item.
QPainter::CompositionMode compositionMode
Associated composition mode if this layer is associated with a map layer.
QString mapLayerId
Associated map layer ID, or an empty string if this export layer is not associated with a map layer.
double opacity
Associated opacity, if this layer is associated with a map layer.
QString name
User-friendly name for the export layer.
QString mapTheme
Associated map theme, or an empty string if this export layer does not need to be associated with a m...
Contains information relating to a node (i.e.
TYPE * resolveWeakly(const QgsProject *project, MatchType matchType=MatchType::All)
Resolves the map layer by attempting to find a matching layer in a project using a weak match.
QString source
Weak reference to layer public source.
QString name
Weak reference to layer name.
QString provider
Weak reference to layer provider.
TYPE * resolve(const QgsProject *project)
Resolves the map layer by attempting to find a layer with matching ID within a project.
QString layerId
Original layer ID.