36 , 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() ) ) )
38 createDefaultFrameSymbol();
43void QgsLayoutItemMapOverview::createDefaultFrameSymbol()
45 QVariantMap properties;
46 properties.insert( QStringLiteral(
"color" ), QStringLiteral(
"255,0,0,75" ) );
47 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
48 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"no" ) );
66 if ( !overviewFrameMap )
73 if ( overviewFrameMap->
crs() !=
96 QPolygonF intersectExtent = thisExtent.intersected( otherExtent );
99 double dotsPerMM = painter->device()->logicalDpiX() / 25.4;
110 painter->setCompositionMode( mBlendMode );
111 painter->translate(
mMap->mXOffset,
mMap->mYOffset );
112 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
114 mFrameSymbol->startRender( context );
118 QTransform mapTransform;
119 QPolygonF thisRectPoly = QPolygonF( QRectF( 0, 0, dotsPerMM *
mMap->rect().width(), dotsPerMM *
mMap->rect().height() ) );
122 thisRectPoly.pop_back();
123 thisExtent.pop_back();
126 QTransform::quadToQuad( thisExtent, thisRectPoly, mapTransform );
127 QPolygonF intersectPolygon;
128 intersectPolygon = mapTransform.map( intersectExtent );
130 QVector<QPolygonF> rings;
134 mFrameSymbol->renderPolygon( intersectPolygon, &rings,
nullptr, context );
140 QPolygonF outerPolygon;
141 outerPolygon << QPointF( 0, 0 )
142 << QPointF(
mMap->rect().width() * dotsPerMM, 0 )
143 << QPointF(
mMap->rect().width() * dotsPerMM,
mMap->rect().height() * dotsPerMM )
144 << QPointF( 0,
mMap->rect().height() * dotsPerMM )
148 rings.append( intersectPolygon );
149 mFrameSymbol->renderPolygon( outerPolygon, &rings,
nullptr, context );
152 mFrameSymbol->stopRender( context );
163 QDomElement overviewFrameElem = doc.createElement( QStringLiteral(
"ComposerMapOverview" ) );
165 overviewFrameElem.setAttribute( QStringLiteral(
"frameMap" ), mFrameMap ? mFrameMap ->uuid() : QString() );
167 overviewFrameElem.setAttribute( QStringLiteral(
"inverted" ), mInverted );
168 overviewFrameElem.setAttribute( QStringLiteral(
"centered" ), mCentered );
171 overviewFrameElem.appendChild( frameStyleElem );
174 elem.appendChild( overviewFrameElem );
181 if ( itemElem.isNull() )
188 mFrameMapUuid = itemElem.attribute( QStringLiteral(
"frameMap" ) );
192 mInverted = ( itemElem.attribute( QStringLiteral(
"inverted" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
193 mCentered = ( itemElem.attribute( QStringLiteral(
"centered" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
195 QDomElement frameStyleElem = itemElem.firstChildElement( QStringLiteral(
"symbol" ) );
196 if ( !frameStyleElem.isNull() )
198 mFrameSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( frameStyleElem, context ) );
205 if ( !mFrameMapUuid.isEmpty() )
207 setLinkedMap( qobject_cast< QgsLayoutItemMap * >(
mLayout->itemByUuid( mFrameMapUuid,
true ) ) );
213 return mBlendMode != QPainter::CompositionMode_SourceOver;
218 if ( mFrameMap ==
map )
263 if ( !overviewFrameMap )
293 mExtentLayer->setBlendMode( mBlendMode );
296 mExtentLayer->dataProvider()->truncate();
297 mExtentLayer->setCrs(
mMap->
crs() );
301 intersectExtent = thisGeom.
difference( intersectExtent );
306 mExtentLayer->dataProvider()->addFeature( f );
308 return mExtentLayer.get();
313 return mExtentLayer.get();
330 mFrameSymbol.reset( symbol );
335 return mFrameSymbol.get();
340 return mFrameSymbol.get();
367 if (
mMap->
layout() && mCentered && mFrameMap )
374 center.
y() - extent.
height() / 2,
418 return qobject_cast<QgsLayoutItemMapOverview *>(
item );
424 return qobject_cast<QgsLayoutItemMapOverview *>(
item );
436 QList< QgsLayoutItemMapOverview * > list;
437 QList< QgsLayoutItemMapItem * >::const_iterator it =
mItems.begin();
438 for ( ; it !=
mItems.end(); ++it )
454 QDomNodeList mapOverviewNodeList = elem.elementsByTagName( QStringLiteral(
"ComposerMapOverview" ) );
455 for (
int i = 0; i < mapOverviewNodeList.size(); ++i )
457 QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
459 mapOverview->
readXml( mapOverviewElem, doc, context );
460 mItems.append( mapOverview );
468 QList<QgsMapLayer *> res = layers;
469 res.reserve( layers.count() +
mItems.count() );
479 l->
setCustomProperty( QStringLiteral(
"_noset_layer_expression_context" ), true );
493 auto pos = std::find( res.begin(), res.end(), stackLayer );
494 if ( pos == res.end() )
500 if ( pos == res.end() )
506 res.insert( pos, l );
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Contains information about the context in which a coordinate transform is executed.
Custom exception class for Coordinate Reference System related exceptions.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
A geometry is the spatial representation of a feature.
QPolygonF asQPolygonF() const
Returns contents of the geometry as a QPolygonF.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
QgsGeometry difference(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points making up this geometry that do not make up other.
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QgsGeometry intersection(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points shared by this geometry and other.
A collection of map items which are drawn above the map content in a QgsLayoutItemMap.
void addItem(QgsLayoutItemMapItem *item)
Adds a new map item to the stack and takes ownership of the item.
void removeItem(const QString &itemId)
Removes an item which matching itemId from the stack and deletes the corresponding QgsLayoutItemMapIt...
QgsLayoutItemMapItem * item(int index) const
Returns a reference to the item at the specified index within the stack.
void moveItemUp(const QString &itemId)
Moves an item which matching itemId up the stack, causing it to be rendered above other items.
void removeItems()
Clears the item stack and deletes all QgsLayoutItemMapItems contained by the stack.
QList< QgsLayoutItemMapItem * > mItems
void moveItemDown(const QString &itemId)
Moves an item which matching itemId up the stack, causing it to be rendered above other items.
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
@ StackBelowMapLabels
Render above all map layers, but below map labels.
@ StackAboveMapLabels
Render above all map layers and labels.
@ StackBelowMapLayer
Render below a specific map layer (see stackingLayer())
@ StackAboveMapLayer
Render above a specific map layer (see stackingLayer())
@ StackBelowMap
Render below all map layers.
QgsLayoutItemMap * mMap
Associated map.
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...
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...
bool mEnabled
True if item is to be displayed on map.
StackingPosition stackingPosition() const
Returns the item's stacking position, which specifies where the in the map's stack the item should be...
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
const QgsLayoutItemMap * map() const
Returns the layout item map for the item.
QgsMapLayer * stackingLayer() const
Returns the item's stacking layer, which specifies where the in the map's stack the item should be re...
void moveOverviewUp(const QString &overviewId)
Moves an overview with matching overviewId up the stack, causing it to be rendered above other overvi...
QgsLayoutItemMapOverviewStack(QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapOverviewStack, attached to the specified map.
QgsLayoutItemMapOverview & operator[](int index)
Returns a reference to an overview at the specified index within the stack.
void addOverview(QgsLayoutItemMapOverview *overview)
Adds a new map overview to the stack and takes ownership of the overview.
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...
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...
void moveOverviewDown(const QString &overviewId)
Moves an overview with matching overviewId down the stack, causing it to be rendered below other over...
void removeOverview(const QString &overviewId)
Removes an overview with matching overviewId from the stack and deletes the corresponding QgsLayoutIt...
QList< QgsLayoutItemMapOverview * > asList() const
Returns a list of QgsLayoutItemMapOverviews contained by the stack.
QgsLayoutItemMapOverview * overview(const QString &overviewId) const
Returns a reference to an overview with matching overviewId within the stack.
An individual overview which is drawn above the map content in a QgsLayoutItemMap,...
QgsFillSymbol * frameSymbol()
Returns the fill symbol used for drawing the overview extent.
QPainter::CompositionMode blendMode() const
Retrieves the blending mode used for drawing the overview.
bool usesAdvancedEffects() const override
Returns true if the item is drawn using advanced effects, such as blend modes.
void connectSignals()
Reconnects signals for overview map, so that overview correctly follows changes to source map's exten...
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the overview.
QgsMapLayer * mapLayer() override
Returns the internal map layer used by this item, if available.
QgsVectorLayer * asMapLayer()
Returns a vector layer to render as part of the QgsLayoutItemMap render, containing a feature represe...
void draw(QPainter *painter) override
Draws the item on to a destination painter.
void overviewExtentChanged()
Handles recentering of the map and redrawing of the map's overview.
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...
bool centered() const
Returns whether the extent of the map is forced to center on the overview.
~QgsLayoutItemMapOverview() override
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to show the overview extent of.
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
void setFrameSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used for drawing the overview extent.
bool inverted() const
Returns whether the overview frame is inverted, ie, whether the shaded area is drawn outside the exte...
void setInverted(bool inverted)
Sets whether the overview frame is inverted, ie, whether the shaded area is drawn outside the extent ...
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
QgsLayoutItemMapOverview(const QString &name, QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapOverview.
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...
void setCentered(bool centered)
Sets whether the extent of the map is forced to center on the overview.
QgsLayoutItemMap * linkedMap()
Returns the source map to show the overview extent of.
Layout graphical items for displaying a map.
void extentChanged()
Emitted when the map's extent changes.
void mapRotationChanged(double newRotation)
Emitted when the map's rotation changes.
void setExtent(const QgsRectangle &extent)
Sets a new extent for the map.
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation.
void invalidateCache() override
QgsRectangle extent() const
Returns the current map extent.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
const QgsLayout * layout() const
Returns the layout the object is attached to.
QPointer< QgsLayout > mLayout
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
Base class for all map layer types.
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
static Qgis::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a Qgis::BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a Qgis::BlendMode.
A class to represent a 2D point.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
double width() const
Returns the width of the rectangle.
QgsPointXY center() const
Returns the center point of the rectangle.
double height() const
Returns the height of the rectangle.
Contains information about the context of a rendering operation.
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Scoped object for saving and restoring a QPainter object's state.
An interface for classes which can visit style entity (e.g.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
A symbol entity for QgsStyle databases.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
Represents a vector layer which manages a vector based data sets.
Contains information relating to the style entity currently being visited.