QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
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() ) ) )
40 createDefaultFrameSymbol();
45 void QgsLayoutItemMapOverview::createDefaultFrameSymbol()
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" ) );
68 if ( !overviewFrameMap )
75 if ( overviewFrameMap->
crs() !=
98 QPolygonF intersectExtent = thisExtent.intersected( otherExtent );
101 double dotsPerMM = painter->device()->logicalDpiX() / 25.4;
112 painter->setCompositionMode( mBlendMode );
113 painter->translate(
mMap->mXOffset,
mMap->mYOffset );
114 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
116 mFrameSymbol->startRender( context );
120 QTransform mapTransform;
121 QPolygonF thisRectPoly = QPolygonF( QRectF( 0, 0, dotsPerMM *
mMap->rect().width(), dotsPerMM *
mMap->rect().height() ) );
124 thisRectPoly.pop_back();
125 thisExtent.pop_back();
128 QTransform::quadToQuad( thisExtent, thisRectPoly, mapTransform );
129 QPolygonF intersectPolygon;
130 intersectPolygon = mapTransform.map( intersectExtent );
132 QVector<QPolygonF> rings;
136 mFrameSymbol->renderPolygon( intersectPolygon, &rings,
nullptr, context );
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 )
150 rings.append( intersectPolygon );
151 mFrameSymbol->renderPolygon( outerPolygon, &rings,
nullptr, context );
154 mFrameSymbol->stopRender( context );
165 QDomElement overviewFrameElem = doc.createElement( QStringLiteral(
"ComposerMapOverview" ) );
167 overviewFrameElem.setAttribute( QStringLiteral(
"frameMap" ), mFrameMap ? mFrameMap ->uuid() : QString() );
169 overviewFrameElem.setAttribute( QStringLiteral(
"inverted" ), mInverted );
170 overviewFrameElem.setAttribute( QStringLiteral(
"centered" ), mCentered );
173 overviewFrameElem.appendChild( frameStyleElem );
176 elem.appendChild( overviewFrameElem );
183 if ( itemElem.isNull() )
190 mFrameMapUuid = itemElem.attribute( QStringLiteral(
"frameMap" ) );
194 mInverted = ( itemElem.attribute( QStringLiteral(
"inverted" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
195 mCentered = ( itemElem.attribute( QStringLiteral(
"centered" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
197 QDomElement frameStyleElem = itemElem.firstChildElement( QStringLiteral(
"symbol" ) );
198 if ( !frameStyleElem.isNull() )
200 mFrameSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( frameStyleElem, context ) );
207 if ( !mFrameMapUuid.isEmpty() )
209 setLinkedMap( qobject_cast< QgsLayoutItemMap * >(
mLayout->itemByUuid( mFrameMapUuid,
true ) ) );
215 return mBlendMode != QPainter::CompositionMode_SourceOver;
220 if ( mFrameMap ==
map )
265 if ( !overviewFrameMap )
295 mExtentLayer->setBlendMode( mBlendMode );
298 mExtentLayer->dataProvider()->truncate();
299 mExtentLayer->setCrs(
mMap->
crs() );
303 intersectExtent = thisGeom.
difference( intersectExtent );
308 mExtentLayer->dataProvider()->addFeature( f );
310 return mExtentLayer.get();
315 return mExtentLayer.get();
332 mFrameSymbol.reset( symbol );
337 return mFrameSymbol.get();
342 return mFrameSymbol.get();
369 if (
mMap->
layout() && mCentered && mFrameMap )
376 center.
y() - extent.
height() / 2,
420 return qobject_cast<QgsLayoutItemMapOverview *>(
item );
426 return qobject_cast<QgsLayoutItemMapOverview *>(
item );
438 QList< QgsLayoutItemMapOverview * > list;
439 QList< QgsLayoutItemMapItem * >::const_iterator it =
mItems.begin();
440 for ( ; it !=
mItems.end(); ++it )
456 QDomNodeList mapOverviewNodeList = elem.elementsByTagName( QStringLiteral(
"ComposerMapOverview" ) );
457 for (
int i = 0; i < mapOverviewNodeList.size(); ++i )
459 QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
461 mapOverview->
readXml( mapOverviewElem, doc, context );
462 mItems.append( mapOverview );
470 QList<QgsMapLayer *> res = layers;
471 res.reserve( layers.count() +
mItems.count() );
481 l->
setCustomProperty( QStringLiteral(
"_noset_layer_expression_context" ), true );
495 auto pos = std::find( res.begin(), res.end(), stackLayer );
496 if ( pos == res.end() )
502 if ( pos == res.end() )
508 res.insert( pos, l );
QgsLayoutItemMapOverviewStack(QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapOverviewStack, attached to the specified map.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
const QgsLayout * layout() const
Returns the layout the object is attached to.
@ StackAboveMapLayer
Render above a specific map layer (see stackingLayer())
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
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 finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
Contains information about the context in which a coordinate transform is executed.
void addOverview(QgsLayoutItemMapOverview *overview)
Adds a new map overview to the stack and takes ownership of the overview.
@ StackBelowMapLayer
Render below a specific map layer (see stackingLayer())
void overviewExtentChanged()
Handles recentering of the map and redrawing of the map's overview.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
The class is used as a container of context for various read/write operations on other objects.
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.
A symbol entity for QgsStyle databases.
void moveOverviewDown(const QString &overviewId)
Moves an overview with matching overviewId down the stack, causing it to be rendered below other over...
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
void extentChanged()
Emitted when the map's extent changes.
void setInverted(bool inverted)
Sets whether the overview frame is inverted, ie, whether the shaded area is drawn outside the extent ...
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to show the overview extent of.
const QgsLayoutItemMap * map() const
Returns the layout item map for the item.
Contains information about the context of a rendering operation.
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
A collection of map items which are drawn above the map content in a QgsLayoutItemMap....
void removeItems()
Clears the item stack and deletes all QgsLayoutItemMapItems contained by the stack.
@ StackBelowMap
Render below all map layers.
void setFrameSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used for drawing the overview extent.
void draw(QPainter *painter) override
Draws the item on to a destination painter.
A rectangle specified with double values.
Contains information relating to the style entity currently being visited.
bool inverted() const
Returns whether the overview frame is inverted, ie, whether the shaded area is drawn outside the exte...
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
QgsVectorLayer * asMapLayer()
Returns a vector layer to render as part of the QgsLayoutItemMap render, containing a feature represe...
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
void setCentered(bool centered)
Sets whether the extent of the map is forced to center on the overview.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the overview.
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
QgsLayoutItemMapOverview * overview(const QString &overviewId) const
Returns a reference to an overview with matching overviewId within the stack.
QList< QgsLayoutItemMapOverview * > asList() const
Returns a list of QgsLayoutItemMapOverviews contained by the stack.
bool mEnabled
True if item is to be displayed on map.
QPolygonF asQPolygonF() const SIP_HOLDGIL
Returns contents of the geometry as a QPolygonF.
QgsLayoutItemMap * linkedMap()
Returns the source map to show the overview extent of.
Custom exception class for Coordinate Reference System related exceptions.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
QgsMapLayer * stackingLayer() const
Returns the item's stacking layer, which specifies where the in the map's stack the item should be re...
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
QgsLayoutItemMap * mMap
Associated map.
bool centered() const
Returns whether the extent of the map is forced to center on the overview.
void removeItem(const QString &itemId)
Removes an item which matching itemId from the stack and deletes the corresponding QgsLayoutItemMapIt...
~QgsLayoutItemMapOverview() override
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
QgsRectangle extent() const
Returns the current map extent.
void invalidateCache() override
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...
Scoped object for saving and restoring a QPainter object's state.
@ StackBelowMapLabels
Render above all map layers, but below map labels.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
void moveItemDown(const QString &itemId)
Moves an item which matching itemId up the stack, causing it to be rendered above other items.
QgsLayoutItemMapOverview(const QString &name, QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapOverview.
A class to represent a 2D point.
An individual overview which is drawn above the map content in a QgsLayoutItemMap,...
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
Layout graphical items for displaying a map.
QList< QgsLayoutItemMapItem * > mItems
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...
QgsMapLayer * mapLayer() override
Returns the internal map layer used by this item, if available.
StackingPosition stackingPosition() const
Returns the item's stacking position, which specifies where the in the map's stack the item should be...
void connectSignals()
Reconnects signals for overview map, so that overview correctly follows changes to source map's exten...
QPointer< QgsLayout > mLayout
A geometry is the spatial representation of a feature.
@ StackAboveMapLabels
Render above all map layers and labels.
Represents a vector layer which manages a vector based data sets.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
void mapRotationChanged(double newRotation)
Emitted when the map's rotation changes.
Base class for all map layer types. This is the base class for all map layer types (vector,...
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...
void removeOverview(const QString &overviewId)
Removes an overview with matching overviewId from the stack and deletes the corresponding QgsLayoutIt...
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
void moveItemUp(const QString &itemId)
Moves an item which matching itemId up the stack, causing it to be rendered above other items.
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...
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsLayoutItemMapItem * item(int index) const
Returns a reference to the item at the specified index within the stack.
QgsFillSymbol * frameSymbol()
Returns the fill symbol used for drawing the overview extent.
void addItem(QgsLayoutItemMapItem *item)
Adds a new map item to the stack and takes ownership of the item.
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 setExtent(const QgsRectangle &extent)
Sets a new extent for the map.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other.
QgsLayoutItemMapOverview & operator[](int index)
Returns a reference to an overview at the specified index within the stack.
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...
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation.
void moveOverviewUp(const QString &overviewId)
Moves an overview with matching overviewId up the stack, causing it to be rendered above other overvi...