QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
33 #include <QPainter>
34 
36  : QgsLayoutItemMapItem( name, map )
37  , mExtentLayer( qgis::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() ) ) )
38 {
39  createDefaultFrameSymbol();
40 }
41 
43 
44 void QgsLayoutItemMapOverview::createDefaultFrameSymbol()
45 {
46  QgsStringMap properties;
47  properties.insert( QStringLiteral( "color" ), QStringLiteral( "255,0,0,75" ) );
48  properties.insert( QStringLiteral( "style" ), QStringLiteral( "solid" ) );
49  properties.insert( QStringLiteral( "style_border" ), QStringLiteral( "no" ) );
50  mFrameSymbol.reset( QgsFillSymbol::createSimple( properties ) );
51 
52  mExtentLayer->setRenderer( new QgsSingleSymbolRenderer( mFrameSymbol->clone() ) );
53 }
54 
55 void QgsLayoutItemMapOverview::draw( QPainter *painter )
56 {
57  if ( !mEnabled || !mFrameMap || !mMap || !mMap->layout() )
58  {
59  return;
60  }
61  if ( !painter )
62  {
63  return;
64  }
65 
66  const QgsLayoutItemMap *overviewFrameMap = linkedMap();
67  if ( !overviewFrameMap )
68  {
69  return;
70  }
71 
72  //get polygon for other overview frame map's extent (use visibleExtentPolygon as it accounts for map rotation)
73  QPolygonF otherExtent = overviewFrameMap->visibleExtentPolygon();
74  if ( overviewFrameMap->crs() !=
75  mMap->crs() )
76  {
77  QgsGeometry g = QgsGeometry::fromQPolygonF( otherExtent );
78 
79  // reproject extent
80  QgsCoordinateTransform ct( overviewFrameMap->crs(),
81  mMap->crs(), mLayout->project() );
82  g = g.densifyByCount( 20 );
83  try
84  {
85  g.transform( ct );
86  }
87  catch ( QgsCsException & )
88  {
89  }
90 
91  otherExtent = g.asQPolygonF();
92  }
93 
94  //get current map's extent as a QPolygonF
95  QPolygonF thisExtent = mMap->visibleExtentPolygon();
96  //intersect the two
97  QPolygonF intersectExtent = thisExtent.intersected( otherExtent );
98 
99  //setup painter scaling to dots so that raster symbology is drawn to scale
100  double dotsPerMM = painter->device()->logicalDpiX() / 25.4;
101 
102  //setup render context
104  context.setForceVectorOutput( true );
105  QgsExpressionContext expressionContext = createExpressionContext();
106  context.setExpressionContext( expressionContext );
107 
108  QgsScopedQPainterState painterState( painter );
109  context.setPainterFlagsUsingContext( painter );
110 
111  painter->setCompositionMode( mBlendMode );
112  painter->translate( mMap->mXOffset, mMap->mYOffset );
113  painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
114 
115  mFrameSymbol->startRender( context );
116 
117  //construct a polygon corresponding to the intersecting map extent
118  //need to scale line to dots, rather then mm, since the painter has been scaled to dots
119  QTransform mapTransform;
120  QPolygonF thisRectPoly = QPolygonF( QRectF( 0, 0, dotsPerMM * mMap->rect().width(), dotsPerMM * mMap->rect().height() ) );
121 
122  //workaround QT Bug #21329
123  thisRectPoly.pop_back();
124  thisExtent.pop_back();
125 
126  //create transform from map coordinates to painter coordinates
127  QTransform::quadToQuad( thisExtent, thisRectPoly, mapTransform );
128  QPolygonF intersectPolygon;
129  intersectPolygon = mapTransform.map( intersectExtent );
130 
131  QVector<QPolygonF> rings; //empty list
132  if ( !mInverted )
133  {
134  //Render the intersecting map extent
135  mFrameSymbol->renderPolygon( intersectPolygon, &rings, nullptr, context );
136  }
137  else
138  {
139  //We are inverting the overview frame (ie, shading outside the intersecting extent)
140  //Construct a polygon corresponding to the overview map extent
141  QPolygonF outerPolygon;
142  outerPolygon << QPointF( 0, 0 )
143  << QPointF( mMap->rect().width() * dotsPerMM, 0 )
144  << QPointF( mMap->rect().width() * dotsPerMM, mMap->rect().height() * dotsPerMM )
145  << QPointF( 0, mMap->rect().height() * dotsPerMM )
146  << QPointF( 0, 0 );
147 
148  //Intersecting extent is an inner ring for the shaded area
149  rings.append( intersectPolygon );
150  mFrameSymbol->renderPolygon( outerPolygon, &rings, nullptr, context );
151  }
152 
153  mFrameSymbol->stopRender( context );
154 }
155 
156 bool QgsLayoutItemMapOverview::writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const
157 {
158  if ( elem.isNull() )
159  {
160  return false;
161  }
162 
163  //overview map frame
164  QDomElement overviewFrameElem = doc.createElement( QStringLiteral( "ComposerMapOverview" ) );
165 
166  overviewFrameElem.setAttribute( QStringLiteral( "frameMap" ), mFrameMap ? mFrameMap ->uuid() : QString() );
167  overviewFrameElem.setAttribute( QStringLiteral( "blendMode" ), QgsPainting::getBlendModeEnum( mBlendMode ) );
168  overviewFrameElem.setAttribute( QStringLiteral( "inverted" ), mInverted );
169  overviewFrameElem.setAttribute( QStringLiteral( "centered" ), mCentered );
170 
171  QDomElement frameStyleElem = QgsSymbolLayerUtils::saveSymbol( QString(), mFrameSymbol.get(), doc, context );
172  overviewFrameElem.appendChild( frameStyleElem );
173 
174  bool ok = QgsLayoutItemMapItem::writeXml( overviewFrameElem, doc, context );
175  elem.appendChild( overviewFrameElem );
176  return ok;
177 }
178 
179 bool QgsLayoutItemMapOverview::readXml( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context )
180 {
181  Q_UNUSED( doc )
182  if ( itemElem.isNull() )
183  {
184  return false;
185  }
186 
187  bool ok = QgsLayoutItemMapItem::readXml( itemElem, doc, context );
188 
189  mFrameMapUuid = itemElem.attribute( QStringLiteral( "frameMap" ) );
190  setLinkedMap( nullptr );
191 
192  mBlendMode = QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( itemElem.attribute( QStringLiteral( "blendMode" ), QStringLiteral( "0" ) ).toUInt() ) );
193  mInverted = ( itemElem.attribute( QStringLiteral( "inverted" ), QStringLiteral( "0" ) ) != QLatin1String( "0" ) );
194  mCentered = ( itemElem.attribute( QStringLiteral( "centered" ), QStringLiteral( "0" ) ) != QLatin1String( "0" ) );
195 
196  QDomElement frameStyleElem = itemElem.firstChildElement( QStringLiteral( "symbol" ) );
197  if ( !frameStyleElem.isNull() )
198  {
199  mFrameSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( frameStyleElem, context ) );
200  }
201  return ok;
202 }
203 
205 {
206  if ( !mFrameMapUuid.isEmpty() )
207  {
208  setLinkedMap( qobject_cast< QgsLayoutItemMap * >( mLayout->itemByUuid( mFrameMapUuid, true ) ) );
209  }
210 }
211 
213 {
214  return mBlendMode != QPainter::CompositionMode_SourceOver;
215 }
216 
218 {
219  if ( mFrameMap == map )
220  {
221  //no change
222  return;
223  }
224 
225  //disconnect old map
226  if ( mFrameMap )
227  {
230  }
231  mFrameMap = map;
232  //connect to new map signals
233  connectSignals();
235 }
236 
238 {
239  return mFrameMap;
240 }
241 
243 {
244  if ( !mMap )
245  {
246  return;
247  }
248 
249  if ( mFrameMap )
250  {
253  }
254 }
255 
257 {
258  if ( !mEnabled || !mFrameMap || !mMap || !mMap->layout() )
259  {
260  return nullptr;
261  }
262 
263  const QgsLayoutItemMap *overviewFrameMap = linkedMap();
264  if ( !overviewFrameMap )
265  {
266  return nullptr;
267  }
268 
269  //get polygon for other overview frame map's extent (use visibleExtentPolygon as it accounts for map rotation)
270  QPolygonF otherExtent = overviewFrameMap->visibleExtentPolygon();
271  QgsGeometry g = QgsGeometry::fromQPolygonF( otherExtent );
272 
273  if ( overviewFrameMap->crs() != mMap->crs() )
274  {
275  // reproject extent
276  QgsCoordinateTransform ct( overviewFrameMap->crs(),
277  mMap->crs(), mLayout->project() );
278  g = g.densifyByCount( 20 );
279  try
280  {
281  g.transform( ct );
282  }
283  catch ( QgsCsException & )
284  {
285  }
286  }
287 
288  //get current map's extent as a QPolygonF
289  QPolygonF thisExtent = mMap->visibleExtentPolygon();
290  QgsGeometry thisGeom = QgsGeometry::fromQPolygonF( thisExtent );
291  //intersect the two
292  QgsGeometry intersectExtent = thisGeom.intersection( g );
293 
294  mExtentLayer->setBlendMode( mBlendMode );
295 
296  static_cast< QgsSingleSymbolRenderer * >( mExtentLayer->renderer() )->setSymbol( mFrameSymbol->clone() );
297  mExtentLayer->dataProvider()->truncate();
298  mExtentLayer->setCrs( mMap->crs() );
299 
300  if ( mInverted )
301  {
302  intersectExtent = thisGeom.difference( intersectExtent );
303  }
304 
305  QgsFeature f;
306  f.setGeometry( intersectExtent );
307  mExtentLayer->dataProvider()->addFeature( f );
308 
309  return mExtentLayer.get();
310 }
311 
313 {
314  return mExtentLayer.get();
315 }
316 
318 {
319  if ( mFrameSymbol )
320  {
321  QgsStyleSymbolEntity entity( mFrameSymbol.get() );
322  if ( !visitor->visit( QgsStyleEntityVisitorInterface::StyleLeaf( &entity, QStringLiteral( "overview" ), QObject::tr( "Overview" ) ) ) )
323  return false;
324  }
325 
326  return true;
327 }
328 
330 {
331  mFrameSymbol.reset( symbol );
332 }
333 
335 {
336  return mFrameSymbol.get();
337 }
338 
340 {
341  return mFrameSymbol.get();
342 }
343 
344 void QgsLayoutItemMapOverview::setBlendMode( const QPainter::CompositionMode blendMode )
345 {
346  mBlendMode = blendMode;
347 }
348 
349 void QgsLayoutItemMapOverview::setInverted( const bool inverted )
350 {
351  mInverted = inverted;
352 }
353 
354 void QgsLayoutItemMapOverview::setCentered( const bool centered )
355 {
356  mCentered = centered;
358 }
359 
361 {
362  if ( !mMap )
363  {
364  return;
365  }
366 
367  //if using overview centering, update the map's extent
368  if ( mMap->layout() && mCentered && mFrameMap )
369  {
370  QgsRectangle extent = mMap->extent();
371  QgsRectangle otherExtent = mFrameMap->extent();
372 
373  QgsPointXY center = otherExtent.center();
374  QgsRectangle movedExtent( center.x() - extent.width() / 2,
375  center.y() - extent.height() / 2,
376  center.x() - extent.width() / 2 + extent.width(),
377  center.y() - extent.height() / 2 + extent.height() );
378  mMap->setExtent( movedExtent );
379  }
380 
381  //repaint map so that overview gets updated
383 }
384 
385 
386 //
387 // QgsLayoutItemMapOverviewStack
388 //
389 
392 {
393 
394 }
395 
397 {
399 }
400 
401 void QgsLayoutItemMapOverviewStack::removeOverview( const QString &overviewId )
402 {
404 }
405 
406 void QgsLayoutItemMapOverviewStack::moveOverviewUp( const QString &overviewId )
407 {
409 }
410 
411 void QgsLayoutItemMapOverviewStack::moveOverviewDown( const QString &overviewId )
412 {
414 }
415 
417 {
419  return qobject_cast<QgsLayoutItemMapOverview *>( item );
420 }
421 
423 {
425  return qobject_cast<QgsLayoutItemMapOverview *>( item );
426 }
427 
429 {
430  QgsLayoutItemMapItem *item = mItems.at( idx );
431  QgsLayoutItemMapOverview *overview = qobject_cast<QgsLayoutItemMapOverview *>( item );
432  return *overview;
433 }
434 
435 QList<QgsLayoutItemMapOverview *> QgsLayoutItemMapOverviewStack::asList() const
436 {
437  QList< QgsLayoutItemMapOverview * > list;
438  QList< QgsLayoutItemMapItem * >::const_iterator it = mItems.begin();
439  for ( ; it != mItems.end(); ++it )
440  {
441  QgsLayoutItemMapOverview *overview = qobject_cast<QgsLayoutItemMapOverview *>( *it );
442  if ( overview )
443  {
444  list.append( overview );
445  }
446  }
447  return list;
448 }
449 
450 bool QgsLayoutItemMapOverviewStack::readXml( const QDomElement &elem, const QDomDocument &doc, const QgsReadWriteContext &context )
451 {
452  removeItems();
453 
454  //read overview stack
455  QDomNodeList mapOverviewNodeList = elem.elementsByTagName( QStringLiteral( "ComposerMapOverview" ) );
456  for ( int i = 0; i < mapOverviewNodeList.size(); ++i )
457  {
458  QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
459  QgsLayoutItemMapOverview *mapOverview = new QgsLayoutItemMapOverview( mapOverviewElem.attribute( QStringLiteral( "name" ) ), mMap );
460  mapOverview->readXml( mapOverviewElem, doc, context );
461  mItems.append( mapOverview );
462  }
463 
464  return true;
465 }
466 
467 QList<QgsMapLayer *> QgsLayoutItemMapOverviewStack::modifyMapLayerList( const QList<QgsMapLayer *> &layers )
468 {
469  QList<QgsMapLayer *> res = layers;
470  res.reserve( layers.count() + mItems.count() );
471  for ( QgsLayoutItemMapItem *item : qgis::as_const( mItems ) )
472  {
473  if ( !item )
474  continue;
475 
476  QgsVectorLayer *l = static_cast< QgsLayoutItemMapOverview * >( item )->asMapLayer();
477  if ( !l )
478  continue;
479 
480  switch ( item->stackingPosition() )
481  {
483  continue;
484 
487  {
488  QgsMapLayer *stackLayer = item->stackingLayer();
489  if ( !stackLayer )
490  continue;
491 
492  auto pos = std::find( res.begin(), res.end(), stackLayer );
493  if ( pos == res.end() )
494  continue;
495 
497  {
498  pos++;
499  if ( pos == res.end() )
500  {
501  res.push_back( l );
502  break;
503  }
504  }
505  res.insert( pos, l );
506  break;
507  }
508 
510  res.push_back( l );
511  break;
512 
514  res.push_front( l );
515  break;
516  }
517  }
518 
519  return res;
520 }
QgsLayoutItemMapOverviewStack::QgsLayoutItemMapOverviewStack
QgsLayoutItemMapOverviewStack(QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapOverviewStack, attached to the specified map.
Definition: qgslayoutitemmapoverview.cpp:390
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsLayoutObject::layout
const QgsLayout * layout() const
Returns the layout the object is attached to.
Definition: qgslayoutobject.cpp:126
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:209
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:179
QgsLayoutItemMapOverview::finalizeRestoreFromXml
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
Definition: qgslayoutitemmapoverview.cpp:204
QgsPointXY::y
double y
Definition: qgspointxy.h:48
QgsGeometry::transform
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
Definition: qgsgeometry.cpp:2813
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:143
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
QgsLayoutItemMapOverviewStack::addOverview
void addOverview(QgsLayoutItemMapOverview *overview)
Adds a new map overview to the stack and takes ownership of the overview.
Definition: qgslayoutitemmapoverview.cpp:396
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:360
QgsPainting::BlendMode
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
Definition: qgspainting.h:37
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
qgssinglesymbolrenderer.h
QgsStyleSymbolEntity
A symbol entity for QgsStyle databases.
Definition: qgsstyle.h:1201
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:411
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:230
QgsLayoutItemMap::extentChanged
void extentChanged()
Emitted when the map's extent changes.
QgsPointXY::x
Q_GADGET double x
Definition: qgspointxy.h:47
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:349
QgsLayoutItemMapOverview::setLinkedMap
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to show the overview extent of.
Definition: qgslayoutitemmapoverview.cpp:217
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:58
QgsLayoutItemMapItem
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
Definition: qgslayoutitemmapitem.h:34
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
QgsLayoutItemMapItemStack::mMap
QgsLayoutItemMap * mMap
Definition: qgslayoutitemmapitem.h:355
QgsSingleSymbolRenderer
Definition: qgssinglesymbolrenderer.h:30
QgsLayoutItemMapItemStack
A collection of map items which are drawn above the map content in a QgsLayoutItemMap.
Definition: qgslayoutitemmapitem.h:231
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:329
QgsLayoutItemMapOverview::draw
void draw(QPainter *painter) override
Draws the item on to a destination painter.
Definition: qgslayoutitemmapoverview.cpp:55
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsStyleEntityVisitorInterface::StyleLeaf
Contains information relating to the style entity currently being visited.
Definition: qgsstyleentityvisitor.h:61
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:2380
QgsLayoutItemMapOverview::asMapLayer
QgsVectorLayer * asMapLayer()
Returns a vector layer to render as part of the QgsLayoutItemMap render, containing a feature represe...
Definition: qgslayoutitemmapoverview.cpp:256
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:354
QgsLayoutItemMapOverview::setBlendMode
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the overview.
Definition: qgslayoutitemmapoverview.cpp:344
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:138
QgsLayoutItemMapOverviewStack::overview
QgsLayoutItemMapOverview * overview(const QString &overviewId) const
Returns a reference to an overview with matching overviewId within the stack.
Definition: qgslayoutitemmapoverview.cpp:416
QgsLayoutItemMapOverviewStack::asList
QList< QgsLayoutItemMapOverview * > asList() const
Returns a list of QgsLayoutItemMapOverviews contained by the stack.
Definition: qgslayoutitemmapoverview.cpp:435
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:2549
QgsLayoutItemMapOverview::linkedMap
QgsLayoutItemMap * linkedMap()
Returns the source map to show the overview extent of.
Definition: qgslayoutitemmapoverview.cpp:237
QgsCsException
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
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:2117
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:139
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:265
qgspainting.h
QgsLayoutItemMap::invalidateCache
void invalidateCache() override
Definition: qgslayoutitemmap.cpp:1815
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:1120
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:317
qgslayout.h
QgsLayoutItemMap::crs
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
Definition: qgslayoutitemmap.cpp:292
QgsLayoutItemMapOverview::frameSymbol
QgsFillSymbol * frameSymbol()
Returns the fill symbol used for drawing the overview extent.
Definition: qgslayoutitemmapoverview.cpp:334
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:35
qgsvectorlayer.h
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsLayoutItemMapOverview
An individual overview which is drawn above the map content in a QgsLayoutItemMap,...
Definition: qgslayoutitemmapoverview.h:127
QgsRenderContext::setForceVectorOutput
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
Definition: qgsrendercontext.cpp:281
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:318
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:467
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:758
QgsLayoutItemMapOverview::mapLayer
QgsMapLayer * mapLayer() override
Returns the internal map layer used by this item, if available.
Definition: qgslayoutitemmapoverview.cpp:312
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:242
QgsLayoutObject::mLayout
QPointer< QgsLayout > mLayout
Definition: qgslayoutobject.h:343
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:387
QgsRectangle::width
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QgsLayoutItemMap::mapRotationChanged
void mapRotationChanged(double newRotation)
Emitted when the map's rotation changes.
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
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
QgsLayoutItemMapOverviewStack::removeOverview
void removeOverview(const QString &overviewId)
Removes an overview with matching overviewId from the stack and deletes the corresponding QgsLayoutIt...
Definition: qgslayoutitemmapoverview.cpp:401
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgssymbol.h:1234
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:588
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:450
qgsexception.h
QgsGeometry::fromQPolygonF
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
Definition: qgsgeometry.cpp:3072
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsLayoutItemMapItemStack::item
QgsLayoutItemMapItem * item(int index) const
Returns a reference to the item at the specified index within the stack.
Definition: qgslayoutitemmapitem.cpp:227
QgsFillSymbol::createSimple
static QgsFillSymbol * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
Definition: qgssymbol.cpp:1481
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:53
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:212
QgsLayoutItemMap::setExtent
void setExtent(const QgsRectangle &extent)
Sets a new extent for the map.
Definition: qgslayoutitemmap.cpp:201
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:1182
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:2441
QgsLayoutItemMapOverviewStack::operator[]
QgsLayoutItemMapOverview & operator[](int index)
Returns a reference to an overview at the specified index within the stack.
Definition: qgslayoutitemmapoverview.cpp:428
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:156
qgsstyleentityvisitor.h
QgsLayoutItemMap::visibleExtentPolygon
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation.
Definition: qgslayoutitemmap.cpp:287
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:406