37 #include <QStyleOptionGraphicsItem> 42 mBackgroundUpdateTimer =
new QTimer(
this );
43 mBackgroundUpdateTimer->setSingleShot(
true );
44 connect( mBackgroundUpdateTimer, &QTimer::timeout,
this, &QgsLayoutItemMap::recreateCachedImageInBackground );
48 setCacheMode( QGraphicsItem::NoCache );
55 mGridStack = qgis::make_unique< QgsLayoutItemMapGridStack >( this );
56 mOverviewStack = qgis::make_unique< QgsLayoutItemMapOverviewStack >( this );
67 mPainterJob->cancel();
92 QList<QgsLayoutItemMap *> mapsList;
93 mLayout->layoutItems( mapsList );
102 if ( map->mMapId == mMapId )
105 maxId = std::max( maxId, map->mMapId );
110 mLayout->itemsModel()->updateItemDisplayName(
this );
122 return tr(
"Map %1" ).arg( mMapId );
134 mCachedLayerStyleOverridesPresetName.clear();
138 updateAtlasFeature();
143 if ( rect().isEmpty() )
148 calculator.
setDpi( 25.4 );
155 double currentScaleDenominator =
scale();
162 double scaleRatio = scaleDenominator / currentScaleDenominator;
163 mExtent.
scale( scaleRatio );
165 if ( mAtlasDriven && mAtlasScalingMode ==
Fixed )
172 calculator.
setDpi( 25.4 );
173 scaleRatio = scaleDenominator / calculator.
calculate( mExtent, rect().width() );
174 mExtent.
scale( scaleRatio );
188 if ( mExtent == extent )
198 QRectF currentRect = rect();
200 double newHeight = currentRect.width() * mExtent.
height() / mExtent.
width();
212 double currentWidthHeightRatio = 1.0;
213 if ( !currentExtent.
isNull() )
214 currentWidthHeightRatio = currentExtent.
width() / currentExtent.
height();
216 currentWidthHeightRatio = rect().width() / rect().height();
217 double newWidthHeightRatio = newExtent.
width() / newExtent.
height();
219 if ( currentWidthHeightRatio < newWidthHeightRatio )
222 double newHeight = newExtent.
width() / currentWidthHeightRatio;
223 double deltaHeight = newHeight - newExtent.
height();
230 double newWidth = currentWidthHeightRatio * newExtent.
height();
231 double deltaWidth = newWidth - newExtent.
width();
236 if ( mExtent == newExtent )
258 mapPolygon( mExtent, poly );
267 return mLayout->project()->crs();
278 return _qgis_listRefToRaw( mLayers );
283 mLayers = _qgis_listRawToRef( layers );
288 if ( overrides == mLayerStyleOverrides )
291 mLayerStyleOverrides = overrides;
298 mLayerStyleOverrides.clear();
299 for (
const QgsMapLayerRef &layerRef : qgis::as_const( mLayers ) )
305 mLayerStyleOverrides.insert( layer->id(), style.
xmlData() );
312 mLastRenderedImageOffsetX -= dx;
313 mLastRenderedImageOffsetY -= dy;
316 transformShift( dx, dy );
340 double mapY = mExtent.
yMinimum() + ( 1 - ( point.y() / rect().height() ) ) * ( mExtent.
yMaximum() - mExtent.
yMinimum() );
346 centerX = mapX + ( centerX - mapX ) * ( 1.0 / factor );
347 centerY = mapY + ( centerY - mapY ) * ( 1.0 / factor );
349 double newIntervalX, newIntervalY;
366 if ( mAtlasDriven && mAtlasScalingMode ==
Fixed )
373 calculator.
setDpi( 25.4 );
374 double scaleRatio =
scale() / calculator.
calculate( mExtent, rect().width() );
375 mExtent.
scale( scaleRatio );
391 if ( layer->dataProvider() && layer->dataProvider()->name() == QLatin1String(
"wms" ) )
427 if ( mOverviewStack->containsAdvancedEffects() )
433 if ( mGridStack->containsAdvancedEffects() )
445 mMapRotation = rotation;
446 mEvaluatedMapRotation = mMapRotation;
460 mAtlasDriven = enabled;
477 double margin = mAtlasMargin;
485 margin = ddMargin / 100;
497 if ( mGridStack->size() < 1 )
500 mGridStack->addGrid( grid );
502 return mGridStack->grid( 0 );
507 if ( mOverviewStack->size() < 1 )
510 mOverviewStack->addOverview( overview );
512 return mOverviewStack->overview( 0 );
523 mapElem.setAttribute( QStringLiteral(
"keepLayerSet" ), QStringLiteral(
"true" ) );
527 mapElem.setAttribute( QStringLiteral(
"keepLayerSet" ), QStringLiteral(
"false" ) );
530 if ( mDrawAnnotations )
532 mapElem.setAttribute( QStringLiteral(
"drawCanvasItems" ), QStringLiteral(
"true" ) );
536 mapElem.setAttribute( QStringLiteral(
"drawCanvasItems" ), QStringLiteral(
"false" ) );
540 QDomElement extentElem = doc.createElement( QStringLiteral(
"Extent" ) );
545 mapElem.appendChild( extentElem );
549 QDomElement crsElem = doc.createElement( QStringLiteral(
"crs" ) );
551 mapElem.appendChild( crsElem );
555 mapElem.setAttribute( QStringLiteral(
"followPreset" ), mFollowVisibilityPreset ? QStringLiteral(
"true" ) : QStringLiteral(
"false" ) );
556 mapElem.setAttribute( QStringLiteral(
"followPresetName" ), mFollowVisibilityPresetName );
559 mapElem.setAttribute( QStringLiteral(
"mapRotation" ), QString::number( mMapRotation ) );
562 QDomElement layerSetElem = doc.createElement( QStringLiteral(
"LayerSet" ) );
567 QDomElement layerElem = doc.createElement( QStringLiteral(
"Layer" ) );
568 QDomText layerIdText = doc.createTextNode( layerRef.layerId );
569 layerElem.appendChild( layerIdText );
571 layerElem.setAttribute( QStringLiteral(
"name" ), layerRef.name );
572 layerElem.setAttribute( QStringLiteral(
"source" ), layerRef.source );
573 layerElem.setAttribute( QStringLiteral(
"provider" ), layerRef.provider );
575 layerSetElem.appendChild( layerElem );
577 mapElem.appendChild( layerSetElem );
580 if ( mKeepLayerStyles )
582 QDomElement stylesElem = doc.createElement( QStringLiteral(
"LayerStyles" ) );
583 for (
auto styleIt = mLayerStyleOverrides.constBegin(); styleIt != mLayerStyleOverrides.constEnd(); ++styleIt )
585 QDomElement styleElem = doc.createElement( QStringLiteral(
"LayerStyle" ) );
590 styleElem.setAttribute( QStringLiteral(
"layerid" ), ref.layerId );
591 styleElem.setAttribute( QStringLiteral(
"name" ), ref.name );
592 styleElem.setAttribute( QStringLiteral(
"source" ), ref.source );
593 styleElem.setAttribute( QStringLiteral(
"provider" ), ref.provider );
597 stylesElem.appendChild( styleElem );
599 mapElem.appendChild( stylesElem );
603 mGridStack->writeXml( mapElem, doc, context );
606 mOverviewStack->writeXml( mapElem, doc, context );
609 QDomElement atlasElem = doc.createElement( QStringLiteral(
"AtlasMap" ) );
610 atlasElem.setAttribute( QStringLiteral(
"atlasDriven" ), mAtlasDriven );
611 atlasElem.setAttribute( QStringLiteral(
"scalingMode" ), mAtlasScalingMode );
612 atlasElem.setAttribute( QStringLiteral(
"margin" ),
qgsDoubleToString( mAtlasMargin ) );
613 mapElem.appendChild( atlasElem );
615 mapElem.setAttribute( QStringLiteral(
"labelMargin" ), mLabelMargin.
encodeMeasurement() );
616 mapElem.setAttribute( QStringLiteral(
"mapFlags" ), static_cast< int>( mMapFlags ) );
618 QDomElement labelBlockingItemsElem = doc.createElement( QStringLiteral(
"labelBlockingItems" ) );
619 for (
const auto &item : qgis::as_const( mBlockingLabelItems ) )
624 QDomElement blockingItemElem = doc.createElement( QStringLiteral(
"item" ) );
625 blockingItemElem.setAttribute( QStringLiteral(
"uuid" ), item->uuid() );
626 labelBlockingItemsElem.appendChild( blockingItemElem );
628 mapElem.appendChild( labelBlockingItemsElem );
635 mUpdatesEnabled =
false;
638 QDomNodeList extentNodeList = itemElem.elementsByTagName( QStringLiteral(
"Extent" ) );
639 if ( !extentNodeList.isEmpty() )
641 QDomElement extentElem = extentNodeList.at( 0 ).toElement();
642 double xmin, xmax, ymin, ymax;
643 xmin = extentElem.attribute( QStringLiteral(
"xmin" ) ).toDouble();
644 xmax = extentElem.attribute( QStringLiteral(
"xmax" ) ).toDouble();
645 ymin = extentElem.attribute( QStringLiteral(
"ymin" ) ).toDouble();
646 ymax = extentElem.attribute( QStringLiteral(
"ymax" ) ).toDouble();
650 QDomNodeList crsNodeList = itemElem.elementsByTagName( QStringLiteral(
"crs" ) );
651 if ( !crsNodeList.isEmpty() )
653 QDomElement crsElem = crsNodeList.at( 0 ).toElement();
662 mMapRotation = itemElem.attribute( QStringLiteral(
"mapRotation" ), QStringLiteral(
"0" ) ).toDouble();
665 mFollowVisibilityPreset = itemElem.attribute( QStringLiteral(
"followPreset" ) ).compare( QLatin1String(
"true" ) ) == 0;
666 mFollowVisibilityPresetName = itemElem.attribute( QStringLiteral(
"followPresetName" ) );
669 QString keepLayerSetFlag = itemElem.attribute( QStringLiteral(
"keepLayerSet" ) );
670 if ( keepLayerSetFlag.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
672 mKeepLayerSet =
true;
676 mKeepLayerSet =
false;
679 QString drawCanvasItemsFlag = itemElem.attribute( QStringLiteral(
"drawCanvasItems" ), QStringLiteral(
"true" ) );
680 if ( drawCanvasItemsFlag.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
682 mDrawAnnotations =
true;
686 mDrawAnnotations =
false;
689 mLayerStyleOverrides.clear();
693 QDomNodeList layerSetNodeList = itemElem.elementsByTagName( QStringLiteral(
"LayerSet" ) );
694 if ( !layerSetNodeList.isEmpty() )
696 QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
697 QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( QStringLiteral(
"Layer" ) );
698 mLayers.reserve( layerIdNodeList.size() );
699 for (
int i = 0; i < layerIdNodeList.size(); ++i )
701 QDomElement layerElem = layerIdNodeList.at( i ).toElement();
702 QString layerId = layerElem.text();
703 QString layerName = layerElem.attribute( QStringLiteral(
"name" ) );
704 QString layerSource = layerElem.attribute( QStringLiteral(
"source" ) );
705 QString layerProvider = layerElem.attribute( QStringLiteral(
"provider" ) );
707 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
714 QDomNodeList layerStylesNodeList = itemElem.elementsByTagName( QStringLiteral(
"LayerStyles" ) );
715 mKeepLayerStyles = !layerStylesNodeList.isEmpty();
716 if ( mKeepLayerStyles )
718 QDomElement layerStylesElem = layerStylesNodeList.at( 0 ).toElement();
719 QDomNodeList layerStyleNodeList = layerStylesElem.elementsByTagName( QStringLiteral(
"LayerStyle" ) );
720 for (
int i = 0; i < layerStyleNodeList.size(); ++i )
722 const QDomElement &layerStyleElement = layerStyleNodeList.at( i ).toElement();
723 QString layerId = layerStyleElement.attribute( QStringLiteral(
"layerid" ) );
724 QString layerName = layerStyleElement.attribute( QStringLiteral(
"name" ) );
725 QString layerSource = layerStyleElement.attribute( QStringLiteral(
"source" ) );
726 QString layerProvider = layerStyleElement.attribute( QStringLiteral(
"provider" ) );
727 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
731 style.
readXml( layerStyleElement );
737 mNumCachedLayers = 0;
738 mCacheInvalidated =
true;
741 mOverviewStack->readXml( itemElem, doc, context );
744 mGridStack->readXml( itemElem, doc, context );
747 QDomNodeList atlasNodeList = itemElem.elementsByTagName( QStringLiteral(
"AtlasMap" ) );
748 if ( !atlasNodeList.isEmpty() )
750 QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
751 mAtlasDriven = ( atlasElem.attribute( QStringLiteral(
"atlasDriven" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
752 if ( atlasElem.hasAttribute( QStringLiteral(
"fixedScale" ) ) )
754 mAtlasScalingMode = ( atlasElem.attribute( QStringLiteral(
"fixedScale" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) ) ?
Fixed :
Auto;
756 else if ( atlasElem.hasAttribute( QStringLiteral(
"scalingMode" ) ) )
758 mAtlasScalingMode =
static_cast<AtlasScalingMode>( atlasElem.attribute( QStringLiteral(
"scalingMode" ) ).toInt() );
760 mAtlasMargin = atlasElem.attribute( QStringLiteral(
"margin" ), QStringLiteral(
"0.1" ) ).toDouble();
765 mMapFlags =
static_cast< MapItemFlags
>( itemElem.attribute( QStringLiteral(
"mapFlags" ),
nullptr ).toInt() );
768 mBlockingLabelItems.clear();
769 mBlockingLabelItemUuids.clear();
770 QDomNodeList labelBlockingNodeList = itemElem.elementsByTagName( QStringLiteral(
"labelBlockingItems" ) );
771 if ( !labelBlockingNodeList.isEmpty() )
773 QDomElement blockingItems = labelBlockingNodeList.at( 0 ).toElement();
774 QDomNodeList labelBlockingNodeList = blockingItems.childNodes();
775 for (
int i = 0; i < labelBlockingNodeList.size(); ++i )
777 const QDomElement &itemBlockingElement = labelBlockingNodeList.at( i ).toElement();
778 const QString itemUuid = itemBlockingElement.attribute( QStringLiteral(
"uuid" ) );
779 mBlockingLabelItemUuids << itemUuid;
785 mUpdatesEnabled =
true;
791 if ( !
mLayout || !painter || !painter->device() || !mUpdatesEnabled )
800 QRectF thisPaintRect = rect();
806 if (
mLayout->renderContext().isPreviewRender() )
809 painter->setClipRect( thisPaintRect );
810 if ( !mCacheFinalImage || mCacheFinalImage->isNull() )
813 painter->setBrush( QBrush( QColor( 125, 125, 125, 125 ) ) );
814 painter->drawRect( thisPaintRect );
815 painter->setBrush( Qt::NoBrush );
817 messageFont.setPointSize( 12 );
818 painter->setFont( messageFont );
819 painter->setPen( QColor( 255, 255, 255, 255 ) );
820 painter->drawText( thisPaintRect, Qt::AlignCenter | Qt::AlignHCenter, tr(
"Rendering map" ) );
821 if ( mPainterJob && mCacheInvalidated && !mDrawingPreview )
825 mBackgroundUpdateTimer->start( 1 );
827 else if ( !mPainterJob && !mDrawingPreview )
831 mBackgroundUpdateTimer->start( 1 );
836 if ( mCacheInvalidated && !mDrawingPreview )
840 mBackgroundUpdateTimer->start( 1 );
845 double imagePixelWidth = mCacheFinalImage->width();
846 double scale = rect().width() / imagePixelWidth;
850 painter->translate( mLastRenderedImageOffsetX + mXOffset, mLastRenderedImageOffsetY + mYOffset );
851 painter->scale( scale, scale );
852 painter->drawImage( 0, 0, *mCacheFinalImage );
858 painter->setClipRect( thisPaintRect, Qt::NoClip );
860 if ( shouldDrawPart( OverviewMapExtent ) )
862 mOverviewStack->drawItems( painter,
false );
864 if ( shouldDrawPart( Grid ) )
866 mGridStack->drawItems( painter );
869 if ( shouldDrawPart( Frame ) )
871 drawMapFrame( painter );
881 QPaintDevice *paintDevice = painter->device();
893 int widthInPixels =
static_cast< int >( std::round(
boundingRect().width() * layoutUnitsInInches * destinationDpi ) );
894 int heightInPixels =
static_cast< int >( std::round(
boundingRect().height() * layoutUnitsInInches * destinationDpi ) );
895 QImage image = QImage( widthInPixels, heightInPixels, QImage::Format_ARGB32 );
897 image.fill( Qt::transparent );
898 image.setDotsPerMeterX( static_cast< int >( std::round( 1000 * destinationDpi / 25.4 ) ) );
899 image.setDotsPerMeterY( static_cast< int >( std::round( 1000 * destinationDpi / 25.4 ) ) );
900 double dotsPerMM = destinationDpi / 25.4;
901 QPainter p( &image );
904 QRect imagePaintRect( static_cast< int >( std::round( tl.x() * dotsPerMM ) ),
905 static_cast< int >( std::round( tl.y() * dotsPerMM ) ),
906 static_cast< int >( std::round( thisPaintRect.width() * dotsPerMM ) ),
907 static_cast< int >( std::round( thisPaintRect.height() * dotsPerMM ) ) );
908 p.setClipRect( imagePaintRect );
910 p.translate( imagePaintRect.topLeft() );
914 if ( shouldDrawPart( Background ) )
916 p.scale( dotsPerMM, dotsPerMM );
917 drawMapBackground( &p );
918 p.scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
921 drawMap( &p, cExtent, imagePaintRect.size(), image.logicalDpiX() );
926 p.scale( dotsPerMM, dotsPerMM );
928 if ( shouldDrawPart( OverviewMapExtent ) )
930 mOverviewStack->drawItems( &p,
false );
932 if ( shouldDrawPart( Grid ) )
934 mGridStack->drawItems( &p );
939 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
940 painter->drawImage( QPointF( -tl.x()* dotsPerMM, -tl.y() * dotsPerMM ), image );
941 painter->scale( dotsPerMM, dotsPerMM );
947 if ( shouldDrawPart( Background ) )
949 drawMapBackground( painter );
953 painter->setClipRect( thisPaintRect );
955 painter->translate( mXOffset, mYOffset );
957 double dotsPerMM = paintDevice->logicalDpiX() / 25.4;
959 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
960 drawMap( painter, cExtent, size, paintDevice->logicalDpiX() );
964 painter->setClipRect( thisPaintRect, Qt::NoClip );
966 if ( shouldDrawPart( OverviewMapExtent ) )
968 mOverviewStack->drawItems( painter,
false );
970 if ( shouldDrawPart( Grid ) )
972 mGridStack->drawItems( painter );
978 if ( shouldDrawPart( Frame ) )
980 drawMapFrame( painter );
1001 void QgsLayoutItemMap::drawMap( QPainter *painter,
const QgsRectangle &
extent, QSizeF size,
double dpi )
1015 if ( shouldDrawPart( OverviewMapExtent ) )
1026 mRenderingErrors = job.
errors();
1029 void QgsLayoutItemMap::recreateCachedImageInBackground()
1035 QPainter *oldPainter = mPainter.release();
1036 QImage *oldImage = mCacheRenderingImage.release();
1039 oldJob->deleteLater();
1043 oldJob->cancelWithoutBlocking();
1047 mCacheRenderingImage.reset(
nullptr );
1050 Q_ASSERT( !mPainterJob );
1051 Q_ASSERT( !mPainter );
1052 Q_ASSERT( !mCacheRenderingImage );
1058 int w =
static_cast< int >( std::round( widthLayoutUnits * mPreviewScaleFactor ) );
1059 int h =
static_cast< int >( std::round( heightLayoutUnits * mPreviewScaleFactor ) );
1062 if ( w > 5000 || h > 5000 )
1067 h =
static_cast< int>( std::round( w * heightLayoutUnits / widthLayoutUnits ) );
1072 w =
static_cast< int >( std::round( h * widthLayoutUnits / heightLayoutUnits ) );
1076 if ( w <= 0 || h <= 0 )
1079 mCacheRenderingImage.reset(
new QImage( w, h, QImage::Format_ARGB32 ) );
1082 mCacheRenderingImage->setDotsPerMeterX( static_cast< int >( std::round( 1000 * w / widthLayoutUnits ) ) );
1083 mCacheRenderingImage->setDotsPerMeterY( static_cast< int >( std::round( 1000 * h / heightLayoutUnits ) ) );
1094 mCacheRenderingImage->fill( QColor( 255, 255, 255, 0 ).rgba() );
1097 mCacheInvalidated =
false;
1098 mPainter.reset(
new QPainter( mCacheRenderingImage.get() ) );
1101 if ( shouldDrawPart( OverviewMapExtent ) )
1103 settings.
setLayers( mOverviewStack->modifyMapLayerList( settings.
layers() ) );
1108 mPainterJob->start();
1120 mDrawingPreview =
false;
1144 jobMapSettings.
setRotation( mEvaluatedMapRotation );
1148 if ( includeLayerSettings )
1152 if (
mLayout && -1 !=
mLayout->renderContext().currentExportLayer() )
1154 const int layerIdx =
mLayout->renderContext().currentExportLayer() - (
hasBackground() ? 1 : 0 );
1155 if ( layerIdx >= 0 && layerIdx < layers.length() )
1158 QgsMapLayer *ml = layers[ layers.length() - layerIdx - 1 ];
1172 if ( !
mLayout->renderContext().isPreviewRender() )
1200 if ( mEvaluatedLabelMargin.
length() > 0 )
1203 visiblePoly.append( visiblePoly.at( 0 ) );
1204 const double layoutLabelMargin =
mLayout->convertToLayoutUnits( mEvaluatedLabelMargin );
1205 const double layoutLabelMarginInMapUnits = layoutLabelMargin / rect().width() * jobMapSettings.
extent().
width();
1207 mapBoundaryGeom = mapBoundaryGeom.
buffer( -layoutLabelMarginInMapUnits, 0 );
1211 if ( !mBlockingLabelItems.isEmpty() )
1216 return jobMapSettings;
1223 mBlockingLabelItems.clear();
1224 for (
const QString &
uuid : qgis::as_const( mBlockingLabelItemUuids ) )
1233 mOverviewStack->finalizeRestoreFromXml();
1234 mGridStack->finalizeRestoreFromXml();
1245 return mCurrentRectangle;
1278 QVariantList layersIds;
1288 const QList<QgsMapLayer *> layersInMap =
layersToRender( &context );
1290 layersIds.reserve( layersInMap.count() );
1291 layers.reserve( layersInMap.count() );
1294 layersIds << layer->id();
1300 scope->
addFunction( QStringLiteral(
"is_layer_visible" ),
new QgsExpressionContextUtils::GetLayerVisibility( layersInMap ) );
1308 if ( extentWidth <= 0 )
1312 return rect().width() / extentWidth;
1317 double dx = mXOffset;
1318 double dy = mYOffset;
1319 transformShift( dx, dy );
1321 poly.translate( -dx, -dy );
1327 if ( !mBlockingLabelItems.contains( item ) )
1328 mBlockingLabelItems.append( item );
1335 mBlockingLabelItems.removeAll( item );
1342 return mBlockingLabelItems.contains( item );
1348 if ( mapPoly.empty() )
1350 return QPointF( 0, 0 );
1355 double dx = mapCoords.x() - rotationPoint.
x();
1356 double dy = mapCoords.y() - rotationPoint.
y();
1358 QgsPointXY backRotatedCoords( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
1361 double xItem = rect().width() * ( backRotatedCoords.x() - unrotatedExtent.xMinimum() ) / unrotatedExtent.width();
1362 double yItem = rect().height() * ( 1 - ( backRotatedCoords.y() - unrotatedExtent.yMinimum() ) / unrotatedExtent.height() );
1363 return QPointF( xItem, yItem );
1377 mapPolygon( newExtent, poly );
1378 QRectF bRect = poly.boundingRect();
1392 mCacheInvalidated =
true;
1398 QRectF rectangle = rect();
1399 double frameExtension =
frameEnabled() ? pen().widthF() / 2.0 : 0.0;
1401 double topExtension = 0.0;
1402 double rightExtension = 0.0;
1403 double bottomExtension = 0.0;
1404 double leftExtension = 0.0;
1407 mGridStack->calculateMaxGridExtension( topExtension, rightExtension, bottomExtension, leftExtension );
1409 topExtension = std::max( topExtension, frameExtension );
1410 rightExtension = std::max( rightExtension, frameExtension );
1411 bottomExtension = std::max( bottomExtension, frameExtension );
1412 leftExtension = std::max( leftExtension, frameExtension );
1414 rectangle.setLeft( rectangle.left() - leftExtension );
1415 rectangle.setRight( rectangle.right() + rightExtension );
1416 rectangle.setTop( rectangle.top() - topExtension );
1417 rectangle.setBottom( rectangle.bottom() + bottomExtension );
1418 if ( rectangle != mCurrentRectangle )
1420 prepareGeometryChange();
1421 mCurrentRectangle = rectangle;
1437 refreshMapExtents( &context );
1439 if ( mExtent != beforeExtent )
1446 refreshLabelMargin(
false );
1450 mCacheInvalidated =
true;
1455 void QgsLayoutItemMap::layersAboutToBeRemoved(
const QList<QgsMapLayer *> &
layers )
1457 if ( !mLayers.isEmpty() || mLayerStyleOverrides.isEmpty() )
1461 mLayerStyleOverrides.remove( layer->id() );
1463 _qgis_removeLayers( mLayers, layers );
1467 void QgsLayoutItemMap::painterJobFinished()
1470 mPainterJob.reset(
nullptr );
1471 mPainter.reset(
nullptr );
1472 mCacheFinalImage = std::move( mCacheRenderingImage );
1473 mLastRenderedImageOffsetX = 0;
1474 mLastRenderedImageOffsetY = 0;
1478 void QgsLayoutItemMap::shapeChanged()
1483 double w = rect().width();
1484 double h = rect().height();
1487 double newWidth = mExtent.
width();
1489 double newHeight = newWidth * h / w;
1494 refreshMapExtents();
1501 void QgsLayoutItemMap::mapThemeChanged(
const QString &theme )
1503 if ( theme == mCachedLayerStyleOverridesPresetName )
1504 mCachedLayerStyleOverridesPresetName.clear();
1507 void QgsLayoutItemMap::connectUpdateSlot()
1515 this, &QgsLayoutItemMap::layersAboutToBeRemoved );
1519 if (
layers().isEmpty() )
1546 QTransform QgsLayoutItemMap::layoutToMapCoordsTransform()
const 1549 QTransform mapTransform;
1550 QPolygonF thisRectPoly = QPolygonF( QRectF( 0, 0, rect().width(), rect().height() ) );
1552 thisRectPoly.pop_back();
1553 thisExtent.pop_back();
1555 QPolygonF thisItemPolyInLayout = mapToScene( thisRectPoly );
1558 QTransform::quadToQuad( thisItemPolyInLayout, thisExtent, mapTransform );
1559 return mapTransform;
1562 QList<QgsLabelBlockingRegion> QgsLayoutItemMap::createLabelBlockingRegions(
const QgsMapSettings & )
const 1564 const QTransform mapTransform = layoutToMapCoordsTransform();
1565 QList< QgsLabelBlockingRegion > blockers;
1566 blockers.reserve( mBlockingLabelItems.count() );
1567 for (
const auto &item : qgis::as_const( mBlockingLabelItems ) )
1569 if ( !item || !item->isVisible() )
1572 QPolygonF itemRectInMapCoordinates = mapTransform.map( item->mapToScene( item->rect() ) );
1573 itemRectInMapCoordinates.append( itemRectInMapCoordinates.at( 0 ) );
1582 return mLabelMargin;
1587 mLabelMargin = margin;
1588 refreshLabelMargin(
false );
1591 void QgsLayoutItemMap::updateToolTip()
1603 QList<QgsMapLayer *> renderLayers;
1605 if ( mFollowVisibilityPreset )
1607 QString presetName = mFollowVisibilityPresetName;
1612 if (
mLayout->project()->mapThemeCollection()->hasMapTheme( presetName ) )
1613 renderLayers =
mLayout->project()->mapThemeCollection()->mapThemeVisibleLayers( presetName );
1615 renderLayers =
mLayout->project()->mapThemeCollection()->masterVisibleLayers();
1617 else if ( !
layers().isEmpty() )
1623 renderLayers =
mLayout->project()->mapThemeCollection()->masterVisibleLayers();
1630 renderLayers.clear();
1632 const QStringList layerNames = ddLayers.split(
'|' );
1634 for (
const QString &name : layerNames )
1636 const QList< QgsMapLayer * > matchingLayers =
mLayout->project()->mapLayersByName( name );
1639 renderLayers << layer;
1648 int removeAt = renderLayers.indexOf(
mLayout->reportContext().layer() );
1649 if ( removeAt != -1 )
1651 renderLayers.removeAt( removeAt );
1655 return renderLayers;
1658 QMap<QString, QString> QgsLayoutItemMap::layerStyleOverridesToRender(
const QgsExpressionContext &context )
const 1660 if ( mFollowVisibilityPreset )
1662 QString presetName = mFollowVisibilityPresetName;
1667 if (
mLayout->project()->mapThemeCollection()->hasMapTheme( presetName ) )
1669 if ( presetName.isEmpty() || presetName != mCachedLayerStyleOverridesPresetName )
1672 mCachedPresetLayerStyleOverrides =
mLayout->project()->mapThemeCollection()->mapThemeStyleOverrides( presetName );
1673 mCachedLayerStyleOverridesPresetName = presetName;
1676 return mCachedPresetLayerStyleOverrides;
1679 return QMap<QString, QString>();
1681 else if ( mKeepLayerStyles )
1683 return mLayerStyleOverrides;
1687 return QMap<QString, QString>();
1691 QgsRectangle QgsLayoutItemMap::transformedExtent()
const 1693 double dx = mXOffset;
1694 double dy = mYOffset;
1695 transformShift( dx, dy );
1699 void QgsLayoutItemMap::mapPolygon(
const QgsRectangle &extent, QPolygonF &poly )
const 1709 poly << QPointF( poly.at( 0 ) );
1718 dx = rotationPoint.
x() - extent.
xMinimum();
1719 dy = rotationPoint.
y() - extent.
yMaximum();
1721 poly << QPointF( rotationPoint.
x() - dx, rotationPoint.
y() - dy );
1724 dx = rotationPoint.
x() - extent.
xMaximum();
1725 dy = rotationPoint.
y() - extent.
yMaximum();
1727 poly << QPointF( rotationPoint.
x() - dx, rotationPoint.
y() - dy );
1730 dx = rotationPoint.
x() - extent.
xMaximum();
1731 dy = rotationPoint.
y() - extent.
yMinimum();
1733 poly << QPointF( rotationPoint.
x() - dx, rotationPoint.
y() - dy );
1736 dx = rotationPoint.
x() - extent.
xMinimum();
1737 dy = rotationPoint.
y() - extent.
yMinimum();
1739 poly << QPointF( rotationPoint.
x() - dx, rotationPoint.
y() - dy );
1742 poly << QPointF( poly.at( 0 ) );
1745 void QgsLayoutItemMap::transformShift(
double &xShift,
double &yShift )
const 1748 double dxScaled = xShift * mmToMapUnits;
1749 double dyScaled = - yShift * mmToMapUnits;
1764 const QList< QgsAnnotation * > annotations =
mLayout->project()->annotationManager()->annotations();
1765 if ( annotations.isEmpty() )
1775 if ( !annotation || !annotation->isVisible() )
1779 if ( annotation->mapLayer() && !layers.contains( annotation->mapLayer() ) )
1782 drawAnnotation( annotation, rc );
1796 double itemX, itemY;
1799 QPointF mapPos = layoutMapPosForItem( annotation );
1808 context.
painter()->translate( itemX, itemY );
1811 double dotsPerMM = context.
painter()->device()->logicalDpiX() / 25.4;
1812 context.
painter()->scale( 1 / dotsPerMM, 1 / dotsPerMM );
1814 annotation->
render( context );
1818 QPointF QgsLayoutItemMap::layoutMapPosForItem(
const QgsAnnotation *annotation )
const 1821 return QPointF( 0, 0 );
1830 if ( annotationCrs !=
crs() )
1847 void QgsLayoutItemMap::drawMapFrame( QPainter *p )
1853 p->setBrush( Qt::NoBrush );
1854 p->setRenderHint( QPainter::Antialiasing,
true );
1855 p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
1860 void QgsLayoutItemMap::drawMapBackground( QPainter *p )
1865 p->setBrush( brush() );
1866 p->setPen( Qt::NoPen );
1867 p->setRenderHint( QPainter::Antialiasing,
true );
1868 p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
1873 bool QgsLayoutItemMap::shouldDrawPart( QgsLayoutItemMap::PartType part )
const 1875 int currentExportLayer =
mLayout->renderContext().currentExportLayer();
1877 if ( -1 == currentExportLayer )
1887 if ( SelectionBoxes == part )
1889 return currentExportLayer == idx;
1896 if ( Frame == part )
1898 return currentExportLayer == idx;
1902 if ( OverviewMapExtent == part )
1904 return currentExportLayer == idx;
1909 return currentExportLayer == idx;
1913 if ( Background == part )
1915 return currentExportLayer == 0;
1931 bool useDdXMin =
false;
1932 bool useDdXMax =
false;
1933 bool useDdYMin =
false;
1934 bool useDdYMax =
false;
1966 if ( newExtent != mExtent )
1972 double currentWidthHeightRatio = mExtent.
width() / mExtent.
height();
1973 double newWidthHeightRatio = newExtent.
width() / newExtent.
height();
1975 if ( currentWidthHeightRatio < newWidthHeightRatio )
1978 double newHeight = newExtent.
width() / currentWidthHeightRatio;
1979 double deltaHeight = newHeight - newExtent.
height();
1986 double newWidth = currentWidthHeightRatio * newExtent.
height();
1987 double deltaWidth = newWidth - newExtent.
width();
1992 mExtent = newExtent;
2002 newExtent = mExtent;
2005 if ( useDdXMax || useDdXMin || useDdYMax || useDdYMin )
2009 if ( useDdXMin && !useDdXMax )
2015 else if ( !useDdXMin && useDdXMax )
2021 if ( useDdYMin && !useDdYMax )
2027 else if ( !useDdYMin && useDdYMax )
2034 if ( newExtent != mExtent )
2036 mExtent = newExtent;
2053 void QgsLayoutItemMap::refreshLabelMargin(
bool updateItem )
2057 mEvaluatedLabelMargin.
setLength( labelMargin );
2066 void QgsLayoutItemMap::updateAtlasFeature()
2085 if ( mAtlasScalingMode ==
Fixed || mAtlasScalingMode ==
Predefined || isPointLayer )
2090 double originalScale = calc.
calculate( originalExtent, rect().width() );
2091 double geomCenterX = ( xa1 + xa2 ) / 2.0;
2092 double geomCenterY = ( ya1 + ya2 ) / 2.0;
2094 if ( mAtlasScalingMode ==
Fixed || isPointLayer )
2097 double xMin = geomCenterX - originalExtent.
width() / 2.0;
2098 double yMin = geomCenterY - originalExtent.
height() / 2.0;
2101 xMin + originalExtent.
width(),
2102 yMin + originalExtent.
height() );
2106 double newScale = calc.
calculate( newExtent, rect().width() );
2107 newExtent.
scale( originalScale / newScale );
2112 double newWidth = originalExtent.
width();
2113 double newHeight = originalExtent.
height();
2114 QVector<qreal> scales =
mLayout->reportContext().predefinedScales();
2115 for (
int i = 0; i < scales.size(); i++ )
2117 double ratio = scales[i] / originalScale;
2118 newWidth = originalExtent.
width() * ratio;
2119 newHeight = originalExtent.
height() * ratio;
2122 double xMin = geomCenterX - newWidth / 2.0;
2123 double yMin = geomCenterY - newHeight / 2.0;
2131 double newScale = calc.
calculate( newExtent, rect().width() );
2132 newExtent.
scale( scales[i] / newScale );
2142 else if ( mAtlasScalingMode ==
Auto )
2146 double geomRatio = bounds.
width() / bounds.
height();
2147 double mapRatio = originalExtent.
width() / originalExtent.
height();
2150 if ( geomRatio < mapRatio )
2153 double adjWidth = ( mapRatio * bounds.
height() - bounds.
width() ) / 2.0;
2158 else if ( geomRatio > mapRatio )
2161 double adjHeight = ( bounds.
width() / mapRatio - bounds.
height() ) / 2.0;
2167 const double evaluatedAtlasMargin =
atlasMargin();
2168 if ( evaluatedAtlasMargin > 0.0 )
2170 newExtent.
scale( 1 + evaluatedAtlasMargin );
2186 if ( mEvaluatedMapRotation != 0.0 )
2196 double dx = std::max( std::abs( prevCenter.
x() - bounds.
xMinimum() ),
2197 std::abs( prevCenter.
x() - bounds.
xMaximum() ) );
2198 double dy = std::max( std::abs( prevCenter.
y() - bounds.
yMinimum() ),
2199 std::abs( prevCenter.
y() - bounds.
yMaximum() ) );
2202 center.
x() + dx, center.
y() + dy );
QIcon icon() const override
Returns the item's icon.
QString displayName() const override
Gets item display name.
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
The class is used as a container of context for various read/write operations on other objects...
QgsUnitTypes::LayoutUnit units() const
Returns the units for the measurement.
static double scaleFactorFromItemStyle(const QStyleOptionGraphicsItem *style)
Extracts the scale factor from an item style.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
void finished()
emitted when asynchronous rendering is finished (or canceled).
Single variable definition for use within a QgsExpressionContextScope.
void addLabelBlockingItem(QgsLayoutItem *item)
Sets the specified layout item as a "label blocking item" for this map.
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
A rectangle specified with double values.
Base class for all map layer types.
void setExtent(const QgsRectangle &rect, bool magnified=true)
Set coordinates of the rectangle which should be rendered.
Job implementation that renders everything sequentially using a custom painter.
bool isVisible() const
Returns true if the annotation is visible and should be rendered.
QPointF mapToItemCoords(QPointF mapCoords) const
Transforms map coordinates to item coordinates (considering rotation and move offset) ...
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
bool containsAdvancedEffects() const override
Returns true if the item contains contents with blend modes or transparency effects which can only be...
Base class for graphical items within a QgsLayout.
double calculate(const QgsRectangle &mapExtent, double canvasWidth)
Calculate the scale denominator.
An individual overview which is drawn above the map content in a QgsLayoutItemMap, and shows the extent of another QgsLayoutItemMap.
virtual bool containsAdvancedEffects() const
Returns true if the item contains contents with blend modes or transparency effects which can only be...
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
QgsLayoutItemMap(QgsLayout *layout)
Constructor for QgsLayoutItemMap, with the specified parent layout.
void moveContent(double dx, double dy) override
Moves the content of the item, by a specified dx and dy in layout units.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double...
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
void setXMaximum(double x)
Set the maximum x value.
int type() const override
Use antialiasing while drawing.
QString xmlData() const
Returns XML content of the style.
void readXml(const QDomElement &styleElement)
Read style configuration (for project file reading)
void addFunction(const QString &name, QgsScopedExpressionFunction *function)
Adds a function to the scope.
Layer and style map theme.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
void setExtent(const QgsRectangle &extent)
Sets a new extent for the map.
void layerOrderChanged()
Emitted when the layer order has changed.
A class to represent a 2D point.
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
QgsMapSettings mapSettings(const QgsRectangle &extent, QSizeF size, double dpi, bool includeLayerSettings) const
Returns map settings that will be used for drawing of the map.
void extentChanged()
Emitted when the map's extent changes.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
OperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
static QgsLayoutItemMap * create(QgsLayout *layout)
Returns a new map item for the specified layout.
Whether to use also label candidates that are partially outside of the map view.
bool frameEnabled() const
Returns true if the item includes a frame.
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
TYPE * resolveWeakly(const QgsProject *project)
Resolves the map layer by attempting to find a matching layer in a project using a weak match...
void setOutputDpi(double dpi)
Sets DPI used for conversion between real world units (e.g. mm) and pixels.
QString toProj4() const
Returns a Proj4 string representation of this CRS.
void crsChanged()
Emitted when the CRS of the project has changed.
void setDpi(double dpi)
Sets the dpi (dots per inch) for the output resolution, to be used in scale calculations.
Errors errors() const
List of errors that happened during the rendering job - available when the rendering has been finishe...
void zoomContent(double factor, QPointF point) override
Zooms content of item.
A geometry is the spatial representation of a feature.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
virtual void setFrameStrokeWidth(QgsLayoutMeasurement width)
Sets the frame stroke width.
static const QStringList containsAdvancedEffects(const QgsMapSettings &mapSettings)
Checks whether any of the layers attached to a map settings object contain advanced effects...
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...
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
bool drawAnnotations() const
Returns whether annotations are drawn within the map.
Flags flags() const
Returns combination of flags used for rendering.
QgsUnitTypes::DistanceUnit mapUnits
void invalidateCache() override
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Set map of map layer style overrides (key: layer ID, value: style name) where a different style shoul...
void preparedForAtlas()
Emitted when the map has been prepared for atlas rendering, just before actual rendering.
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Enable layer opacity and blending effects.
QPolygonF transformedMapPolygon() const
Returns extent that considers rotation and shift with mOffsetX / mOffsetY.
friend class QgsLayoutItemMapOverview
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
QPointF relativePosition() const
Returns the relative position of the annotation, if it is not attached to a fixed map position...
Vector graphics should not be cached and drawn as raster images.
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
Abstract base class for annotation items which are drawn over a map.
void setFrameStrokeWidth(QgsLayoutMeasurement width) override
Sets the frame stroke width.
The QgsMapSettings class contains configuration for rendering of the map.
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
void readFromLayer(QgsMapLayer *layer)
Store layer's active style information in the instance.
void storeCurrentLayerStyles()
Stores the current project layer styles into style overrides.
void sizePositionChanged()
Emitted when the item's size or position changes.
Stores style information (renderer, opacity, labeling, diagrams etc.) applicable to a map layer...
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
void mapThemeChanged(const QString &theme)
Emitted when a map theme changes definition.
static QgsRectangle fromCenterAndSize(QgsPointXY center, double width, double height)
Creates a new rectangle, given the specified center point and width and height.
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
QString ellipsoidAcronym() const
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
QList< QgsMapLayer * > layers() const
Returns the stored layer set.
QgsRectangle extent() const
Returns the current map extent.
Layout graphical items for displaying a map.
void setOutputSize(QSize size)
Sets the size of the resulting map image.
QString layerId
Original layer ID.
QgsPropertyCollection mDataDefinedProperties
const QgsLayout * layout() const
Returns the layout the object is attached to.
void setTextRenderFormat(QgsRenderContext::TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
QgsMapThemeCollection mapThemeCollection
void setLength(const double length)
Sets the length of the measurement.
void setLayers(const QList< QgsMapLayer *> &layers)
Sets the stored layers set.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
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...
bool hasBackground() const
Returns true if the item has a background.
Whether vector selections should be shown in the rendered map.
double width() const
Returns the width of the rectangle.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
~QgsLayoutItemMap() override
void setYMinimum(double y)
Set the minimum y value.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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...
double atlasMargin(QgsLayoutObject::PropertyValueType valueType=QgsLayoutObject::EvaluatedValue)
Returns the margin size (percentage) used when the map is in atlas mode.
static QgsRenderContext createRenderContextForMap(QgsLayoutItemMap *map, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout map and painter destination.
QColor backgroundColor() const
Returns the background color for this item.
Enable anti-aliasing for map rendering.
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
void render(QgsRenderContext &context) const
Renders the annotation to a target render context.
double mapUnitsToLayoutUnits() const
Returns the conversion factor from map units to layout units.
QPointer< QgsLayout > mLayout
void setMapUnits(QgsUnitTypes::DistanceUnit mapUnits)
Set the map units.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
Hide coverage layer in outputs.
Whether to draw labels which are partially outside of the map view.
void setMoveContentPreviewOffset(double dx, double dy) override
Sets temporary offset for the item, by a specified dx and dy in layout units.
Reads and writes project states.
void setLabelBoundaryGeometry(const QgsGeometry &boundary)
Sets the label boundary geometry, which restricts where in the rendered map labels are permitted to b...
QgsLayoutItemMap::MapItemFlags mapFlags() const
Returns the map item's flags, which control how the map content is drawn.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the map's preset crs (coordinate reference system).
QString id() const
Returns the item's ID name.
QgsLayoutItem::Flags itemFlags() const override
Returns the item's flags, which indicate how the item behaves.
QgsRectangle requestedExtent() const
Calculates the extent to request and the yShift of the top-left point in case of rotation.
QList< QgsMapLayer * > layersToRender(const QgsExpressionContext *context=nullptr) const
Returns a list of the layers which will be rendered within this map item, considering any locked laye...
Label blocking region (in map coordinates and CRS).
Single scope for storing variables and functions for use within a QgsExpressionContext.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
virtual bool requiresRasterization() const
Returns true if the item is drawn in such a way that forces the whole layout to be rasterized when ex...
static void rotate(double angle, double &x, double &y)
Rotates a point / vector around the origin.
If set, then raster layers will not be drawn as separate tiles. This may improve the appearance in ex...
Enable drawing of vertex markers for layers in editing mode.
The extent is adjusted so that each feature is fully visible.
An individual grid which is drawn above the map content in a QgsLayoutItemMap.
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation...
void mapRotationChanged(double newRotation)
Emitted when the map's rotation changes.
Use antialiasing when drawing items.
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Sets the stored overrides of styles for layers.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
Contains settings and helpers relating to a render of a QgsLayoutItem.
QString projectionAcronym() const
Returns the projection acronym for the projection used by the CRS.
QgsExpressionContext & expressionContext()
Gets the expression context.
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
void setUnits(const QgsUnitTypes::LayoutUnit units)
Sets the units for the measurement.
void setAtlasDriven(bool enabled)
Sets whether the map extent will follow the current atlas feature.
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
static QgsLayoutMeasurement decodeMeasurement(const QString &string)
Decodes a measurement from a string.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a string...
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
double mapRotation(QgsLayoutObject::PropertyValueType valueType=QgsLayoutObject::EvaluatedValue) const
Returns the rotation used for drawing the map within the layout item, in degrees clockwise.
Return the current evaluated value for the property.
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets the global configuration of the labeling engine.
void setLabelMargin(const QgsLayoutMeasurement &margin)
Sets the margin from the map edges in which no labels may be placed.
QgsCoordinateReferenceSystem mapPositionCrs() const
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map po...
Contains information about the context of a rendering operation.
void removeLabelBlockingItem(QgsLayoutItem *item)
Removes the specified layout item from the map's "label blocking items".
Force output in vector format where possible, even if items require rasterization to keep their corre...
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
double length() const
Returns the length of the measurement.
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...
void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties) override
QPainter * painter()
Returns the destination QPainter for the render operation.
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the registry.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
void setSelectionColor(const QColor &color)
Sets color that is used for drawing of selected vector features.
bool containsWmsLayer() const
Returns true if the map contains a WMS layer.
void writeXml(QDomElement &styleElement) const
Write style configuration (for project file writing)
QgsLayoutItemMapOverview * overview()
Returns the map item's first overview.
Enable advanced effects such as blend modes.
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
void updateBoundingRect()
Updates the bounding rect of this item. Call this function before doing any changes related to annota...
void refreshed()
Emitted when the layout has been refreshed and items should also be refreshed and updated...
void setYMaximum(double y)
Set the maximum y value.
The current scale of the map is used for each feature of the atlas.
double scale() const
Returns the map scale.
friend class QgsLayoutItemMapGrid
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Stores global configuration for labeling engine.
virtual QString uuid() const
Returns the item identification string.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
This class represents a coordinate reference system (CRS).
QString toWkt() const
Returns a WKT representation of this CRS.
void assignFreeId()
Sets the map id() to a number not yet used in the layout.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void setLayers(const QList< QgsMapLayer *> &layers)
Set list of layers for map rendering.
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
void layerStyleOverridesChanged()
Emitted when layer style overrides are changed...
Enable vector simplification and other rendering optimizations.
Item overrides the default layout item painting method.
Custom exception class for Coordinate Reference System related exceptions.
QPolygonF visiblePolygon() const
Returns the visible area as a polygon (may be rotated)
bool atlasDriven() const
Returns whether the map extent is set to follow the current atlas feature.
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
QgsPointXY center() const
Returns the center point of the rectangle.
void zoomToExtent(const QgsRectangle &extent)
Zooms the map so that the specified extent is fully visible within the map item.
AtlasScalingMode
Scaling modes used for the serial rendering (atlas)
bool isLabelBlockingItem(QgsLayoutItem *item) const
Returns true if the specified item is a "label blocking item".
int numberExportLayers() const override
Returns the number of layers that this item requires for exporting during layered exports (e...
void setMapFlags(QgsLayoutItemMap::MapItemFlags flags)
Sets the map item's flags, which control how the map content is drawn.
QString encodeMeasurement() const
Encodes the layout measurement to a string.
TYPE * resolve(const QgsProject *project)
Resolves the map layer by attempting to find a layer with matching ID within a project.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
void changed()
Emitted when the object's properties change.
DataDefinedProperty
Data defined properties for different item types.
QgsLayoutMeasurement labelMargin() const
Returns the margin from the map edges in which no labels may be placed.
void setScale(double scale, bool forceUpdate=true)
Sets new map scale and changes only the map extent.
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
QRectF boundingRect() const override
void renderSynchronously()
Render the map synchronously in this thread.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
QString authid() const
Returns the authority identifier for the CRS.
void setXMinimum(double x)
Set the minimum x value.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
double height() const
Returns the height of the rectangle.
A scale is chosen from the predefined scales.
void setFlag(Flag f, bool enabled=true)
Sets whether a particual flag is enabled.
void setLabelBlockingRegions(const QList< QgsLabelBlockingRegion > ®ions)
Sets a list of regions to avoid placing labels within.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QgsLayoutItemMapGrid * grid()
Returns the map item's first grid.