36#include "moc_qgslayoutitemmapoverview.cpp"
38using namespace Qt::StringLiterals;
44 createDefaultFrameSymbol();
49void QgsLayoutItemMapOverview::createDefaultFrameSymbol()
51 QVariantMap properties;
52 properties.insert( u
"color"_s, u
"255,0,0,75"_s );
53 properties.insert( u
"style"_s, u
"solid"_s );
54 properties.insert( u
"style_border"_s, u
"no"_s );
72 if ( !overviewFrameMap )
79 if ( overviewFrameMap->
crs() !=
100 QPolygonF thisExtent =
mMap->visibleExtentPolygon();
102 QPolygonF intersectExtent = thisExtent.intersected( otherExtent );
105 double dotsPerMM = painter->device()->logicalDpiX() / 25.4;
117 painter->setCompositionMode( mBlendMode );
118 painter->translate(
mMap->mXOffset,
mMap->mYOffset );
119 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
121 mFrameSymbol->startRender( context );
125 QTransform mapTransform;
126 QPolygonF thisRectPoly = QPolygonF( QRectF( 0, 0, dotsPerMM *
mMap->rect().width(), dotsPerMM *
mMap->rect().height() ) );
129 thisRectPoly.pop_back();
130 thisExtent.pop_back();
133 QTransform::quadToQuad( thisExtent, thisRectPoly, mapTransform );
134 QPolygonF intersectPolygon;
135 intersectPolygon = mapTransform.map( intersectExtent );
137 QVector<QPolygonF> rings;
141 mFrameSymbol->renderPolygon( intersectPolygon, &rings,
nullptr, context );
147 QPolygonF outerPolygon;
148 outerPolygon << QPointF( 0, 0 )
149 << QPointF(
mMap->rect().width() * dotsPerMM, 0 )
150 << QPointF(
mMap->rect().width() * dotsPerMM,
mMap->rect().height() * dotsPerMM )
151 << QPointF( 0,
mMap->rect().height() * dotsPerMM )
155 rings.append( intersectPolygon );
156 mFrameSymbol->renderPolygon( outerPolygon, &rings,
nullptr, context );
159 mFrameSymbol->stopRender( context );
170 QDomElement overviewFrameElem = doc.createElement( u
"ComposerMapOverview"_s );
172 overviewFrameElem.setAttribute( u
"frameMap"_s, mFrameMap ? mFrameMap ->uuid() : QString() );
174 overviewFrameElem.setAttribute( u
"inverted"_s, mInverted );
175 overviewFrameElem.setAttribute( u
"centered"_s, mCentered );
178 overviewFrameElem.appendChild( frameStyleElem );
181 elem.appendChild( overviewFrameElem );
188 if ( itemElem.isNull() )
195 mFrameMapUuid = itemElem.attribute( u
"frameMap"_s );
199 mInverted = ( itemElem.attribute( u
"inverted"_s, u
"0"_s ) !=
"0"_L1 );
200 mCentered = ( itemElem.attribute( u
"centered"_s, u
"0"_s ) !=
"0"_L1 );
202 QDomElement frameStyleElem = itemElem.firstChildElement( u
"symbol"_s );
203 if ( !frameStyleElem.isNull() )
212 if ( !mFrameMapUuid.isEmpty() )
214 setLinkedMap( qobject_cast< QgsLayoutItemMap * >(
mLayout->itemByUuid( mFrameMapUuid,
true ) ) );
220 return mBlendMode != QPainter::CompositionMode_SourceOver;
225 if ( mFrameMap ==
map )
240 mMap->invalidateCache();
270 if ( !overviewFrameMap )
279 if ( overviewFrameMap->
crs() !=
mMap->crs() )
295 QPolygonF thisExtent =
mMap->visibleExtentPolygon();
300 mExtentLayer->setBlendMode( mBlendMode );
303 mExtentLayer->dataProvider()->truncate();
304 mExtentLayer->setCrs(
mMap->crs() );
308 intersectExtent = thisGeom.
difference( intersectExtent );
313 mExtentLayer->dataProvider()->addFeature( f );
315 return mExtentLayer.get();
320 return mExtentLayer.get();
337 mFrameSymbol.reset( symbol );
342 return mFrameSymbol.get();
347 return mFrameSymbol.get();
374 if (
mMap->layout() && mCentered && mFrameMap )
381 center.
y() - extent.
height() / 2,
384 mMap->setExtent( movedExtent );
388 mMap->invalidateCache();
425 return qobject_cast<QgsLayoutItemMapOverview *>(
item );
431 return qobject_cast<QgsLayoutItemMapOverview *>(
item );
443 QList< QgsLayoutItemMapOverview * > list;
444 QList< QgsLayoutItemMapItem * >::const_iterator it =
mItems.begin();
445 for ( ; it !=
mItems.end(); ++it )
461 QDomNodeList mapOverviewNodeList = elem.elementsByTagName( u
"ComposerMapOverview"_s );
462 for (
int i = 0; i < mapOverviewNodeList.size(); ++i )
464 QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
466 mapOverview->
readXml( mapOverviewElem, doc, context );
467 mItems.append( mapOverview );
475 QList<QgsMapLayer *> res = layers;
476 res.reserve( layers.count() +
mItems.count() );
488 switch (
item->stackingPosition() )
500 auto pos = std::find( res.begin(), res.end(), stackLayer );
501 if ( pos == res.end() )
507 if ( pos == res.end() )
513 res.insert( pos, l );
@ Default
Allow raster-based rendering in situations where it is required for correct rendering or where it wil...
@ PreferVector
Prefer vector-based rendering, when the result will still be visually near-identical to a raster-base...
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 std::unique_ptr< 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.
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.
QgsLayoutItemMapItemStack(QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapItemStack, attached to the specified map.
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.
QString name() const
Returns the friendly display name for the item.
QgsLayoutItemMapItem(const QString &name, QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapItem, attached to the specified map.
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.
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.
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation.
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 container for the context for various read/write operations on objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
void setRasterizedRenderingPolicy(Qgis::RasterizedRenderingPolicy policy)
Sets the policy controlling when rasterisation of content during renders is permitted.
Qgis::RasterizedRenderingPolicy rasterizedRenderingPolicy() const
Returns the policy controlling when rasterisation of content during renders is permitted.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Scoped object for saving and restoring a QPainter object's state.
A feature renderer which renders all features with the same symbol.
void setSymbol(QgsSymbol *s)
Sets the symbol which will be rendered for every feature.
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 std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
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 dataset.
Contains information relating to the style entity currently being visited.