49#include <QApplication>
53#include <QStyleOptionGraphicsItem>
56#include "moc_qgslayoutitemmap.cpp"
58using namespace Qt::StringLiterals;
67 mBackgroundUpdateTimer =
new QTimer(
this );
68 mBackgroundUpdateTimer->setSingleShot(
true );
69 connect( mBackgroundUpdateTimer, &QTimer::timeout,
this, &QgsLayoutItemMap::recreateCachedImageInBackground );
73 setCacheMode( QGraphicsItem::NoCache );
80 mGridStack = std::make_unique< QgsLayoutItemMapGridStack >(
this );
81 mOverviewStack = std::make_unique< QgsLayoutItemMapOverviewStack >(
this );
96 crs.updateDefinition();
114 mPainterJob->cancel();
139 QList<QgsLayoutItemMap *> mapsList;
140 mLayout->layoutItems( mapsList );
149 if ( map->mMapId == mMapId )
152 maxId = std::max( maxId, map->mMapId );
157 mLayout->itemsModel()->updateItemDisplayName(
this );
169 return tr(
"Map %1" ).arg( mMapId );
181 mCachedLayerStyleOverridesPresetName.clear();
185 updateAtlasFeature();
190 if ( rect().isEmpty() || !
mLayout )
195 calculator.
setDpi( 25.4 );
198 calculator.
setMethod( project->scaleMethod() );
206 double currentScaleDenominator =
scale();
213 double scaleRatio = scaleDenominator / currentScaleDenominator;
214 mExtent.scale( scaleRatio );
216 if ( mAtlasDriven && mAtlasScalingMode ==
Fixed )
223 calculator.
setDpi( 25.4 );
229 const double newScale = calculator.
calculate( mExtent, rect().width() );
232 scaleRatio = scaleDenominator / newScale;
233 mExtent.scale( scaleRatio );
258 if ( mExtent.isFinite() && !mExtent.isEmpty() )
260 const QRectF currentRect = rect();
261 const double newHeight = mExtent.width() == 0 ? 0
262 : currentRect.width() * mExtent.height() / mExtent.width();
274 double currentWidthHeightRatio = 1.0;
275 if ( !currentExtent.
isEmpty() )
276 currentWidthHeightRatio = currentExtent.
width() / currentExtent.
height();
278 currentWidthHeightRatio = rect().width() / rect().height();
280 if ( currentWidthHeightRatio != 0 && ! std::isnan( currentWidthHeightRatio ) && !newExtent.
isEmpty() )
282 double newWidthHeightRatio = newExtent.
width() / newExtent.
height();
284 if ( currentWidthHeightRatio < newWidthHeightRatio )
287 double newHeight = newExtent.
width() / currentWidthHeightRatio;
288 double deltaHeight = newHeight - newExtent.
height();
295 double newWidth = currentWidthHeightRatio * newExtent.
height();
296 double deltaWidth = newWidth - newExtent.
width();
302 if ( mExtent == newExtent )
321QPolygonF QgsLayoutItemMap::calculateVisibleExtentPolygon(
bool includeClipping )
const
324 mapPolygon( mExtent, poly );
326 if ( includeClipping )
333 poly = poly.intersected( geom.asQPolygonF() );
337 if ( mItemClippingSettings->isActive() )
339 const QgsGeometry geom = mItemClippingSettings->clippedMapExtent();
352 return calculateVisibleExtentPolygon(
true );
357 if ( mCrs.isValid() )
360 return mLayout->project()->crs();
375 return _qgis_listRefToRaw( mLayers );
380 mGroupLayers.clear();
382 QList<QgsMapLayer *> layersCopy {
layers };
387 for (
auto it = layersCopy.begin(); it != layersCopy.end(); ++it )
389 if (
const QgsGroupLayer *groupLayer = qobject_cast<QgsGroupLayer *>( *it ) )
391 auto existingIt = mGroupLayers.find( groupLayer->id() );
392 if ( existingIt != mGroupLayers.end( ) )
394 *it = ( *existingIt ).second.get();
398 std::unique_ptr<QgsGroupLayer> groupLayerClone { groupLayer->clone() };
399 mGroupLayers[ groupLayer->id() ] = std::move( groupLayerClone );
400 *it = mGroupLayers[ groupLayer->id() ].get();
404 mLayers = _qgis_listRawToRef( layersCopy );
409 if ( overrides == mLayerStyleOverrides )
412 mLayerStyleOverrides = overrides;
419 mLayerStyleOverrides.clear();
426 mLayerStyleOverrides.insert( layer->id(), style.
xmlData() );
433 if ( mFollowVisibilityPreset == follow )
436 mFollowVisibilityPreset = follow;
438 if ( !mFollowVisibilityPresetName.isEmpty() )
439 emit
themeChanged( mFollowVisibilityPreset ? mFollowVisibilityPresetName : QString() );
444 if ( name == mFollowVisibilityPresetName )
447 mFollowVisibilityPresetName = name;
448 if ( mFollowVisibilityPreset )
454 mLastRenderedImageOffsetX -= dx;
455 mLastRenderedImageOffsetY -= dy;
458 transformShift( dx, dy );
459 mExtent.setXMinimum( mExtent.xMinimum() + dx );
460 mExtent.setXMaximum( mExtent.xMaximum() + dx );
461 mExtent.setYMinimum( mExtent.yMinimum() + dy );
462 mExtent.setYMaximum( mExtent.yMaximum() + dy );
481 double mapX = mExtent.xMinimum() + ( point.x() / rect().width() ) * ( mExtent.xMaximum() - mExtent.xMinimum() );
482 double mapY = mExtent.yMinimum() + ( 1 - ( point.y() / rect().height() ) ) * ( mExtent.yMaximum() - mExtent.yMinimum() );
485 double centerX = ( mExtent.xMaximum() + mExtent.xMinimum() ) / 2;
486 double centerY = ( mExtent.yMaximum() + mExtent.yMinimum() ) / 2;
488 centerX = mapX + ( centerX - mapX ) * ( 1.0 / factor );
489 centerY = mapY + ( centerY - mapY ) * ( 1.0 / factor );
491 double newIntervalX, newIntervalY;
495 newIntervalX = ( mExtent.xMaximum() - mExtent.xMinimum() ) / factor;
496 newIntervalY = ( mExtent.yMaximum() - mExtent.yMinimum() ) / factor;
503 mExtent.setXMaximum( centerX + newIntervalX / 2 );
504 mExtent.setXMinimum( centerX - newIntervalX / 2 );
505 mExtent.setYMaximum( centerY + newIntervalY / 2 );
506 mExtent.setYMinimum( centerY - newIntervalY / 2 );
508 if ( mAtlasDriven && mAtlasScalingMode ==
Fixed )
515 calculator.
setDpi( 25.4 );
520 const double newScale = calculator.
calculate( mExtent, rect().width() );
523 const double scaleRatio =
scale() / newScale ;
524 mExtent.scale( scaleRatio );
541 if ( layer->dataProvider() && layer->providerType() ==
"wms"_L1 )
551 if (
blendMode() != QPainter::CompositionMode_SourceOver )
570 auto containsAdvancedEffectsIgnoreItemOpacity = [
this]()->
bool
580 if ( mOverviewStack->containsAdvancedEffects() )
588 if ( mGridStack->containsAdvancedEffects() )
601 if ( !containsAdvancedEffectsIgnoreItemOpacity() )
622 if ( mOverviewStack->containsAdvancedEffects() )
630 if ( mGridStack->containsAdvancedEffects() )
645 mMapRotation = rotation;
646 mEvaluatedMapRotation = mMapRotation;
659 mAtlasDriven = enabled;
676 double margin = mAtlasMargin;
684 margin = ddMargin / 100;
696 if ( mGridStack->size() < 1 )
699 mGridStack->addGrid(
grid );
701 return mGridStack->grid( 0 );
706 if ( mOverviewStack->size() < 1 )
709 mOverviewStack->addOverview(
overview );
711 return mOverviewStack->overview( 0 );
721 for (
int i = 0; i < mGridStack->size(); ++i )
724 if (
grid->mEvaluatedEnabled )
727 frameBleed = std::max( frameBleed,
grid->mEvaluatedGridFrameWidth +
grid->mEvaluatedGridFrameMargin +
grid->mEvaluatedGridFrameLineThickness / 2.0 );
743 mapElem.setAttribute( u
"keepLayerSet"_s, u
"true"_s );
747 mapElem.setAttribute( u
"keepLayerSet"_s, u
"false"_s );
750 if ( mDrawAnnotations )
752 mapElem.setAttribute( u
"drawCanvasItems"_s, u
"true"_s );
756 mapElem.setAttribute( u
"drawCanvasItems"_s, u
"false"_s );
760 QDomElement extentElem = doc.createElement( u
"Extent"_s );
765 mapElem.appendChild( extentElem );
767 if ( mCrs.isValid() )
769 QDomElement crsElem = doc.createElement( u
"crs"_s );
770 mCrs.writeXml( crsElem, doc );
771 mapElem.appendChild( crsElem );
775 mapElem.setAttribute( u
"followPreset"_s, mFollowVisibilityPreset ? u
"true"_s : u
"false"_s );
776 mapElem.setAttribute( u
"followPresetName"_s, mFollowVisibilityPresetName );
779 mapElem.setAttribute( u
"mapRotation"_s, QString::number( mMapRotation ) );
782 QDomElement layerSetElem = doc.createElement( u
"LayerSet"_s );
787 QDomElement layerElem = doc.createElement( u
"Layer"_s );
789 const auto it = std::find_if( mGroupLayers.cbegin(), mGroupLayers.cend(), [ &layerRef ](
const std::pair<
const QString, std::unique_ptr<QgsGroupLayer>> &groupLayer ) ->
bool
791 return groupLayer.second.get() == layerRef.get();
794 if ( it != mGroupLayers.end() )
800 layerId = layerRef.layerId;
803 QDomText layerIdText = doc.createTextNode( layerId );
804 layerElem.appendChild( layerIdText );
806 layerElem.setAttribute( u
"name"_s, layerRef.name );
807 layerElem.setAttribute( u
"source"_s, layerRef.source );
808 layerElem.setAttribute( u
"provider"_s, layerRef.provider );
810 if ( it != mGroupLayers.end() )
812 const auto childLayers { it->second->childLayers() };
813 QDomElement childLayersElement = doc.createElement( u
"childLayers"_s );
814 for (
const QgsMapLayer *childLayer : std::as_const( childLayers ) )
816 QDomElement childElement = doc.createElement( u
"child"_s );
817 childElement.setAttribute( u
"layerid"_s, childLayer->id() );
818 childLayersElement.appendChild( childElement );
820 layerElem.appendChild( childLayersElement );
822 layerSetElem.appendChild( layerElem );
824 mapElem.appendChild( layerSetElem );
827 if ( mKeepLayerStyles )
829 QDomElement stylesElem = doc.createElement( u
"LayerStyles"_s );
830 for (
auto styleIt = mLayerStyleOverrides.constBegin(); styleIt != mLayerStyleOverrides.constEnd(); ++styleIt )
832 QDomElement styleElem = doc.createElement( u
"LayerStyle"_s );
837 styleElem.setAttribute( u
"layerid"_s, ref.
layerId );
838 styleElem.setAttribute( u
"name"_s, ref.
name );
839 styleElem.setAttribute( u
"source"_s, ref.
source );
840 styleElem.setAttribute( u
"provider"_s, ref.
provider );
844 stylesElem.appendChild( styleElem );
846 mapElem.appendChild( stylesElem );
850 mGridStack->writeXml( mapElem, doc, context );
853 mOverviewStack->writeXml( mapElem, doc, context );
856 QDomElement atlasElem = doc.createElement( u
"AtlasMap"_s );
857 atlasElem.setAttribute( u
"atlasDriven"_s, mAtlasDriven );
858 atlasElem.setAttribute( u
"scalingMode"_s, mAtlasScalingMode );
860 mapElem.appendChild( atlasElem );
862 mapElem.setAttribute( u
"labelMargin"_s, mLabelMargin.encodeMeasurement() );
863 mapElem.setAttribute( u
"mapFlags"_s,
static_cast< int>( mMapFlags ) );
865 QDomElement labelBlockingItemsElem = doc.createElement( u
"labelBlockingItems"_s );
866 for (
const auto &item : std::as_const( mBlockingLabelItems ) )
871 QDomElement blockingItemElem = doc.createElement( u
"item"_s );
872 blockingItemElem.setAttribute( u
"uuid"_s, item->uuid() );
873 labelBlockingItemsElem.appendChild( blockingItemElem );
875 mapElem.appendChild( labelBlockingItemsElem );
878 mapElem.setAttribute( u
"isTemporal"_s,
isTemporal() ? 1 : 0 );
881 mapElem.setAttribute( u
"temporalRangeBegin"_s,
temporalRange().begin().toString( Qt::ISODate ) );
882 mapElem.setAttribute( u
"temporalRangeEnd"_s,
temporalRange().end().toString( Qt::ISODate ) );
885 mapElem.setAttribute( u
"enableZRange"_s, mZRangeEnabled ? 1 : 0 );
886 if ( mZRange.lower() != std::numeric_limits< double >::lowest() )
888 if ( mZRange.upper() != std::numeric_limits< double >::max() )
891 mAtlasClippingSettings->writeXml( mapElem, doc, context );
892 mItemClippingSettings->writeXml( mapElem, doc, context );
899 mUpdatesEnabled =
false;
902 QDomNodeList extentNodeList = itemElem.elementsByTagName( u
"Extent"_s );
903 if ( !extentNodeList.isEmpty() )
905 QDomElement extentElem = extentNodeList.at( 0 ).toElement();
906 double xmin, xmax, ymin, ymax;
907 xmin = extentElem.attribute( u
"xmin"_s ).toDouble();
908 xmax = extentElem.attribute( u
"xmax"_s ).toDouble();
909 ymin = extentElem.attribute( u
"ymin"_s ).toDouble();
910 ymax = extentElem.attribute( u
"ymax"_s ).toDouble();
914 QDomNodeList crsNodeList = itemElem.elementsByTagName( u
"crs"_s );
916 if ( !crsNodeList.isEmpty() )
918 QDomElement crsElem = crsNodeList.at( 0 ).toElement();
919 crs.readXml( crsElem );
924 mMapRotation = itemElem.attribute( u
"mapRotation"_s, u
"0"_s ).toDouble();
925 mEvaluatedMapRotation = mMapRotation;
928 mFollowVisibilityPreset = itemElem.attribute( u
"followPreset"_s ).compare(
"true"_L1 ) == 0;
929 mFollowVisibilityPresetName = itemElem.attribute( u
"followPresetName"_s );
932 QString keepLayerSetFlag = itemElem.attribute( u
"keepLayerSet"_s );
933 if ( keepLayerSetFlag.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 )
935 mKeepLayerSet =
true;
939 mKeepLayerSet =
false;
942 QString drawCanvasItemsFlag = itemElem.attribute( u
"drawCanvasItems"_s, u
"true"_s );
943 if ( drawCanvasItemsFlag.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 )
945 mDrawAnnotations =
true;
949 mDrawAnnotations =
false;
952 mLayerStyleOverrides.clear();
954 QList<QgsMapLayerRef> layerSet;
955 QDomNodeList layerSetNodeList = itemElem.elementsByTagName( u
"LayerSet"_s );
956 if ( !layerSetNodeList.isEmpty() )
958 QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
959 QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( u
"Layer"_s );
960 layerSet.reserve( layerIdNodeList.size() );
961 for (
int i = 0; i < layerIdNodeList.size(); ++i )
963 QDomElement layerElem = layerIdNodeList.at( i ).toElement();
964 QString layerId = layerElem.text();
965 QString layerName = layerElem.attribute( u
"name"_s );
966 QString layerSource = layerElem.attribute( u
"source"_s );
967 QString layerProvider = layerElem.attribute( u
"provider"_s );
969 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
977 setLayers( _qgis_listRefToRaw( layerSet ) );
980 if ( !layerSetNodeList.isEmpty() )
982 QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
983 QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( u
"Layer"_s );
984 for (
int i = 0; i < layerIdNodeList.size(); ++i )
986 QDomElement layerElem = layerIdNodeList.at( i ).toElement();
987 const QString layerId = layerElem.text();
988 const auto it = mGroupLayers.find( layerId );
989 if ( it != mGroupLayers.cend() )
991 QList<QgsMapLayerRef> childSet;
992 const QDomNodeList childLayersElements = layerElem.elementsByTagName( u
"childLayers"_s );
993 const QDomNodeList children = childLayersElements.at( 0 ).childNodes();
994 for (
int i = 0; i < children.size(); ++i )
996 const QDomElement childElement = children.at( i ).toElement();
997 const QString
id = childElement.attribute( u
"layerid"_s );
1001 childSet.push_back( layerRef );
1004 it->second->setChildLayers( _qgis_listRefToRaw( childSet ) );
1011 QDomNodeList layerStylesNodeList = itemElem.elementsByTagName( u
"LayerStyles"_s );
1012 mKeepLayerStyles = !layerStylesNodeList.isEmpty();
1013 if ( mKeepLayerStyles )
1015 QDomElement layerStylesElem = layerStylesNodeList.at( 0 ).toElement();
1016 QDomNodeList layerStyleNodeList = layerStylesElem.elementsByTagName( u
"LayerStyle"_s );
1017 for (
int i = 0; i < layerStyleNodeList.size(); ++i )
1019 const QDomElement &layerStyleElement = layerStyleNodeList.at( i ).toElement();
1020 QString layerId = layerStyleElement.attribute( u
"layerid"_s );
1021 QString layerName = layerStyleElement.attribute( u
"name"_s );
1022 QString layerSource = layerStyleElement.attribute( u
"source"_s );
1023 QString layerProvider = layerStyleElement.attribute( u
"provider"_s );
1024 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
1028 style.
readXml( layerStyleElement );
1034 mNumCachedLayers = 0;
1035 mCacheInvalidated =
true;
1038 mOverviewStack->readXml( itemElem, doc, context );
1041 mGridStack->readXml( itemElem, doc, context );
1044 QDomNodeList atlasNodeList = itemElem.elementsByTagName( u
"AtlasMap"_s );
1045 if ( !atlasNodeList.isEmpty() )
1047 QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1048 mAtlasDriven = ( atlasElem.attribute( u
"atlasDriven"_s, u
"0"_s ) !=
"0"_L1 );
1049 if ( atlasElem.hasAttribute( u
"fixedScale"_s ) )
1051 mAtlasScalingMode = ( atlasElem.attribute( u
"fixedScale"_s, u
"0"_s ) !=
"0"_L1 ) ?
Fixed :
Auto;
1053 else if ( atlasElem.hasAttribute( u
"scalingMode"_s ) )
1055 mAtlasScalingMode =
static_cast<AtlasScalingMode>( atlasElem.attribute( u
"scalingMode"_s ).toInt() );
1057 mAtlasMargin = atlasElem.attribute( u
"margin"_s, u
"0.1"_s ).toDouble();
1062 mMapFlags =
static_cast< MapItemFlags>( itemElem.attribute( u
"mapFlags"_s,
nullptr ).toInt() );
1065 mBlockingLabelItems.clear();
1066 mBlockingLabelItemUuids.clear();
1067 QDomNodeList labelBlockingNodeList = itemElem.elementsByTagName( u
"labelBlockingItems"_s );
1068 if ( !labelBlockingNodeList.isEmpty() )
1070 QDomElement blockingItems = labelBlockingNodeList.at( 0 ).toElement();
1071 QDomNodeList labelBlockingNodeList = blockingItems.childNodes();
1072 for (
int i = 0; i < labelBlockingNodeList.size(); ++i )
1074 const QDomElement &itemBlockingElement = labelBlockingNodeList.at( i ).toElement();
1075 const QString itemUuid = itemBlockingElement.attribute( u
"uuid"_s );
1076 mBlockingLabelItemUuids << itemUuid;
1080 mAtlasClippingSettings->readXml( itemElem, doc, context );
1081 mItemClippingSettings->readXml( itemElem, doc, context );
1086 setIsTemporal( itemElem.attribute( u
"isTemporal"_s ).toInt() );
1089 const QDateTime begin = QDateTime::fromString( itemElem.attribute( u
"temporalRangeBegin"_s ), Qt::ISODate );
1090 const QDateTime end = QDateTime::fromString( itemElem.attribute( u
"temporalRangeEnd"_s ), Qt::ISODate );
1094 mZRangeEnabled = itemElem.attribute( u
"enableZRange"_s ).toInt();
1096 double zLower = itemElem.attribute( u
"zRangeLower"_s ).toDouble( &ok );
1099 zLower = std::numeric_limits< double >::lowest();
1101 double zUpper = itemElem.attribute( u
"zRangeUpper"_s ).toDouble( &ok );
1104 zUpper = std::numeric_limits< double >::max();
1108 mUpdatesEnabled =
true;
1112bool QgsLayoutItemMap::hasCustomFramePath()
const
1123 return mItemClippingSettings->isActive();
1128 QPainterPath customFramePath;
1129 if ( mAtlasClippingSettings->enabled() && mAtlasClippingSettings->clipItemShape() )
1134 QPolygonF visibleExtent = calculateVisibleExtentPolygon(
false );
1135 QPolygonF rectPoly = QPolygonF( QRectF( 0, 0, rect().width(), rect().height() ) );
1138 visibleExtent.pop_back();
1139 rectPoly.pop_back();
1142 QTransform transform;
1143 QTransform::quadToQuad( visibleExtent, rectPoly, transform );
1153 if ( mItemClippingSettings->isActive() )
1155 const QgsGeometry g = mItemClippingSettings->clipPathInMapItemCoordinates();
1158 if ( !customFramePath.isEmpty() )
1161 customFramePath.closeSubpath();
1175 if ( !
mLayout || !painter || !painter->device() || !mUpdatesEnabled )
1184 QRectF thisPaintRect = rect();
1190 if (
mLayout->renderContext().isPreviewRender() )
1192 bool renderInProgress =
false;
1193 mPreviewDevicePixelRatio = painter->device()->devicePixelRatioF();
1196 painter->setClipRect( thisPaintRect );
1197 if ( !mCacheFinalImage || mCacheFinalImage->isNull() )
1200 painter->setBrush( QBrush( QColor( 125, 125, 125, 125 ) ) );
1201 painter->drawRect( thisPaintRect );
1202 painter->setBrush( Qt::NoBrush );
1204 messageFont.setPointSize( 12 );
1205 painter->setFont( messageFont );
1206 painter->setPen( QColor( 255, 255, 255, 255 ) );
1207 painter->drawText( thisPaintRect, Qt::AlignCenter | Qt::AlignHCenter, tr(
"Rendering map" ) );
1208 if ( mPainterJob && mCacheInvalidated && !mDrawingPreview )
1212 mBackgroundUpdateTimer->start( 100 );
1214 else if ( !mPainterJob && !mDrawingPreview )
1218 mBackgroundUpdateTimer->start( 100 );
1220 renderInProgress =
true;
1224 if ( mCacheInvalidated && !mDrawingPreview )
1228 mBackgroundUpdateTimer->start( 100 );
1229 renderInProgress =
true;
1234 double imagePixelWidth = mCacheFinalImage->width();
1235 double scale = rect().width() / imagePixelWidth * mCacheFinalImage->devicePixelRatio();
1239 painter->translate( mLastRenderedImageOffsetX + mXOffset, mLastRenderedImageOffsetY + mYOffset );
1240 painter->setCompositionMode( blendModeForRender() );
1242 painter->drawImage( 0, 0, *mCacheFinalImage );
1247 painter->setClipRect( thisPaintRect, Qt::NoClip );
1249 mOverviewStack->drawItems( painter,
false );
1250 mGridStack->drawItems( painter );
1252 drawMapFrame( painter );
1254 if ( renderInProgress )
1265 QPaintDevice *paintDevice = painter->device();
1273 painter->setRenderHint( QPainter::LosslessImageRendering,
true );
1278 && ( !
mLayout || !forceVector ) )
1283 int widthInPixels =
static_cast< int >( std::round(
boundingRect().width() * layoutUnitsInInches * destinationDpi ) );
1284 int heightInPixels =
static_cast< int >( std::round(
boundingRect().height() * layoutUnitsInInches * destinationDpi ) );
1285 QImage image = QImage( widthInPixels, heightInPixels, QImage::Format_ARGB32 );
1287 image.fill( Qt::transparent );
1288 image.setDotsPerMeterX(
static_cast< int >( std::round( 1000 * destinationDpi / 25.4 ) ) );
1289 image.setDotsPerMeterY(
static_cast< int >( std::round( 1000 * destinationDpi / 25.4 ) ) );
1290 double dotsPerMM = destinationDpi / 25.4;
1291 QPainter p( &image );
1294 QRect imagePaintRect(
static_cast< int >( std::round( tl.x() * dotsPerMM ) ),
1295 static_cast< int >( std::round( tl.y() * dotsPerMM ) ),
1296 static_cast< int >( std::round( thisPaintRect.width() * dotsPerMM ) ),
1297 static_cast< int >( std::round( thisPaintRect.height() * dotsPerMM ) ) );
1298 p.setClipRect( imagePaintRect );
1300 p.translate( imagePaintRect.topLeft() );
1304 if ( shouldDrawPart( Background ) )
1306 p.scale( dotsPerMM, dotsPerMM );
1307 drawMapBackground( &p );
1308 p.scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
1311 drawMap( &p, cExtent, imagePaintRect.size(), image.logicalDpiX() );
1316 p.scale( dotsPerMM, dotsPerMM );
1318 if ( shouldDrawPart( OverviewMapExtent ) )
1320 mOverviewStack->drawItems( &p,
false );
1322 if ( shouldDrawPart( Grid ) )
1324 mGridStack->drawItems( &p );
1329 painter->setCompositionMode( blendModeForRender() );
1330 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
1331 painter->drawImage( QPointF( -tl.x()* dotsPerMM, -tl.y() * dotsPerMM ), image );
1332 painter->scale( dotsPerMM, dotsPerMM );
1337 if ( shouldDrawPart( Background ) )
1339 drawMapBackground( painter );
1343 painter->setClipRect( thisPaintRect );
1348 painter->translate( mXOffset, mYOffset );
1350 double dotsPerMM = paintDevice->logicalDpiX() / 25.4;
1352 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
1354 if ( mCurrentExportPart != NotLayered )
1356 if ( !mStagedRendererJob )
1358 createStagedRenderJob( cExtent, size, paintDevice->logicalDpiX() );
1361 mStagedRendererJob->renderCurrentPart( painter );
1365 drawMap( painter, cExtent, size, paintDevice->logicalDpiX() );
1369 painter->setClipRect( thisPaintRect, Qt::NoClip );
1371 if ( shouldDrawPart( OverviewMapExtent ) )
1373 mOverviewStack->drawItems( painter,
false );
1375 if ( shouldDrawPart( Grid ) )
1377 mGridStack->drawItems( painter );
1382 if ( shouldDrawPart( Frame ) )
1384 drawMapFrame( painter );
1395 + ( layerCount + ( layerCount ? 1 : 0 ) )
1396 + ( mGridStack->hasEnabledItems() ? 1 : 0 )
1397 + ( mOverviewStack->hasEnabledItems() ? 1 : 0 )
1403 mCurrentExportPart = Start;
1405 mExportThemes = !mFollowVisibilityPreset ?
mLayout->renderContext().exportThemes() : QStringList();
1406 mExportThemeIt = mExportThemes.begin();
1411 mCurrentExportPart = NotLayered;
1412 mExportThemes.clear();
1413 mExportThemeIt = mExportThemes.begin();
1418 switch ( mCurrentExportPart )
1423 mCurrentExportPart = Background;
1429 mCurrentExportPart = Layer;
1433 if ( mStagedRendererJob )
1435 if ( mStagedRendererJob->nextPart() )
1439 mExportLabelingResults.reset( mStagedRendererJob->takeLabelingResults() );
1440 mStagedRendererJob.reset();
1444 if ( mExportThemeIt != mExportThemes.end() && ++mExportThemeIt != mExportThemes.end() )
1450 if ( mGridStack->hasEnabledItems() )
1452 mCurrentExportPart = Grid;
1458 for (
int i = 0; i < mOverviewStack->size(); ++i )
1463 mCurrentExportPart = OverviewMapExtent;
1469 case OverviewMapExtent:
1472 mCurrentExportPart = Frame;
1479 if ( isSelected() && !
mLayout->renderContext().isPreviewRender() )
1481 mCurrentExportPart = SelectionBoxes;
1486 case SelectionBoxes:
1487 mCurrentExportPart = End;
1508 switch ( mCurrentExportPart )
1518 if ( !mExportThemes.empty() && mExportThemeIt != mExportThemes.end() )
1521 if ( mStagedRendererJob )
1523 switch ( mStagedRendererJob->currentStage() )
1527 detail.
mapLayerId = mStagedRendererJob->currentLayerId();
1528 detail.
compositionMode = mStagedRendererJob->currentLayerCompositionMode();
1529 detail.
opacity = mStagedRendererJob->currentLayerOpacity();
1537 else if (
mLayout->project()->mainAnnotationLayer()->id() == detail.
mapLayerId )
1548 const QList<QgsLayoutItemMapOverview *> res = mOverviewStack->asList();
1554 if ( item->mapLayer() && detail.
mapLayerId == item->mapLayer()->id() )
1559 detail.
name = u
"%1: %2"_s.arg(
displayName(), item->mapLayer()->name() );
1568 detail.
mapLayerId = mStagedRendererJob->currentLayerId();
1574 detail.
name = tr(
"%1: %2 (Labels)" ).arg(
displayName(), layer->name() );
1609 case OverviewMapExtent:
1617 case SelectionBoxes:
1632void QgsLayoutItemMap::drawMap( QPainter *painter,
const QgsRectangle &extent, QSizeF size,
double dpi )
1646 if ( shouldDrawPart( OverviewMapExtent ) )
1648 ms.setLayers( mOverviewStack->modifyMapLayerList( ms.layers() ) );
1651 QgsMapRendererCustomPainterJob job( ms, painter );
1652#ifdef HAVE_SERVER_PYTHON_PLUGINS
1653 job.setFeatureFilterProvider(
mLayout->renderContext().featureFilterProvider() );
1656 QgsGroupedFeatureFilterProvider jobFeatureFilter;
1659 jobFeatureFilter.
addProvider( mAtlasFeatureFilterProvider.get() );
1660 if ( job.featureFilterProvider() )
1662 jobFeatureFilter.
addProvider( job.featureFilterProvider() );
1664 job.setFeatureFilterProvider( &jobFeatureFilter );
1670 job.renderSynchronously();
1672 mExportLabelingResults.reset( job.takeLabelingResults() );
1674 mRenderingErrors = job.errors();
1678 mRenderingErrors.append( QgsMapRendererJob::Error( QString(), u
"Invalid layer(s)"_s ) );
1682void QgsLayoutItemMap::recreateCachedImageInBackground()
1687 QgsMapRendererCustomPainterJob *oldJob = mPainterJob.release();
1688 QPainter *oldPainter = mPainter.release();
1689 QImage *oldImage = mCacheRenderingImage.release();
1692 oldJob->deleteLater();
1700 mCacheRenderingImage.reset(
nullptr );
1704 Q_ASSERT( !mPainterJob );
1705 Q_ASSERT( !mPainter );
1706 Q_ASSERT( !mCacheRenderingImage );
1708 QgsRectangle ext =
extent();
1712 int w =
static_cast< int >( std::round( widthLayoutUnits * mPreviewScaleFactor ) );
1713 int h =
static_cast< int >( std::round( heightLayoutUnits * mPreviewScaleFactor ) );
1716 if ( w > 5000 || h > 5000 )
1721 h =
static_cast< int>( std::round( w * heightLayoutUnits / widthLayoutUnits ) );
1726 w =
static_cast< int >( std::round( h * widthLayoutUnits / heightLayoutUnits ) );
1730 if ( w <= 0 || h <= 0 )
1733 mCacheRenderingImage = std::make_unique<QImage>( w * mPreviewDevicePixelRatio, h * mPreviewDevicePixelRatio, QImage::Format_ARGB32 );
1736 mCacheRenderingImage->setDotsPerMeterX(
static_cast< int >( std::round( 1000 * w / widthLayoutUnits ) ) );
1737 mCacheRenderingImage->setDotsPerMeterY(
static_cast< int >( std::round( 1000 * h / heightLayoutUnits ) ) );
1738 mCacheRenderingImage->setDevicePixelRatio( mPreviewDevicePixelRatio );
1741 mCacheRenderingImage->fill( QColor( 255, 255, 255, 0 ).rgba() );
1746 if ( hasCustomFramePath() )
1748 QPainter p( mCacheRenderingImage.get() );
1750 p.setPen( Qt::NoPen );
1752 p.scale( mCacheRenderingImage->width() / widthLayoutUnits, mCacheRenderingImage->height() / heightLayoutUnits );
1762 mCacheInvalidated =
false;
1763 mPainter = std::make_unique<QPainter>( mCacheRenderingImage.get() );
1764 QgsMapSettings settings(
mapSettings( ext, QSizeF( w, h ), mCacheRenderingImage->logicalDpiX(),
true ) );
1766 if ( shouldDrawPart( OverviewMapExtent ) )
1768 settings.setLayers( mOverviewStack->modifyMapLayerList( settings.layers() ) );
1771 mPainterJob = std::make_unique<QgsMapRendererCustomPainterJob>( settings, mPainter.get() );
1774 mPainterJob->setFeatureFilterProvider( mAtlasFeatureFilterProvider.get() );
1777 mPainterJob->start();
1789 mDrawingPreview =
false;
1812 if (
layout()->renderContext().isPreviewRender() )
1815 jobMapSettings.
setDevicePixelRatio( mPainter ? mPainter->device()->devicePixelRatioF() : 1.0 );
1818 jobMapSettings.
setRotation( mEvaluatedMapRotation );
1826 if ( includeLayerSettings )
1831 if ( !
mLayout->project()->mainAnnotationLayer()->isEmpty() )
1834 layers.insert( 0,
mLayout->project()->mainAnnotationLayer() );
1841 if ( !
mLayout->renderContext().isPreviewRender() )
1889 if ( mEvaluatedLabelMargin.length() > 0 )
1892 visiblePoly.append( visiblePoly.at( 0 ) );
1893 const double layoutLabelMargin =
mLayout->convertToLayoutUnits( mEvaluatedLabelMargin );
1894 const double layoutLabelMarginInMapUnits = layoutLabelMargin / rect().width() * jobMapSettings.
extent().
width();
1896 mapBoundaryGeom = mapBoundaryGeom.
buffer( -layoutLabelMarginInMapUnits, 0 );
1897 labelBoundary = mapBoundaryGeom;
1900 if ( !mBlockingLabelItems.isEmpty() )
1913 if ( mZRangeEnabled )
1918 if ( mAtlasClippingSettings->enabled() &&
mLayout->reportContext().feature().isValid() )
1922 region.
setFeatureClip( mAtlasClippingSettings->featureClippingType() );
1927 if ( mAtlasClippingSettings->forceLabelsInsideFeature() )
1929 if ( !labelBoundary.
isEmpty() )
1931 labelBoundary = clipGeom.
intersection( labelBoundary );
1935 labelBoundary = clipGeom;
1940 if ( mItemClippingSettings->isActive() )
1942 const QgsGeometry clipGeom = mItemClippingSettings->clippedMapExtent();
1945 jobMapSettings.
addClippingRegion( mItemClippingSettings->toMapClippingRegion() );
1947 if ( mItemClippingSettings->forceLabelsInsideClipPath() )
1949 const double layoutLabelMargin =
mLayout->convertToLayoutUnits( mEvaluatedLabelMargin );
1950 const double layoutLabelMarginInMapUnits = layoutLabelMargin / rect().width() * jobMapSettings.
extent().
width();
1952 mapBoundaryGeom = mapBoundaryGeom.
buffer( -layoutLabelMarginInMapUnits, 0 );
1953 if ( !labelBoundary.
isEmpty() )
1955 labelBoundary = mapBoundaryGeom.
intersection( labelBoundary );
1959 labelBoundary = mapBoundaryGeom;
1965 if ( !labelBoundary.
isNull() )
1968 return jobMapSettings;
1975 mBlockingLabelItems.clear();
1976 for (
const QString &
uuid : std::as_const( mBlockingLabelItemUuids ) )
1985 mOverviewStack->finalizeRestoreFromXml();
1986 mGridStack->finalizeRestoreFromXml();
1987 mItemClippingSettings->finalizeRestoreFromXml();
1998 return mCurrentRectangle;
2012 const double mapScale =
scale();
2036 QVariantList layersIds;
2046 const QList<QgsMapLayer *> layersInMap =
layersToRender( &context );
2048 layersIds.reserve( layersInMap.count() );
2049 layers.reserve( layersInMap.count() );
2052 layersIds << layer->id();
2058 scope->
addFunction( u
"is_layer_visible"_s,
new QgsExpressionContextUtils::GetLayerVisibility( layersInMap,
scale() ) );
2080 if ( extentWidth <= 0 )
2084 return rect().width() / extentWidth;
2089 double dx = mXOffset;
2090 double dy = mYOffset;
2091 transformShift( dx, dy );
2092 QPolygonF poly = calculateVisibleExtentPolygon(
false );
2093 poly.translate( -dx, -dy );
2099 if ( !mBlockingLabelItems.contains( item ) )
2100 mBlockingLabelItems.append( item );
2107 mBlockingLabelItems.removeAll( item );
2114 return mBlockingLabelItems.contains( item );
2119 return mPreviewLabelingResults.get();
2128 if ( mOverviewStack )
2130 for (
int i = 0; i < mOverviewStack->size(); ++i )
2132 if ( mOverviewStack->item( i )->accept( visitor ) )
2139 for (
int i = 0; i < mGridStack->size(); ++i )
2141 if ( mGridStack->item( i )->accept( visitor ) )
2154 mRenderedFeatureHandlers.append( handler );
2159 mRenderedFeatureHandlers.removeAll( handler );
2165 if ( mapPoly.empty() )
2167 return QPointF( 0, 0 );
2172 double dx = mapCoords.x() - rotationPoint.
x();
2173 double dy = mapCoords.y() - rotationPoint.
y();
2175 QgsPointXY backRotatedCoords( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
2178 double xItem = rect().width() * ( backRotatedCoords.
x() - unrotatedExtent.
xMinimum() ) / unrotatedExtent.
width();
2179 double yItem = rect().height() * ( 1 - ( backRotatedCoords.
y() - unrotatedExtent.
yMinimum() ) / unrotatedExtent.
height() );
2180 return QPointF( xItem, yItem );
2194 mapPolygon( newExtent, poly );
2195 QRectF bRect = poly.boundingRect();
2196 extent.setXMinimum( bRect.left() );
2197 extent.setXMaximum( bRect.right() );
2198 extent.setYMinimum( bRect.top() );
2199 extent.setYMaximum( bRect.bottom() );
2209 mCacheInvalidated =
true;
2215 QRectF rectangle = rect();
2216 double frameExtension =
frameEnabled() ? pen().widthF() / 2.0 : 0.0;
2218 double topExtension = 0.0;
2219 double rightExtension = 0.0;
2220 double bottomExtension = 0.0;
2221 double leftExtension = 0.0;
2224 mGridStack->calculateMaxGridExtension( topExtension, rightExtension, bottomExtension, leftExtension );
2226 topExtension = std::max( topExtension, frameExtension );
2227 rightExtension = std::max( rightExtension, frameExtension );
2228 bottomExtension = std::max( bottomExtension, frameExtension );
2229 leftExtension = std::max( leftExtension, frameExtension );
2231 rectangle.setLeft( rectangle.left() - leftExtension );
2232 rectangle.setRight( rectangle.right() + rightExtension );
2233 rectangle.setTop( rectangle.top() - topExtension );
2234 rectangle.setBottom( rectangle.bottom() + bottomExtension );
2235 if ( rectangle != mCurrentRectangle )
2237 prepareGeometryChange();
2238 mCurrentRectangle = rectangle;
2266 refreshMapExtents( &context );
2268 if ( mExtent != beforeExtent )
2275 refreshLabelMargin(
false );
2279 const QString previousTheme = mLastEvaluatedThemeName.isEmpty() ? mFollowVisibilityPresetName : mLastEvaluatedThemeName;
2281 if ( mLastEvaluatedThemeName != previousTheme )
2300 double zLower = mZRange.lower();
2301 double zUpper = mZRange.upper();
2312 mCacheInvalidated =
true;
2317void QgsLayoutItemMap::layersAboutToBeRemoved(
const QList<QgsMapLayer *> &layers )
2320 if ( !mLayers.isEmpty() || mLayerStyleOverrides.isEmpty() )
2324 mLayerStyleOverrides.remove( layer->id() );
2326 _qgis_removeLayers( mLayers,
layers );
2329 for ( QgsMapLayer *layer : std::as_const(
layers ) )
2332 if ( mGroupLayers.erase( layer->id() ) == 0 )
2335 for (
auto it = mGroupLayers.begin(); it != mGroupLayers.end(); ++it )
2337 QgsGroupLayer *groupLayer = it->second.get();
2338 if ( groupLayer->
childLayers().contains( layer ) )
2340 QList<QgsMapLayer *> childLayers { groupLayer->
childLayers() };
2341 childLayers.removeAll( layer );
2349void QgsLayoutItemMap::painterJobFinished()
2352 mPreviewLabelingResults.reset( mPainterJob->takeLabelingResults() );
2353 mPainterJob.reset(
nullptr );
2354 mPainter.reset(
nullptr );
2355 mCacheFinalImage = std::move( mCacheRenderingImage );
2356 mLastRenderedImageOffsetX = 0;
2357 mLastRenderedImageOffsetY = 0;
2363void QgsLayoutItemMap::shapeChanged()
2366 QgsPointXY oldCenter = mExtent.center();
2368 double w = rect().width();
2369 double h = rect().height();
2372 double newWidth = mExtent.width();
2374 double newHeight = newWidth * h / w;
2379 refreshMapExtents();
2386void QgsLayoutItemMap::mapThemeChanged(
const QString &theme )
2388 if ( theme == mCachedLayerStyleOverridesPresetName )
2389 mCachedLayerStyleOverridesPresetName.clear();
2392void QgsLayoutItemMap::currentMapThemeRenamed(
const QString &theme,
const QString &newTheme )
2394 if ( theme == mFollowVisibilityPresetName )
2396 mFollowVisibilityPresetName = newTheme;
2400void QgsLayoutItemMap::connectUpdateSlot()
2403 QgsProject *project =
mLayout->project();
2408 this, &QgsLayoutItemMap::layersAboutToBeRemoved );
2412 if ( layers().isEmpty() )
2421 if ( !mCrs.isValid() )
2441 if ( mAtlasScalingMode == Predefined )
2442 updateAtlasFeature();
2448 QPolygonF thisExtent = calculateVisibleExtentPolygon(
false );
2449 QTransform mapTransform;
2450 QPolygonF thisRectPoly = QPolygonF( QRectF( 0, 0, rect().width(), rect().height() ) );
2452 thisRectPoly.pop_back();
2453 thisExtent.pop_back();
2455 QPolygonF thisItemPolyInLayout = mapToScene( thisRectPoly );
2458 QTransform::quadToQuad( thisItemPolyInLayout, thisExtent, mapTransform );
2459 return mapTransform;
2464 mZRangeEnabled = enabled;
2469 return mZRangeEnabled;
2482QList<QgsLabelBlockingRegion> QgsLayoutItemMap::createLabelBlockingRegions(
const QgsMapSettings & )
const
2485 QList< QgsLabelBlockingRegion > blockers;
2486 blockers.reserve( mBlockingLabelItems.count() );
2487 for (
const auto &item : std::as_const( mBlockingLabelItems ) )
2494 if ( item->property(
"wasVisible" ).isValid() )
2496 if ( !item->property(
"wasVisible" ).toBool() )
2499 else if ( !item->isVisible() )
2502 QPolygonF itemRectInMapCoordinates = mapTransform.map( item->mapToScene( item->rect() ) );
2503 itemRectInMapCoordinates.append( itemRectInMapCoordinates.at( 0 ) );
2505 blockers << QgsLabelBlockingRegion( blockingRegion );
2512 return mLabelMargin;
2517 mLabelMargin = margin;
2518 refreshLabelMargin(
false );
2521void QgsLayoutItemMap::updateToolTip()
2530 if ( mFollowVisibilityPreset )
2532 presetName = mFollowVisibilityPresetName;
2536 else if ( !mExportThemes.empty() && mExportThemeIt != mExportThemes.end() )
2537 presetName = *mExportThemeIt;
2548 QList<QgsMapLayer *> renderLayers;
2550 QString presetName = themeToRender( *evalContext );
2551 if ( !presetName.isEmpty() )
2553 if (
mLayout->project()->mapThemeCollection()->hasMapTheme( presetName ) )
2554 renderLayers =
mLayout->project()->mapThemeCollection()->mapThemeVisibleLayers( presetName );
2556 renderLayers =
mLayout->project()->mapThemeCollection()->masterVisibleLayers();
2558 else if ( !
layers().isEmpty() )
2564 renderLayers =
mLayout->project()->mapThemeCollection()->masterVisibleLayers();
2571 renderLayers.clear();
2573 const QStringList layerNames = ddLayers.split(
'|' );
2575 for (
const QString &name : layerNames )
2577 const QList< QgsMapLayer * > matchingLayers =
mLayout->project()->mapLayersByName( name );
2580 renderLayers << layer;
2589 int removeAt = renderLayers.indexOf(
mLayout->reportContext().layer() );
2590 if ( removeAt != -1 )
2592 renderLayers.removeAt( removeAt );
2597 if ( !includeInvalidLayers )
2599 renderLayers.erase( std::remove_if( renderLayers.begin(), renderLayers.end(), [](
QgsMapLayer * layer )
2601 return !layer || !layer->isValid();
2602 } ), renderLayers.end() );
2605 return renderLayers;
2608QMap<QString, QString> QgsLayoutItemMap::layerStyleOverridesToRender(
const QgsExpressionContext &context )
const
2610 QString presetName = themeToRender( context );
2611 if ( !presetName.isEmpty() )
2613 if (
mLayout->project()->mapThemeCollection()->hasMapTheme( presetName ) )
2615 if ( presetName != mCachedLayerStyleOverridesPresetName )
2618 mCachedPresetLayerStyleOverrides =
mLayout->project()->mapThemeCollection()->mapThemeStyleOverrides( presetName );
2619 mCachedLayerStyleOverridesPresetName = presetName;
2622 return mCachedPresetLayerStyleOverrides;
2625 return QMap<QString, QString>();
2627 else if ( mFollowVisibilityPreset )
2629 QString presetName = mFollowVisibilityPresetName;
2632 if (
mLayout->project()->mapThemeCollection()->hasMapTheme( presetName ) )
2634 if ( presetName.isEmpty() || presetName != mCachedLayerStyleOverridesPresetName )
2637 mCachedPresetLayerStyleOverrides =
mLayout->project()->mapThemeCollection()->mapThemeStyleOverrides( presetName );
2638 mCachedLayerStyleOverridesPresetName = presetName;
2641 return mCachedPresetLayerStyleOverrides;
2644 return QMap<QString, QString>();
2646 else if ( mKeepLayerStyles )
2648 return mLayerStyleOverrides;
2652 return QMap<QString, QString>();
2656QgsRectangle QgsLayoutItemMap::transformedExtent()
const
2658 double dx = mXOffset;
2659 double dy = mYOffset;
2660 transformShift( dx, dy );
2661 return QgsRectangle( mExtent.xMinimum() - dx, mExtent.yMinimum() - dy, mExtent.xMaximum() - dx, mExtent.yMaximum() - dy );
2664void QgsLayoutItemMap::mapPolygon(
const QgsRectangle &extent, QPolygonF &poly )
const
2669 poly << QPointF(
extent.xMinimum(),
extent.yMaximum() );
2670 poly << QPointF(
extent.xMaximum(),
extent.yMaximum() );
2671 poly << QPointF(
extent.xMaximum(),
extent.yMinimum() );
2672 poly << QPointF(
extent.xMinimum(),
extent.yMinimum() );
2674 poly << QPointF( poly.at( 0 ) );
2679 QgsPointXY rotationPoint( (
extent.xMaximum() +
extent.xMinimum() ) / 2.0, (
extent.yMaximum() +
extent.yMinimum() ) / 2.0 );
2683 dx = rotationPoint.x() -
extent.xMinimum();
2684 dy = rotationPoint.y() -
extent.yMaximum();
2686 poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2689 dx = rotationPoint.x() -
extent.xMaximum();
2690 dy = rotationPoint.y() -
extent.yMaximum();
2692 poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2695 dx = rotationPoint.x() -
extent.xMaximum();
2696 dy = rotationPoint.y() -
extent.yMinimum();
2698 poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2701 dx = rotationPoint.x() -
extent.xMinimum();
2702 dy = rotationPoint.y() -
extent.yMinimum();
2704 poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2707 poly << QPointF( poly.at( 0 ) );
2710void QgsLayoutItemMap::transformShift(
double &xShift,
double &yShift )
const
2713 double dxScaled = xShift * mmToMapUnits;
2714 double dyScaled = - yShift * mmToMapUnits;
2729 const QList< QgsAnnotation * > annotations =
mLayout->project()->annotationManager()->annotations();
2730 if ( annotations.isEmpty() )
2739 for ( QgsAnnotation *annotation : annotations )
2741 if ( !annotation || !annotation->isVisible() )
2745 if ( annotation->mapLayer() && !
layers.contains( annotation->mapLayer() ) )
2748 drawAnnotation( annotation, rc );
2759 QgsScopedQPainterState painterState( context.
painter() );
2762 double itemX, itemY;
2765 QPointF mapPos = layoutMapPosForItem( annotation );
2774 context.
painter()->translate( itemX, itemY );
2777 double dotsPerMM = context.
painter()->device()->logicalDpiX() / 25.4;
2778 context.
painter()->scale( 1 / dotsPerMM, 1 / dotsPerMM );
2780 annotation->
render( context );
2783QPointF QgsLayoutItemMap::layoutMapPosForItem(
const QgsAnnotation *annotation )
const
2786 return QPointF( 0, 0 );
2793 QgsCoordinateReferenceSystem annotationCrs = annotation->
mapPositionCrs();
2795 if ( annotationCrs !=
crs() )
2798 QgsCoordinateTransform t( annotationCrs,
crs(),
mLayout->project() );
2802 t.transformInPlace( mapX, mapY, z );
2804 catch (
const QgsCsException & )
2812void QgsLayoutItemMap::drawMapFrame( QPainter *p )
2823void QgsLayoutItemMap::drawMapBackground( QPainter *p )
2834bool QgsLayoutItemMap::shouldDrawPart( QgsLayoutItemMap::PartType part )
const
2836 if ( mCurrentExportPart == NotLayered )
2854 return mCurrentExportPart == Layer;
2857 return mCurrentExportPart == Grid && mGridStack->hasEnabledItems();
2859 case OverviewMapExtent:
2860 return mCurrentExportPart == OverviewMapExtent && mOverviewStack->hasEnabledItems();
2865 case SelectionBoxes:
2866 return mCurrentExportPart == SelectionBoxes && isSelected();
2877 QgsExpressionContext scopedContext;
2882 const QgsExpressionContext *evalContext = context ? context : &scopedContext;
2886 QgsRectangle newExtent =
extent();
2887 bool useDdXMin =
false;
2888 bool useDdXMax =
false;
2889 bool useDdYMin =
false;
2890 bool useDdYMax =
false;
2921 if ( newExtent != mExtent )
2927 double currentWidthHeightRatio = mExtent.width() / mExtent.height();
2928 double newWidthHeightRatio = newExtent.
width() / newExtent.
height();
2930 if ( currentWidthHeightRatio < newWidthHeightRatio )
2933 double newHeight = newExtent.
width() / currentWidthHeightRatio;
2934 double deltaHeight = newHeight - newExtent.
height();
2941 double newWidth = currentWidthHeightRatio * newExtent.
height();
2942 double deltaWidth = newWidth - newExtent.
width();
2947 mExtent = newExtent;
2957 newExtent = mExtent;
2960 if ( useDdXMax || useDdXMin || useDdYMax || useDdYMin )
2964 if ( useDdXMin && !useDdXMax )
2966 double xMax = mExtent.xMaximum() - ( mExtent.xMinimum() - minXD );
2970 else if ( !useDdXMin && useDdXMax )
2972 double xMin = mExtent.xMinimum() - ( mExtent.xMaximum() - maxXD );
2976 if ( useDdYMin && !useDdYMax )
2978 double yMax = mExtent.yMaximum() - ( mExtent.yMinimum() - minYD );
2982 else if ( !useDdYMin && useDdYMax )
2984 double yMin = mExtent.yMinimum() - ( mExtent.yMaximum() - maxYD );
2989 if ( newExtent != mExtent )
2991 mExtent = newExtent;
3008void QgsLayoutItemMap::refreshLabelMargin(
bool updateItem )
3013 mEvaluatedLabelMargin.setUnits( mLabelMargin.units() );
3021void QgsLayoutItemMap::updateAtlasFeature()
3023 if ( !
mLayout->reportContext().layer() || !
mLayout->reportContext().feature().isValid() )
3026 QgsFeatureExpressionFilterProvider *filter =
new QgsFeatureExpressionFilterProvider();
3027 filter->
setFilter(
mLayout->reportContext().layer()->id(), QgsExpression( u
"@id = %1"_s.arg(
mLayout->reportContext().feature().id() ) ) );
3028 mAtlasFeatureFilterProvider = std::make_unique<QgsGroupedFeatureFilterProvider>( );
3029 mAtlasFeatureFilterProvider->addProvider( filter );
3034 QgsRectangle bounds = computeAtlasRectangle();
3042 QgsRectangle newExtent = bounds;
3043 QgsRectangle originalExtent = mExtent;
3048 if ( mAtlasScalingMode ==
Fixed || mAtlasScalingMode ==
Predefined || isPointLayer )
3050 QgsScaleCalculator calc;
3053 if ( QgsProject *project =
mLayout->project() )
3057 double originalScale = calc.
calculate( originalExtent, rect().width() );
3058 double geomCenterX = ( xa1 + xa2 ) / 2.0;
3059 double geomCenterY = ( ya1 + ya2 ) / 2.0;
3060 QVector<qreal> scales;
3062 if ( !
mLayout->reportContext().predefinedScales().empty() )
3063 scales =
mLayout->reportContext().predefinedScales();
3065 scales =
mLayout->renderContext().predefinedScales();
3067 if ( mAtlasScalingMode ==
Fixed || scales.isEmpty() || ( isPointLayer && mAtlasScalingMode !=
Predefined ) )
3070 double xMin = geomCenterX - originalExtent.
width() / 2.0;
3071 double yMin = geomCenterY - originalExtent.
height() / 2.0;
3072 newExtent = QgsRectangle( xMin,
3074 xMin + originalExtent.
width(),
3075 yMin + originalExtent.
height() );
3079 double newScale = calc.
calculate( newExtent, rect().width() );
3082 newExtent.
scale( originalScale / newScale );
3088 double newWidth = originalExtent.
width();
3089 double newHeight = originalExtent.
height();
3090 for (
int i = 0; i < scales.size(); i++ )
3092 double ratio = scales[i] / originalScale;
3093 newWidth = originalExtent.
width() * ratio;
3094 newHeight = originalExtent.
height() * ratio;
3097 double xMin = geomCenterX - newWidth / 2.0;
3098 double yMin = geomCenterY - newHeight / 2.0;
3099 newExtent = QgsRectangle( xMin,
3106 const double newScale = calc.
calculate( newExtent, rect().width() );
3110 newExtent.
scale( scales[i] / newScale );
3120 else if ( mAtlasScalingMode ==
Auto )
3124 double geomRatio = bounds.
width() / bounds.
height();
3125 double mapRatio = originalExtent.
width() / originalExtent.
height();
3128 if ( geomRatio < mapRatio )
3131 double adjWidth = ( mapRatio * bounds.
height() - bounds.
width() ) / 2.0;
3136 else if ( geomRatio > mapRatio )
3139 double adjHeight = ( bounds.
width() / mapRatio - bounds.
height() ) / 2.0;
3143 newExtent = QgsRectangle( xa1, ya1, xa2, ya2 );
3145 const double evaluatedAtlasMargin =
atlasMargin();
3146 if ( evaluatedAtlasMargin > 0.0 )
3148 newExtent.
scale( 1 + evaluatedAtlasMargin );
3162 QgsGeometry g =
mLayout->reportContext().currentGeometry(
crs() );
3174 double dx = std::max( std::abs( prevCenter.
x() - bounds.
xMinimum() ),
3175 std::abs( prevCenter.
x() - bounds.
xMaximum() ) );
3176 double dy = std::max( std::abs( prevCenter.
y() - bounds.
yMinimum() ),
3177 std::abs( prevCenter.
y() - bounds.
yMaximum() ) );
3179 return QgsRectangle( center.
x() - dx, center.
y() - dy,
3180 center.
x() + dx, center.
y() + dy );
3188void QgsLayoutItemMap::createStagedRenderJob(
const QgsRectangle &extent,
const QSizeF size,
double dpi )
3191 settings.
setLayers( mOverviewStack->modifyMapLayerList( settings.
layers() ) );
3193 mStagedRendererJob = std::make_unique< QgsMapRendererStagedRenderJob >( settings,
3197 mStagedRendererJob->start();
3210 if ( mMap->layout() && mMap->layout()->project() )
3212 connect( mMap->layout()->project(), static_cast < void ( QgsProject::* )( const QList<QgsMapLayer *>& layers ) > ( &QgsProject::layersWillBeRemoved ),
3213 this, &QgsLayoutItemMapAtlasClippingSettings::layersAboutToBeRemoved );
3219 return mClipToAtlasFeature;
3224 if (
enabled == mClipToAtlasFeature )
3227 mClipToAtlasFeature =
enabled;
3233 return mFeatureClippingType;
3238 if ( mFeatureClippingType == type )
3241 mFeatureClippingType = type;
3247 return mForceLabelsInsideFeature;
3252 if ( forceInside == mForceLabelsInsideFeature )
3255 mForceLabelsInsideFeature = forceInside;
3261 return mClipItemShape;
3275 return mRestrictToLayers;
3280 if ( mRestrictToLayers ==
enabled )
3289 return _qgis_listRefToRaw( mLayersToClip );
3300 QDomElement settingsElem = document.createElement( u
"atlasClippingSettings"_s );
3301 settingsElem.setAttribute( u
"enabled"_s, mClipToAtlasFeature ? u
"1"_s : u
"0"_s );
3302 settingsElem.setAttribute( u
"forceLabelsInside"_s, mForceLabelsInsideFeature ? u
"1"_s : u
"0"_s );
3303 if ( mClipItemShape )
3305 settingsElem.setAttribute( u
"clipItemShape"_s, u
"1"_s );
3307 settingsElem.setAttribute( u
"clippingType"_s, QString::number(
static_cast<int>( mFeatureClippingType ) ) );
3308 settingsElem.setAttribute( u
"restrictLayers"_s, mRestrictToLayers ? u
"1"_s : u
"0"_s );
3311 QDomElement layerSetElem = document.createElement( u
"layersToClip"_s );
3316 QDomElement layerElem = document.createElement( u
"Layer"_s );
3317 QDomText layerIdText = document.createTextNode( layerRef.layerId );
3318 layerElem.appendChild( layerIdText );
3320 layerElem.setAttribute( u
"name"_s, layerRef.name );
3321 layerElem.setAttribute( u
"source"_s, layerRef.source );
3322 layerElem.setAttribute( u
"provider"_s, layerRef.provider );
3324 layerSetElem.appendChild( layerElem );
3326 settingsElem.appendChild( layerSetElem );
3328 element.appendChild( settingsElem );
3334 const QDomElement settingsElem = element.firstChildElement( u
"atlasClippingSettings"_s );
3336 mClipToAtlasFeature = settingsElem.attribute( u
"enabled"_s, u
"0"_s ).toInt();
3337 mForceLabelsInsideFeature = settingsElem.attribute( u
"forceLabelsInside"_s, u
"0"_s ).toInt();
3338 mClipItemShape = settingsElem.attribute( u
"clipItemShape"_s, u
"0"_s ).toInt();
3340 mRestrictToLayers = settingsElem.attribute( u
"restrictLayers"_s, u
"0"_s ).toInt();
3342 mLayersToClip.clear();
3343 QDomNodeList layerSetNodeList = settingsElem.elementsByTagName( u
"layersToClip"_s );
3344 if ( !layerSetNodeList.isEmpty() )
3346 QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
3347 QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( u
"Layer"_s );
3348 mLayersToClip.reserve( layerIdNodeList.size() );
3349 for (
int i = 0; i < layerIdNodeList.size(); ++i )
3351 QDomElement layerElem = layerIdNodeList.at( i ).toElement();
3352 QString layerId = layerElem.text();
3353 QString layerName = layerElem.attribute( u
"name"_s );
3354 QString layerSource = layerElem.attribute( u
"source"_s );
3355 QString layerProvider = layerElem.attribute( u
"provider"_s );
3357 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
3358 if ( mMap->layout() && mMap->layout()->project() )
3360 mLayersToClip << ref;
3367void QgsLayoutItemMapAtlasClippingSettings::layersAboutToBeRemoved(
const QList<QgsMapLayer *> &layers )
3369 if ( !mLayersToClip.isEmpty() )
3371 _qgis_removeLayers( mLayersToClip, layers );
3386 return mEnabled && mClipPathSource;
3401 if ( mClipPathSource )
3404 mClipPathSource->refresh();
3413 QgsGeometry clipGeom( mClipPathSource->clipPath() );
3414 clipGeom.
transform( mMap->layoutToMapCoordsTransform() );
3424 QgsGeometry clipGeom( mClipPathSource->clipPath() );
3425 clipGeom.
transform( mMap->sceneTransform().inverted() );
3440 if ( mClipPathSource == item )
3443 if ( mClipPathSource )
3452 mClipPathSource = item;
3454 if ( mClipPathSource )
3463 mClipPathSource->refresh();
3477 return mClipPathSource;
3482 return mFeatureClippingType;
3487 if ( mFeatureClippingType == type )
3490 mFeatureClippingType = type;
3496 return mForceLabelsInsideClipPath;
3501 if ( forceInside == mForceLabelsInsideClipPath )
3504 mForceLabelsInsideClipPath = forceInside;
3510 QDomElement settingsElem = document.createElement( u
"itemClippingSettings"_s );
3511 settingsElem.setAttribute( u
"enabled"_s, mEnabled ? u
"1"_s : u
"0"_s );
3512 settingsElem.setAttribute( u
"forceLabelsInside"_s, mForceLabelsInsideClipPath ? u
"1"_s : u
"0"_s );
3513 settingsElem.setAttribute( u
"clippingType"_s, QString::number(
static_cast<int>( mFeatureClippingType ) ) );
3514 if ( mClipPathSource )
3515 settingsElem.setAttribute( u
"clipSource"_s, mClipPathSource->uuid() );
3517 settingsElem.setAttribute( u
"clipSource"_s, QString() );
3519 element.appendChild( settingsElem );
3525 const QDomElement settingsElem = element.firstChildElement( u
"itemClippingSettings"_s );
3527 mEnabled = settingsElem.attribute( u
"enabled"_s, u
"0"_s ).toInt();
3528 mForceLabelsInsideClipPath = settingsElem.attribute( u
"forceLabelsInside"_s, u
"0"_s ).toInt();
3530 mClipPathUuid = settingsElem.attribute( u
"clipSource"_s );
3537 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.