35 createDefaultFrameSymbol();
38 void QgsLayoutItemMapOverview::createDefaultFrameSymbol()
41 properties.insert( QStringLiteral(
"color" ), QStringLiteral(
"255,0,0,75" ) );
42 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
43 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"no" ) );
59 if ( !overviewFrameMap )
66 if ( overviewFrameMap->
crs() !=
83 otherExtent = g.asQPolygonF();
89 QPolygonF intersectExtent = thisExtent.intersected( otherExtent );
92 double dotsPerMM = painter->device()->logicalDpiX() / 25.4;
101 painter->setCompositionMode( mBlendMode );
102 painter->translate(
mMap->mXOffset,
mMap->mYOffset );
103 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
104 painter->setRenderHint( QPainter::Antialiasing );
106 mFrameSymbol->startRender( context );
110 QTransform mapTransform;
111 QPolygonF thisRectPoly = QPolygonF( QRectF( 0, 0, dotsPerMM *
mMap->rect().width(), dotsPerMM *
mMap->rect().height() ) );
114 thisRectPoly.pop_back();
115 thisExtent.pop_back();
118 QTransform::quadToQuad( thisExtent, thisRectPoly, mapTransform );
119 QPolygonF intersectPolygon;
120 intersectPolygon = mapTransform.map( intersectExtent );
122 QList<QPolygonF> rings;
126 mFrameSymbol->renderPolygon( intersectPolygon, &rings,
nullptr, context );
132 QPolygonF outerPolygon;
133 outerPolygon << QPointF( 0, 0 )
134 << QPointF(
mMap->rect().width() * dotsPerMM, 0 )
135 << QPointF(
mMap->rect().width() * dotsPerMM,
mMap->rect().height() * dotsPerMM )
136 << QPointF( 0,
mMap->rect().height() * dotsPerMM )
140 rings.append( intersectPolygon );
141 mFrameSymbol->renderPolygon( outerPolygon, &rings,
nullptr, context );
144 mFrameSymbol->stopRender( context );
156 QDomElement overviewFrameElem = doc.createElement( QStringLiteral(
"ComposerMapOverview" ) );
158 overviewFrameElem.setAttribute( QStringLiteral(
"frameMap" ), mFrameMap ? mFrameMap ->uuid() : QString() );
160 overviewFrameElem.setAttribute( QStringLiteral(
"inverted" ), mInverted );
161 overviewFrameElem.setAttribute( QStringLiteral(
"centered" ), mCentered );
164 overviewFrameElem.appendChild( frameStyleElem );
167 elem.appendChild( overviewFrameElem );
174 if ( itemElem.isNull() )
181 mFrameMapUuid = itemElem.attribute( QStringLiteral(
"frameMap" ) );
184 mBlendMode =
QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( itemElem.attribute( QStringLiteral(
"blendMode" ), QStringLiteral(
"0" ) ).toUInt() ) );
185 mInverted = ( itemElem.attribute( QStringLiteral(
"inverted" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
186 mCentered = ( itemElem.attribute( QStringLiteral(
"centered" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
188 QDomElement frameStyleElem = itemElem.firstChildElement( QStringLiteral(
"symbol" ) );
189 if ( !frameStyleElem.isNull() )
191 mFrameSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( frameStyleElem, context ) );
198 if ( !mFrameMapUuid.isEmpty() )
200 setLinkedMap( qobject_cast< QgsLayoutItemMap * >(
mLayout->itemByUuid( mFrameMapUuid,
true ) ) );
206 return mBlendMode != QPainter::CompositionMode_SourceOver;
211 if ( mFrameMap == map )
250 mFrameSymbol.reset( symbol );
255 return mFrameSymbol.get();
260 return mFrameSymbol.get();
287 if (
mMap->
layout() && mCentered && mFrameMap )
294 center.
y() - extent.
height() / 2,
359 QList< QgsLayoutItemMapOverview * > list;
360 QList< QgsLayoutItemMapItem * >::const_iterator it =
mItems.begin();
361 for ( ; it !=
mItems.end(); ++it )
366 list.append( overview );
377 QDomNodeList mapOverviewNodeList = elem.elementsByTagName( QStringLiteral(
"ComposerMapOverview" ) );
378 for (
int i = 0; i < mapOverviewNodeList.size(); ++i )
380 QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
382 mapOverview->
readXml( mapOverviewElem, doc, context );
383 mItems.append( mapOverview );
void setForceVectorOutput(bool force)
The class is used as a container of context for various read/write operations on other objects...
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to show the overview extent of.
A rectangle specified with double values.
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects' current state.
void moveOverviewUp(const QString &overviewId)
Moves an overview with matching overviewId up the stack, causing it to be rendered above other overvi...
void setFrameSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used for drawing the overview extent.
An individual overview which is drawn above the map content in a QgsLayoutItemMap, and shows the extent of another QgsLayoutItemMap.
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.
void setInverted(bool inverted)
Sets whether the overview frame is inverted, ie, whether the shaded area is drawn outside the extent ...
void setExtent(const QgsRectangle &extent)
Sets a new extent for the map.
QgsLayoutItemMapOverview(const QString &name, QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapOverview.
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
static QgsFillSymbol * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
A class to represent a 2D point.
void extentChanged()
Is emitted when the map's extent changes.
void draw(QPainter *painter) override
Draws the item on to a destination painter.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
A collection of map items which are drawn above the map content in a QgsLayoutItemMap.
A geometry is the spatial representation of a feature.
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...
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
QList< QgsLayoutItemMapOverview *> asList() const
Returns a list of QgsLayoutItemMapOverviews contained by the stack.
void invalidateCache() override
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
QgsFillSymbol * frameSymbol()
Returns the fill symbol used for drawing the overview extent.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the overview.
QMap< QString, QString > QgsStringMap
void connectSignals()
Reconnects signals for overview map, so that overview correctly follows changes to source map's exten...
void removeItems()
Clears the item stack and deletes all QgsLayoutItemMapItems contained by the stack.
QgsLayoutItemMapOverview * overview(const QString &overviewId) const
Returns a reference to an overview with matching overviewId within the stack.
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.
QgsLayoutItemMap * mMap
Associated map.
bool inverted() const
Returns whether the overview frame is inverted, ie, whether the shaded area is drawn outside the exte...
bool mEnabled
True if item is to be displayed on map.
QgsRectangle extent() const
Returns the current map extent.
Layout graphical items for displaying a map.
const QgsLayout * layout() const
Returns the layout the object is attached to.
double width() const
Returns the width of the rectangle.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Returns a copy of the geometry which has been densified by adding the specified number of extra nodes...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
QPointer< QgsLayout > mLayout
void moveOverviewDown(const QString &overviewId)
Moves an overview with matching overviewId down the stack, causing it to be rendered below other over...
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...
void moveItemUp(const QString &itemId)
Moves an item which matching itemId up the stack, causing it to be rendered above other items...
void setCentered(bool centered)
Sets whether the extent of the map is forced to center on the overview.
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation...
void mapRotationChanged(double newRotation)
Is emitted when the map's rotation changes.
const QgsLayoutItemMap * map() const
Returns the layout item map for the item.
QgsLayoutItemMapOverviewStack(QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapOverviewStack, attached to the specified 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...
void removeOverview(const QString &overviewId)
Removes an overview with matching overviewId from the stack and deletes the corresponding QgsLayoutIt...
Contains information about the context of a rendering operation.
void overviewExtentChanged()
Handles recentering of the map and redrawing of the map's overview.
bool usesAdvancedEffects() const override
Returns true if the item is drawn using advanced effects, such as blend modes.
QgsLayoutItemMapItem * item(const QString &itemId) const
Returns a reference to an item which matching itemId within the stack.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
static QDomElement saveSymbol(const QString &symbolName, QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
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...
Custom exception class for Coordinate Reference System related exceptions.
QgsPointXY center() const
Returns the center point of the rectangle.
void moveItemDown(const QString &itemId)
Moves an item which matching itemId up the stack, causing it to be rendered above other items...
QList< QgsLayoutItemMapItem *> mItems
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...
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
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...
double height() const
Returns the height of the rectangle.
QgsLayoutItemMap * linkedMap()
Returns the source map to show the overview extent of.