30 , mBlendMode( QPainter::CompositionMode_SourceOver )
34 createDefaultFrameSymbol();
41 , mBlendMode( QPainter::CompositionMode_SourceOver )
47 void QgsComposerMapOverview::createDefaultFrameSymbol()
51 properties.insert(
"color",
"255,0,0,255" );
52 properties.insert(
"style",
"solid" );
53 properties.insert(
"style_border",
"no" );
75 if ( !overviewFrameMap )
86 QPolygonF intersectExtent = thisExtent.intersected( otherExtent );
89 double dotsPerMM = painter->device()->logicalDpiX() / 25.4;
102 painter->setCompositionMode( mBlendMode );
104 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
105 painter->setRenderHint( QPainter::Antialiasing );
111 QTransform mapTransform;
112 QPolygonF thisRectPoly = QPolygonF( QRectF( 0, 0, dotsPerMM *
mComposerMap->rect().width(), dotsPerMM *
mComposerMap->rect().height() ) );
115 thisRectPoly.pop_back();
116 thisExtent.pop_back();
119 QTransform::quadToQuad( thisExtent, thisRectPoly, mapTransform );
120 QPolygonF intersectPolygon;
121 intersectPolygon = mapTransform.map( intersectExtent );
123 QList<QPolygonF> rings;
127 mFrameSymbol->
renderPolygon( intersectPolygon, &rings, 0, context );;
133 QPolygonF outerPolygon;
134 outerPolygon << QPointF( 0, 0 )
135 << QPointF(
mComposerMap->rect().width() * dotsPerMM, 0 )
137 << QPointF( 0,
mComposerMap->rect().height() * dotsPerMM )
141 rings.append( intersectPolygon );
142 mFrameSymbol->
renderPolygon( outerPolygon, &rings, 0, context );
157 QDomElement overviewFrameElem = doc.createElement(
"ComposerMapOverview" );
159 overviewFrameElem.setAttribute(
"frameMap", mFrameMapId );
161 overviewFrameElem.setAttribute(
"inverted", mInverted );
162 overviewFrameElem.setAttribute(
"centered", mCentered );
165 overviewFrameElem.appendChild( frameStyleElem );
168 elem.appendChild( overviewFrameElem );
175 if ( itemElem.isNull() )
182 setFrameMap( itemElem.attribute(
"frameMap",
"-1" ).toInt() );
184 mInverted = ( itemElem.attribute(
"inverted",
"0" ) !=
"0" );
185 mCentered = ( itemElem.attribute(
"centered",
"0" ) !=
"0" );
187 QDomElement frameStyleElem = itemElem.firstChildElement(
"symbol" );
188 if ( !frameStyleElem.isNull() )
191 mFrameSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( frameStyleElem );
198 return mBlendMode != QPainter::CompositionMode_SourceOver;
203 if ( mFrameMapId == mapId )
243 mFrameSymbol = symbol;
275 if ( !overviewFrameMap )
285 center.
y() - extent.
height() / 2,
365 QList< QgsComposerMapOverview* > list;
366 QList< QgsComposerMapItem* >::const_iterator it =
mItems.begin();
367 for ( ; it !=
mItems.end(); ++it )
372 list.append( overview );
383 QDomNodeList mapOverviewNodeList = elem.elementsByTagName(
"ComposerMapOverview" );
384 for (
int i = 0; i < mapOverviewNodeList.size(); ++i )
386 QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
388 mapOverview->
readXML( mapOverviewElem, doc );
389 mItems.append( mapOverview );
void connectSignals()
Reconnects signals for overview map, so that overview correctly follows changes to source map's exten...
void setForceVectorOutput(bool force)
A rectangle specified with double values.
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
void addItem(QgsComposerMapItem *item)
Adds a new map item to the stack and takes ownership of the item.
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
void addOverview(QgsComposerMapOverview *overview)
Adds a new map overview to the stack and takes ownership of the overview.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
QgsComposerMapItem(const QString &name, QgsComposerMap *map)
Constructor for QgsComposerMapItem.
static QgsFillSymbolV2 * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
void cache()
Create cache image.
bool centered() const
Returns whether the extent of the map is forced to center on the overview.
void moveOverviewDown(const QString &overviewId)
Moves an overview down the stack, causing it to be rendered below other overviews.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets overview state from a DOM document.
QMap< QString, QString > QgsStringMap
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
An item which is drawn inside a QgsComposerMap, eg a grid or map overview.
The QgsMapSettings class contains configuration for rendering of the map.
const QgsComposerMapItem * constItem(const QString &itemId) const
Returns a const reference to an item within the stack.
static QDomElement saveSymbol(QString symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
An individual overview which is drawn above the map content in a QgsComposerMap, and shows the extent...
void setFrameSymbol(QgsFillSymbolV2 *symbol)
Sets the fill symbol used for drawing the overview extent.
QPainter::CompositionMode blendMode() const
Retrieves the blending mode used for drawing the overview.
bool mEnabled
True if item is to be displayed on map.
void startRender(QgsRenderContext &context, const QgsFields *fields=0)
QgsComposerMapOverview & operator[](int idx)
Returns a reference to an overview within the stack.
const QgsComposition * composition() const
Returns the composition the item is attached to.
void removeItem(const QString &itemId)
Removes an item from the stack and deletes the corresponding QgsComposerMapItem.
void moveItemUp(const QString &itemId)
Moves an item up the stack, causing it to be rendered above other items.
void setCentered(const bool centered)
Sets whether the extent of the map is forced to center on the overview.
void setPainter(QPainter *p)
void removeOverview(const QString &overviewId)
Removes an overview from the stack and deletes the corresponding QgsComposerMapOverview.
QgsComposerMapOverview(const QString &name, QgsComposerMap *map)
Constructor for QgsComposerMapOverview.
QgsComposerMap * mComposerMap
Associated composer map.
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation...
const QgsComposerMapOverview * constOverview(const QString &overviewId) const
Returns a const reference to an overview within the stack.
A class to represent a point.
QgsComposerMapItem * item(const QString &itemId) const
Returns a reference to an item within the stack.
bool usesAdvancedEffects() const override
Returns true if the item is drawn using advanced effects, such as blend modes.
Object representing map window.
void moveItemDown(const QString &itemId)
Moves an item up the stack, causing it to be rendered above other items.
QgsRectangle * currentMapExtent()
Returns a pointer to the current map extent, which is either the original user specified extent or th...
void draw(QPainter *painter) override
Draws an overview.
static QPainter::CompositionMode getCompositionMode(const QgsMapRenderer::BlendMode &blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
QList< QgsComposerMapItem * > mItems
bool writeXML(QDomElement &elem, QDomDocument &doc) const override
Stores overview state in DOM element.
virtual ~QgsComposerMapOverview()
Contains information about the context of a rendering operation.
QgsComposerMapOverview * overview(const QString &overviewId) const
Returns a reference to an overview within the stack.
void overviewExtentChanged()
Handles recentering of the map and redrawing of the map's overview.
void stopRender(QgsRenderContext &context)
void moveOverviewUp(const QString &overviewId)
Moves an overview up the stack, causing it to be rendered above other overviews.
void setOutputSize(const QSize &size)
Set the size of the resulting map image.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
A collection of map items which are drawn above the map content in a QgsComposerMap.
QList< QgsComposerMapOverview * > asList() const
Returns a list of QgsComposerMapOverviews contained by the stack.
void setExtent(const QgsRectangle &rect)
Set coordinates of the rectangle which should be rendered.
void setInverted(const bool inverted)
Sets whether the overview frame is inverted, ie, whether the shaded area is drawn outside the extent ...
void setFrameMap(const int mapId)
Sets overview frame map.
virtual void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties) override
virtual ~QgsComposerMapOverviewStack()
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets map item state from a DOM document.
static QgsMapRenderer::BlendMode getBlendModeEnum(const QPainter::CompositionMode &blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
void removeItems()
Clears the item stack and deletes all QgsComposerMapItems contained by the stack. ...
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
double width() const
Width of the rectangle.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const override
Stores map item state in DOM element.
QgsComposerMapOverviewStack(QgsComposerMap *map)
Constructor for QgsComposerMapOverviewStack.
QgsPoint center() const
Center point of the rectangle.
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
bool readXML(const QDomElement &elem, const QDomDocument &doc) override
Sets the overview stack's state from a DOM document.
void setBlendMode(const QPainter::CompositionMode blendMode)
Sets the blending mode used for drawing the overview.
double height() const
Height of the rectangle.
QgsComposerMap * mComposerMap
bool inverted() const
Returns whether the overview frame is inverted, ie, whether the shaded area is drawn outside the exte...