QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgslayoutitemmapoverview.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitemmapoverview.cpp
3  --------------------
4  begin : October 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 #include "qgslayoutitemmap.h"
20 #include "qgslayout.h"
21 #include "qgssymbollayerutils.h"
22 #include "qgssymbol.h"
23 #include "qgsmapsettings.h"
24 #include "qgspainting.h"
25 #include "qgspathresolver.h"
26 #include "qgsreadwritecontext.h"
27 #include "qgslayoututils.h"
28 #include "qgsexception.h"
29 #include "qgsvectorlayer.h"
31 #include "qgsstyleentityvisitor.h"
32 #include "qgsfillsymbol.h"
33 
34 #include <QPainter>
35 
37  : QgsLayoutItemMapItem( name, map )
38  , mExtentLayer( std::make_unique< QgsVectorLayer >( QStringLiteral( "Polygon?crs=EPSG:4326" ), tr( "Overview" ), QStringLiteral( "memory" ), QgsVectorLayer::LayerOptions( map && map->layout() && map->layout()->project() ? map->layout()->project()->transformContext() : QgsCoordinateTransformContext() ) ) )
39 {
40  createDefaultFrameSymbol();
41 }
42 
44 
45 void QgsLayoutItemMapOverview::createDefaultFrameSymbol()
46 {
47  QVariantMap properties;
48  properties.insert( QStringLiteral( "color" ), QStringLiteral( "255,0,0,75" ) );
49  properties.insert( QStringLiteral( "style" ), QStringLiteral( "solid" ) );
50  properties.insert( QStringLiteral( "style_border" ), QStringLiteral( "no" ) );
51  mFrameSymbol.reset( QgsFillSymbol::createSimple( properties ) );
52 
53  mExtentLayer->setRenderer( new QgsSingleSymbolRenderer( mFrameSymbol->clone() ) );
54 }
55 
56 void QgsLayoutItemMapOverview::draw( QPainter *painter )
57 {
58  if ( !mEnabled || !mFrameMap || !mMap || !mMap->layout() )
59  {
60  return;
61  }
62  if ( !painter )
63  {
64  return;
65  }
66 
67  const QgsLayoutItemMap *overviewFrameMap = linkedMap();
68  if ( !overviewFrameMap )
69  {
70  return;
71  }
72 
73  //get polygon for other overview frame map's extent (use visibleExtentPolygon as it accounts for map rotation)
74  QPolygonF otherExtent = overviewFrameMap->visibleExtentPolygon();
75  if ( overviewFrameMap->crs() !=
76  mMap->crs() )
77  {
78  QgsGeometry g = QgsGeometry::fromQPolygonF( otherExtent );
79 
80  // reproject extent
81  QgsCoordinateTransform ct( overviewFrameMap->crs(),
82  mMap->crs(), mLayout->project() );
83  g = g.densifyByCount( 20 );
84  try
85  {
86  g.transform( ct );
87  }
88  catch ( QgsCsException & )
89  {
90  }
91 
92  otherExtent = g.asQPolygonF();
93  }
94 
95  //get current map's extent as a QPolygonF
96  QPolygonF thisExtent = mMap->visibleExtentPolygon();
97  //intersect the two
98  QPolygonF intersectExtent = thisExtent.intersected( otherExtent );
99 
100  //setup painter scaling to dots so that raster symbology is drawn to scale
101  double dotsPerMM = painter->device()->logicalDpiX() / 25.4;
102 
103  //setup render context
105  context.setForceVectorOutput( true );
106  QgsExpressionContext expressionContext = createExpressionContext();
107  context.setExpressionContext( expressionContext );
108 
109  QgsScopedQPainterState painterState( painter );
110  context.setPainterFlagsUsingContext( painter );
111 
112  painter->setCompositionMode( mBlendMode );
113  painter->translate( mMap->mXOffset, mMap->mYOffset );
114  painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
115 
116  mFrameSymbol->startRender( context );
117 
118  //construct a polygon corresponding to the intersecting map extent
119  //need to scale line to dots, rather then mm, since the painter has been scaled to dots
120  QTransform mapTransform;
121  QPolygonF thisRectPoly = QPolygonF( QRectF( 0, 0, dotsPerMM * mMap->rect().width(), dotsPerMM * mMap->rect().height() ) );
122 
123  //workaround QT Bug #21329
124  thisRectPoly.pop_back();
125  thisExtent.pop_back();
126 
127  //create transform from map coordinates to painter coordinates
128  QTransform::quadToQuad( thisExtent, thisRectPoly, mapTransform );
129  QPolygonF intersectPolygon;
130  intersectPolygon = mapTransform.map( intersectExtent );
131 
132  QVector<QPolygonF> rings; //empty list
133  if ( !mInverted )
134  {
135  //Render the intersecting map extent
136  mFrameSymbol->renderPolygon( intersectPolygon, &rings, nullptr, context );
137  }
138  else
139  {
140  //We are inverting the overview frame (ie, shading outside the intersecting extent)
141  //Construct a polygon corresponding to the overview map extent
142  QPolygonF outerPolygon;
143  outerPolygon << QPointF( 0, 0 )
144  << QPointF( mMap->rect().width() * dotsPerMM, 0 )
145  << QPointF( mMap->rect().width() * dotsPerMM, mMap->rect().height() * dotsPerMM )
146  << QPointF( 0, mMap->rect().height() * dotsPerMM )
147  << QPointF( 0, 0 );
148 
149  //Intersecting extent is an inner ring for the shaded area
150  rings.append( intersectPolygon );
151  mFrameSymbol->renderPolygon( outerPolygon, &rings, nullptr, context );
152  }
153 
154  mFrameSymbol->stopRender( context );
155 }
156 
157 bool QgsLayoutItemMapOverview::writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const
158 {
159  if ( elem.isNull() )
160  {
161  return false;
162  }
163 
164  //overview map frame
165  QDomElement overviewFrameElem = doc.createElement( QStringLiteral( "ComposerMapOverview" ) );
166 
167  overviewFrameElem.setAttribute( QStringLiteral( "frameMap" ), mFrameMap ? mFrameMap ->uuid() : QString() );
168  overviewFrameElem.setAttribute( QStringLiteral( "blendMode" ), QgsPainting::getBlendModeEnum( mBlendMode ) );
169  overviewFrameElem.setAttribute( QStringLiteral( "inverted" ), mInverted );
170  overviewFrameElem.setAttribute( QStringLiteral( "centered" ), mCentered );
171 
172  QDomElement frameStyleElem = QgsSymbolLayerUtils::saveSymbol( QString(), mFrameSymbol.get(), doc, context );
173  overviewFrameElem.appendChild( frameStyleElem );
174 
175  bool ok = QgsLayoutItemMapItem::writeXml( overviewFrameElem, doc, context );
176  elem.appendChild( overviewFrameElem );
177  return ok;
178 }
179 
180 bool QgsLayoutItemMapOverview::readXml( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context )
181 {
182  Q_UNUSED( doc )
183  if ( itemElem.isNull() )
184  {
185  return false;
186  }
187 
188  bool ok = QgsLayoutItemMapItem::readXml( itemElem, doc, context );
189 
190  mFrameMapUuid = itemElem.attribute( QStringLiteral( "frameMap" ) );
191  setLinkedMap( nullptr );
192 
193  mBlendMode = QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( itemElem.attribute( QStringLiteral( "blendMode" ), QStringLiteral( "0" ) ).toUInt() ) );
194  mInverted = ( itemElem.attribute( QStringLiteral( "inverted" ), QStringLiteral( "0" ) ) != QLatin1String( "0" ) );
195  mCentered = ( itemElem.attribute( QStringLiteral( "centered" ), QStringLiteral( "0" ) ) != QLatin1String( "0" ) );
196 
197  QDomElement frameStyleElem = itemElem.firstChildElement( QStringLiteral( "symbol" ) );
198  if ( !frameStyleElem.isNull() )
199  {
200  mFrameSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( frameStyleElem, context ) );
201  }
202  return ok;
203 }
204 
206 {
207  if ( !mFrameMapUuid.isEmpty() )
208  {
209  setLinkedMap( qobject_cast< QgsLayoutItemMap * >( mLayout->itemByUuid( mFrameMapUuid, true ) ) );
210  }
211 }
212 
214 {
215  return mBlendMode != QPainter::CompositionMode_SourceOver;
216 }
217 
219 {
220  if ( mFrameMap == map )
221  {
222  //no change
223  return;
224  }
225 
226  //disconnect old map
227  if ( mFrameMap )
228  {
231  }
232  mFrameMap = map;
233  //connect to new map signals
234  connectSignals();
236 }
237 
239 {
240  return mFrameMap;
241 }
242 
244 {
245  if ( !mMap )
246  {
247  return;
248  }
249 
250  if ( mFrameMap )
251  {
254  }
255 }
256 
258 {
259  if ( !mEnabled || !mFrameMap || !mMap || !mMap->layout() )
260  {
261  return nullptr;
262  }
263 
264  const QgsLayoutItemMap *overviewFrameMap = linkedMap();
265  if ( !overviewFrameMap )
266  {
267  return nullptr;
268  }
269 
270  //get polygon for other overview frame map's extent (use visibleExtentPolygon as it accounts for map rotation)
271  QPolygonF otherExtent = overviewFrameMap->visibleExtentPolygon();
272  QgsGeometry g = QgsGeometry::fromQPolygonF( otherExtent );
273 
274  if ( overviewFrameMap->crs() != mMap->crs() )
275  {
276  // reproject extent
277  QgsCoordinateTransform ct( overviewFrameMap->crs(),
278  mMap->crs(), mLayout->project() );
279  g = g.densifyByCount( 20 );
280  try
281  {
282  g.transform( ct );
283  }
284  catch ( QgsCsException & )
285  {
286  }
287  }
288 
289  //get current map's extent as a QPolygonF
290  QPolygonF thisExtent = mMap->visibleExtentPolygon();
291  QgsGeometry thisGeom = QgsGeometry::fromQPolygonF( thisExtent );
292  //intersect the two
293  QgsGeometry intersectExtent = thisGeom.intersection( g );
294 
295  mExtentLayer->setBlendMode( mBlendMode );
296 
297  static_cast< QgsSingleSymbolRenderer * >( mExtentLayer->renderer() )->setSymbol( mFrameSymbol->clone() );
298  mExtentLayer->dataProvider()->truncate();
299  mExtentLayer->setCrs( mMap->crs() );
300 
301  if ( mInverted )
302  {
303  intersectExtent = thisGeom.difference( intersectExtent );
304  }
305 
306  QgsFeature f;
307  f.setGeometry( intersectExtent );
308  mExtentLayer->dataProvider()->addFeature( f );
309 
310  return mExtentLayer.get();
311 }
312 
314 {
315  return mExtentLayer.get();
316 }
317 
319 {
320  if ( mFrameSymbol )
321  {
322  QgsStyleSymbolEntity entity( mFrameSymbol.get() );
323  if ( !visitor->visit( QgsStyleEntityVisitorInterface::StyleLeaf( &entity, QStringLiteral( "overview" ), QObject::tr( "Overview" ) ) ) )
324  return false;
325  }
326 
327  return true;
328 }
329 
331 {
332  mFrameSymbol.reset( symbol );
333 }
334 
336 {
337  return mFrameSymbol.get();
338 }
339 
341 {
342  return mFrameSymbol.get();
343 }
344 
345 void QgsLayoutItemMapOverview::setBlendMode( const QPainter::CompositionMode blendMode )
346 {
347  mBlendMode = blendMode;
348 }
349 
350 void QgsLayoutItemMapOverview::setInverted( const bool inverted )
351 {
352  mInverted = inverted;
353 }
354 
355 void QgsLayoutItemMapOverview::setCentered( const bool centered )
356 {
357  mCentered = centered;
359 }
360 
362 {
363  if ( !mMap )
364  {
365  return;
366  }
367 
368  //if using overview centering, update the map's extent
369  if ( mMap->layout() && mCentered && mFrameMap )
370  {
371  QgsRectangle extent = mMap->extent();
372  QgsRectangle otherExtent = mFrameMap->extent();
373 
374  QgsPointXY center = otherExtent.center();
375  QgsRectangle movedExtent( center.x() - extent.width() / 2,
376  center.y() - extent.height() / 2,
377  center.x() - extent.width() / 2 + extent.width(),
378  center.y() - extent.height() / 2 + extent.height() );
379  mMap->setExtent( movedExtent );
380  }
381 
382  //repaint map so that overview gets updated
384 }
385 
386 
387 //
388 // QgsLayoutItemMapOverviewStack
389 //
390 
393 {
394 
395 }
396 
398 {
400 }
401 
402 void QgsLayoutItemMapOverviewStack::removeOverview( const QString &overviewId )
403 {
405 }
406 
407 void QgsLayoutItemMapOverviewStack::moveOverviewUp( const QString &overviewId )
408 {
410 }
411 
412 void QgsLayoutItemMapOverviewStack::moveOverviewDown( const QString &overviewId )
413 {
415 }
416 
418 {
420  return qobject_cast<QgsLayoutItemMapOverview *>( item );
421 }
422 
424 {
426  return qobject_cast<QgsLayoutItemMapOverview *>( item );
427 }
428 
430 {
431  QgsLayoutItemMapItem *item = mItems.at( idx );
432  QgsLayoutItemMapOverview *overview = qobject_cast<QgsLayoutItemMapOverview *>( item );
433  return *overview;
434 }
435 
436 QList<QgsLayoutItemMapOverview *> QgsLayoutItemMapOverviewStack::asList() const
437 {
438  QList< QgsLayoutItemMapOverview * > list;
439  QList< QgsLayoutItemMapItem * >::const_iterator it = mItems.begin();
440  for ( ; it != mItems.end(); ++it )
441  {
442  QgsLayoutItemMapOverview *overview = qobject_cast<QgsLayoutItemMapOverview *>( *it );
443  if ( overview )
444  {
445  list.append( overview );
446  }
447  }
448  return list;
449 }
450 
451 bool QgsLayoutItemMapOverviewStack::readXml( const QDomElement &elem, const QDomDocument &doc, const QgsReadWriteContext &context )
452 {
453  removeItems();
454 
455  //read overview stack
456  QDomNodeList mapOverviewNodeList = elem.elementsByTagName( QStringLiteral( "ComposerMapOverview" ) );
457  for ( int i = 0; i < mapOverviewNodeList.size(); ++i )
458  {
459  QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
460  QgsLayoutItemMapOverview *mapOverview = new QgsLayoutItemMapOverview( mapOverviewElem.attribute( QStringLiteral( "name" ) ), mMap );
461  mapOverview->readXml( mapOverviewElem, doc, context );
462  mItems.append( mapOverview );
463  }
464 
465  return true;
466 }
467 
468 QList<QgsMapLayer *> QgsLayoutItemMapOverviewStack::modifyMapLayerList( const QList<QgsMapLayer *> &layers )
469 {
470  QList<QgsMapLayer *> res = layers;
471  res.reserve( layers.count() + mItems.count() );
472  for ( QgsLayoutItemMapItem *item : std::as_const( mItems ) )
473  {
474  if ( !item )
475  continue;
476 
477  QgsVectorLayer *l = static_cast< QgsLayoutItemMapOverview * >( item )->asMapLayer();
478  if ( !l )
479  continue;
480 
481  l->setCustomProperty( QStringLiteral( "_noset_layer_expression_context" ), true );
482 
483  switch ( item->stackingPosition() )
484  {
486  continue;
487 
490  {
491  QgsMapLayer *stackLayer = item->stackingLayer();
492  if ( !stackLayer )
493  continue;
494 
495  auto pos = std::find( res.begin(), res.end(), stackLayer );
496  if ( pos == res.end() )
497  continue;
498 
500  {
501  pos++;
502  if ( pos == res.end() )
503  {
504  res.push_back( l );
505  break;
506  }
507  }
508  res.insert( pos, l );
509  break;
510  }
511 
513  res.push_back( l );
514  break;
515 
517  res.push_front( l );
518  break;
519  }
520  }
521 
522  return res;
523 }
QgsLayoutItemMapOverviewStack::QgsLayoutItemMapOverviewStack
QgsLayoutItemMapOverviewStack(QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapOverviewStack, attached to the specified map.
Definition: qgslayoutitemmapoverview.cpp:391
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsLayoutObject::layout
const QgsLayout * layout() const
Returns the layout the object is attached to.
Definition: qgslayoutobject.cpp:216
QgsLayoutItemMapItem::StackAboveMapLayer
@ StackAboveMapLayer
Render above a specific map layer (see stackingLayer())
Definition: qgslayoutitemmapitem.h:44
QgsRectangle::height
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
Definition: qgsrectangle.h:230
QgsLayoutItemMapOverview::readXml
bool readXml(const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets the map item state from a DOM document, where element is the DOM node corresponding to a 'Layout...
Definition: qgslayoutitemmapoverview.cpp:180
QgsLayoutItemMapOverview::finalizeRestoreFromXml
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
Definition: qgslayoutitemmapoverview.cpp:205
QgsPointXY::y
double y
Definition: qgspointxy.h:63
QgsRenderContext::setPainterFlagsUsingContext
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
Definition: qgsrendercontext.cpp:169
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsLayoutItemMapOverviewStack::addOverview
void addOverview(QgsLayoutItemMapOverview *overview)
Adds a new map overview to the stack and takes ownership of the overview.
Definition: qgslayoutitemmapoverview.cpp:397
QgsLayoutItemMapItem::StackBelowMapLayer
@ StackBelowMapLayer
Render below a specific map layer (see stackingLayer())
Definition: qgslayoutitemmapitem.h:43
QgsLayoutItemMapOverview::overviewExtentChanged
void overviewExtentChanged()
Handles recentering of the map and redrawing of the map's overview.
Definition: qgslayoutitemmapoverview.cpp:361
QgsPainting::BlendMode
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
Definition: qgspainting.h:49
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
qgssinglesymbolrenderer.h
QgsGeometry::transform
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
Definition: qgsgeometry.cpp:3128
QgsStyleSymbolEntity
A symbol entity for QgsStyle databases.
Definition: qgsstyle.h:1341
QgsLayoutItemMapOverviewStack::moveOverviewDown
void moveOverviewDown(const QString &overviewId)
Moves an overview with matching overviewId down the stack, causing it to be rendered below other over...
Definition: qgslayoutitemmapoverview.cpp:412
QgsMapLayer::setCustomProperty
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
Definition: qgsmaplayer.cpp:1976
QgsLayoutItemMapItem::createExpressionContext
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgslayoutitemmapitem.cpp:124
qgsreadwritecontext.h
QgsRectangle::center
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Definition: qgsrectangle.h:251
QgsLayoutItemMap::extentChanged
void extentChanged()
Emitted when the map's extent changes.
QgsLayoutItemMapOverview::setInverted
void setInverted(bool inverted)
Sets whether the overview frame is inverted, ie, whether the shaded area is drawn outside the extent ...
Definition: qgslayoutitemmapoverview.cpp:350
QgsLayoutItemMapOverview::setLinkedMap
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to show the overview extent of.
Definition: qgslayoutitemmapoverview.cpp:218
qgssymbollayerutils.h
qgspathresolver.h
QgsLayoutItemMapItem::map
const QgsLayoutItemMap * map() const
Returns the layout item map for the item.
Definition: qgslayoutitemmapitem.cpp:84
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsLayoutItemMapItem
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
Definition: qgslayoutitemmapitem.h:33
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
QgsLayoutItemMapItemStack::mMap
QgsLayoutItemMap * mMap
Definition: qgslayoutitemmapitem.h:355
QgsSingleSymbolRenderer
Definition: qgssinglesymbolrenderer.h:29
QgsLayoutItemMapItemStack
A collection of map items which are drawn above the map content in a QgsLayoutItemMap....
Definition: qgslayoutitemmapitem.h:230
QgsLayoutItemMapItemStack::removeItems
void removeItems()
Clears the item stack and deletes all QgsLayoutItemMapItems contained by the stack.
Definition: qgslayoutitemmapitem.cpp:323
qgsmapsettings.h
QgsLayoutItemMapItem::StackBelowMap
@ StackBelowMap
Render below all map layers.
Definition: qgslayoutitemmapitem.h:42
QgsLayoutItemMapOverview::setFrameSymbol
void setFrameSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used for drawing the overview extent.
Definition: qgslayoutitemmapoverview.cpp:330
QgsLayoutItemMapOverview::draw
void draw(QPainter *painter) override
Draws the item on to a destination painter.
Definition: qgslayoutitemmapoverview.cpp:56
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsStyleEntityVisitorInterface::StyleLeaf
Contains information relating to the style entity currently being visited.
Definition: qgsstyleentityvisitor.h:60
QgsLayoutItemMapOverview::inverted
bool inverted() const
Returns whether the overview frame is inverted, ie, whether the shaded area is drawn outside the exte...
Definition: qgslayoutitemmapoverview.h:195
QgsGeometry::intersection
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
Definition: qgsgeometry.cpp:2616
QgsLayoutItemMapOverview::asMapLayer
QgsVectorLayer * asMapLayer()
Returns a vector layer to render as part of the QgsLayoutItemMap render, containing a feature represe...
Definition: qgslayoutitemmapoverview.cpp:257
QgsPainting::getBlendModeEnum
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
Definition: qgspainting.cpp:80
qgslayoututils.h
QgsLayoutItemMapOverview::setCentered
void setCentered(bool centered)
Sets whether the extent of the map is forced to center on the overview.
Definition: qgslayoutitemmapoverview.cpp:355
QgsLayoutItemMapOverview::setBlendMode
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the overview.
Definition: qgslayoutitemmapoverview.cpp:345
QgsLayoutUtils::createRenderContextForLayout
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
Definition: qgslayoututils.cpp:141
QgsLayoutItemMapOverviewStack::overview
QgsLayoutItemMapOverview * overview(const QString &overviewId) const
Returns a reference to an overview with matching overviewId within the stack.
Definition: qgslayoutitemmapoverview.cpp:417
QgsLayoutItemMapOverviewStack::asList
QList< QgsLayoutItemMapOverview * > asList() const
Returns a list of QgsLayoutItemMapOverviews contained by the stack.
Definition: qgslayoutitemmapoverview.cpp:436
QgsLayoutItemMapItem::mEnabled
bool mEnabled
True if item is to be displayed on map.
Definition: qgslayoutitemmapitem.h:213
QgsGeometry::asQPolygonF
QPolygonF asQPolygonF() const SIP_HOLDGIL
Returns contents of the geometry as a QPolygonF.
Definition: qgsgeometry.cpp:2785
QgsLayoutItemMapOverview::linkedMap
QgsLayoutItemMap * linkedMap()
Returns the source map to show the overview extent of.
Definition: qgslayoutitemmapoverview.cpp:238
QgsCsException
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
QgsGeometry::densifyByCount
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
Definition: qgsgeometry.cpp:2263
QgsLayoutItemMapItem::stackingLayer
QgsMapLayer * stackingLayer() const
Returns the item's stacking layer, which specifies where the in the map's stack the item should be re...
Definition: qgslayoutitemmapitem.cpp:114
qgslayoutitemmapoverview.h
QgsFeature::setGeometry
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:170
QgsLayoutItemMapItem::mMap
QgsLayoutItemMap * mMap
Associated map.
Definition: qgslayoutitemmapitem.h:207
QgsLayoutItemMapOverview::centered
bool centered() const
Returns whether the extent of the map is forced to center on the overview.
Definition: qgslayoutitemmapoverview.h:208
QgsLayoutItemMapItemStack::removeItem
void removeItem(const QString &itemId)
Removes an item which matching itemId from the stack and deletes the corresponding QgsLayoutItemMapIt...
Definition: qgslayoutitemmapitem.cpp:162
QgsLayoutItemMapOverview::~QgsLayoutItemMapOverview
~QgsLayoutItemMapOverview() override
QgsPainting::getCompositionMode
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Definition: qgspainting.cpp:20
QgsLayoutItemMap::extent
QgsRectangle extent() const
Returns the current map extent.
Definition: qgslayoutitemmap.cpp:281
qgspainting.h
QgsLayoutItemMap::invalidateCache
void invalidateCache() override
Definition: qgslayoutitemmap.cpp:1868
QgsLayoutItemMapItem::readXml
virtual bool readXml(const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context)
Sets the map item state from a DOM document, where element is the DOM node corresponding to a 'Layout...
Definition: qgslayoutitemmapitem.cpp:55
QgsScopedQPainterState
Scoped object for saving and restoring a QPainter object's state.
Definition: qgsrendercontext.h:1336
QgsLayoutItemMapItem::StackBelowMapLabels
@ StackBelowMapLabels
Render above all map layers, but below map labels.
Definition: qgslayoutitemmapitem.h:45
QgsLayoutItemMapOverview::accept
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
Definition: qgslayoutitemmapoverview.cpp:318
QgsFillSymbol::createSimple
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
Definition: qgsfillsymbol.cpp:20
qgslayout.h
QgsLayoutItemMap::crs
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
Definition: qgslayoutitemmap.cpp:308
QgsLayoutItemMapItemStack::moveItemDown
void moveItemDown(const QString &itemId)
Moves an item which matching itemId up the stack, causing it to be rendered above other items.
Definition: qgslayoutitemmapitem.cpp:194
QgsLayoutItemMapOverview::QgsLayoutItemMapOverview
QgsLayoutItemMapOverview(const QString &name, QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapOverview.
Definition: qgslayoutitemmapoverview.cpp:36
qgsvectorlayer.h
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsLayoutItemMapOverview
An individual overview which is drawn above the map content in a QgsLayoutItemMap,...
Definition: qgslayoutitemmapoverview.h:126
QgsRenderContext::setForceVectorOutput
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
Definition: qgsrendercontext.cpp:330
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:317
QgsLayoutItemMapItemStack::mItems
QList< QgsLayoutItemMapItem * > mItems
Definition: qgslayoutitemmapitem.h:353
QgsLayoutItemMapOverviewStack::modifyMapLayerList
QList< QgsMapLayer * > modifyMapLayerList(const QList< QgsMapLayer * > &layers)
Alters the list of map layers which will be rendered for the link map item, inserting temporary layer...
Definition: qgslayoutitemmapoverview.cpp:468
QgsLayoutItemMapOverview::mapLayer
QgsMapLayer * mapLayer() override
Returns the internal map layer used by this item, if available.
Definition: qgslayoutitemmapoverview.cpp:313
QgsLayoutItemMapItem::stackingPosition
StackingPosition stackingPosition() const
Returns the item's stacking position, which specifies where the in the map's stack the item should be...
Definition: qgslayoutitemmapitem.h:140
QgsLayoutItemMapOverview::connectSignals
void connectSignals()
Reconnects signals for overview map, so that overview correctly follows changes to source map's exten...
Definition: qgslayoutitemmapoverview.cpp:243
QgsLayoutObject::mLayout
QPointer< QgsLayout > mLayout
Definition: qgslayoutobject.h:363
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsLayoutItemMapItem::StackAboveMapLabels
@ StackAboveMapLabels
Render above all map layers and labels.
Definition: qgslayoutitemmapitem.h:46
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsRectangle::width
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:223
QgsLayoutItemMap::mapRotationChanged
void mapRotationChanged(double newRotation)
Emitted when the map's rotation changes.
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsLayoutItemMapItem::writeXml
virtual bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores map item state in a DOM element, where element is the DOM element corresponding to a 'LayoutMa...
Definition: qgslayoutitemmapitem.cpp:33
QgsPointXY::x
double x
Definition: qgspointxy.h:62
QgsLayoutItemMapOverviewStack::removeOverview
void removeOverview(const QString &overviewId)
Removes an overview with matching overviewId from the stack and deletes the corresponding QgsLayoutIt...
Definition: qgslayoutitemmapoverview.cpp:402
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:29
QgsStyleEntityVisitorInterface::visit
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
Definition: qgsstyleentityvisitor.h:153
QgsRenderContext::setExpressionContext
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Definition: qgsrendercontext.h:617
QgsLayoutItemMapItemStack::moveItemUp
void moveItemUp(const QString &itemId)
Moves an item which matching itemId up the stack, causing it to be rendered above other items.
Definition: qgslayoutitemmapitem.cpp:174
QgsLayoutItemMapOverviewStack::readXml
bool readXml(const QDomElement &elem, const QDomDocument &doc, const QgsReadWriteContext &context) override
Sets the item stack's state from a DOM document, where element is a DOM node corresponding to a 'Layo...
Definition: qgslayoutitemmapoverview.cpp:451
qgsexception.h
QgsGeometry::fromQPolygonF
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
Definition: qgsgeometry.cpp:3408
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsLayoutItemMapItemStack::item
QgsLayoutItemMapItem * item(int index) const
Returns a reference to the item at the specified index within the stack.
Definition: qgslayoutitemmapitem.cpp:227
QgsLayoutItemMapOverview::frameSymbol
QgsFillSymbol * frameSymbol()
Returns the fill symbol used for drawing the overview extent.
Definition: qgslayoutitemmapoverview.cpp:335
QgsLayoutItemMapItemStack::addItem
void addItem(QgsLayoutItemMapItem *item)
Adds a new map item to the stack and takes ownership of the item.
Definition: qgslayoutitemmapitem.cpp:157
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:57
QgsLayoutItemMapOverview::blendMode
QPainter::CompositionMode blendMode() const
Retrieves the blending mode used for drawing the overview.
Definition: qgslayoutitemmapoverview.h:182
QgsLayoutItemMapOverview::usesAdvancedEffects
bool usesAdvancedEffects() const override
Returns true if the item is drawn using advanced effects, such as blend modes.
Definition: qgslayoutitemmapoverview.cpp:213
QgsLayoutItemMap::setExtent
void setExtent(const QgsRectangle &extent)
Sets a new extent for the map.
Definition: qgslayoutitemmap.cpp:217
qgsfillsymbol.h
qgssymbol.h
QgsSymbolLayerUtils::saveSymbol
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
Definition: qgssymbollayerutils.cpp:1397
QgsGeometry::difference
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other.
Definition: qgsgeometry.cpp:2677
QgsLayoutItemMapOverviewStack::operator[]
QgsLayoutItemMapOverview & operator[](int index)
Returns a reference to an overview at the specified index within the stack.
Definition: qgslayoutitemmapoverview.cpp:429
QgsLayoutItemMapOverview::writeXml
bool writeXml(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Stores map item state in a DOM element, where element is the DOM element corresponding to a 'LayoutMa...
Definition: qgslayoutitemmapoverview.cpp:157
qgsstyleentityvisitor.h
QgsLayoutItemMap::visibleExtentPolygon
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation.
Definition: qgslayoutitemmap.cpp:303
qgslayoutitemmap.h
QgsLayoutItemMapOverviewStack::moveOverviewUp
void moveOverviewUp(const QString &overviewId)
Moves an overview with matching overviewId up the stack, causing it to be rendered above other overvi...
Definition: qgslayoutitemmapoverview.cpp:407