27 mUseSymbolV2( false ),
28 mShapeStyleSymbol( 0 ),
46 mUseSymbolV2( false ),
47 mShapeStyleSymbol( 0 ),
93 properties.insert(
"color",
"white" );
94 properties.insert(
"style",
"solid" );
95 properties.insert(
"style_border",
"solid" );
96 properties.insert(
"color_border",
"black" );
97 properties.insert(
"width_border",
"0.3" );
98 properties.insert(
"joinstyle",
"miter" );
109 Q_UNUSED( itemStyle );
135 p->setRenderHint( QPainter::Antialiasing );
140 p->drawEllipse( QRectF( 0, 0 , rect().width(), rect().height() ) );
150 p->drawRect( QRectF( 0, 0 , rect().width(), rect().height() ) );
155 triangle << QPointF( 0, rect().height() );
156 triangle << QPointF( rect().width() , rect().height() );
157 triangle << QPointF( rect().width() / 2.0, 0 );
158 p->drawPolygon( triangle );
167 p->setRenderHint( QPainter::Antialiasing );
170 double dotsPerMM = p->device()->logicalDpiX() / 25.4;
179 p->scale( 1 / dotsPerMM, 1 / dotsPerMM );
182 QList<QPolygonF> rings;
183 QPolygonF shapePolygon;
187 QTransform t = QTransform::fromScale( 100, 100 );
189 QTransform ti = t.inverted();
196 QPainterPath ellipsePath;
197 ellipsePath.addEllipse( QRectF( 0, 0 , rect().width() * dotsPerMM, rect().height() * dotsPerMM ) );
198 QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
199 shapePolygon = ti.map( ellipsePoly );
207 QPainterPath roundedRectPath;
208 roundedRectPath.addRoundedRect( QRectF( 0, 0 , rect().width() * dotsPerMM, rect().height() * dotsPerMM ),
mCornerRadius * dotsPerMM,
mCornerRadius * dotsPerMM );
209 QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t );
210 shapePolygon = ti.map( roundedPoly );
214 shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ) );
220 shapePolygon << QPointF( 0, rect().height() * dotsPerMM );
221 shapePolygon << QPointF( rect().width() * dotsPerMM, rect().height() * dotsPerMM );
222 shapePolygon << QPointF( rect().width() / 2.0 * dotsPerMM, 0 );
223 shapePolygon << QPointF( 0, rect().height() * dotsPerMM );
252 p->setBrush( Qt::NoBrush );
253 p->setRenderHint( QPainter::Antialiasing,
true );
262 p->setBrush( brush() );
263 p->setPen( Qt::NoPen );
264 p->setRenderHint( QPainter::Antialiasing,
true );
276 QDomElement composerShapeElem = doc.createElement(
"ComposerShape" );
277 composerShapeElem.setAttribute(
"shapeType",
mShape );
278 composerShapeElem.setAttribute(
"cornerRadius",
mCornerRadius );
281 composerShapeElem.appendChild( shapeStyleElem );
283 elem.appendChild( composerShapeElem );
284 return _writeXML( composerShapeElem, doc );
290 mCornerRadius = itemElem.attribute(
"cornerRadius",
"0" ).toDouble();
293 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
294 if ( composerItemList.size() > 0 )
296 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
299 if ( composerItemElem.attribute(
"rotation",
"0" ).toDouble() != 0 )
302 setItemRotation( composerItemElem.attribute(
"rotation",
"0" ).toDouble() );
308 QDomElement shapeStyleSymbolElem = itemElem.firstChildElement(
"symbol" );
309 if ( !shapeStyleSymbolElem.isNull() )
322 properties.insert(
"style",
"solid" );
326 properties.insert(
"style",
"no" );
330 properties.insert(
"style_border",
"solid" );
334 properties.insert(
"style_border",
"no" );
337 properties.insert(
"width_border", QString::number( pen().widthF() ) );
340 QDomNodeList outlineColorList = itemElem.elementsByTagName(
"OutlineColor" );
341 if ( outlineColorList.size() > 0 )
343 QDomElement frameColorElem = outlineColorList.at( 0 ).toElement();
344 bool redOk, greenOk, blueOk, alphaOk, widthOk;
345 int penRed, penGreen, penBlue, penAlpha;
348 penWidth = itemElem.attribute(
"outlineWidth" ).toDouble( &widthOk );
349 penRed = frameColorElem.attribute(
"red" ).toDouble( &redOk );
350 penGreen = frameColorElem.attribute(
"green" ).toDouble( &greenOk );
351 penBlue = frameColorElem.attribute(
"blue" ).toDouble( &blueOk );
352 penAlpha = frameColorElem.attribute(
"alpha" ).toDouble( &alphaOk );
354 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
357 properties.insert(
"width_border", QString::number( penWidth ) );
360 QDomNodeList fillColorList = itemElem.elementsByTagName(
"FillColor" );
361 if ( fillColorList.size() > 0 )
363 QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
364 bool redOk, greenOk, blueOk, alphaOk;
365 int fillRed, fillGreen, fillBlue, fillAlpha;
367 fillRed = fillColorElem.attribute(
"red" ).toDouble( &redOk );
368 fillGreen = fillColorElem.attribute(
"green" ).toDouble( &greenOk );
369 fillBlue = fillColorElem.attribute(
"blue" ).toDouble( &blueOk );
370 fillAlpha = fillColorElem.attribute(
"alpha" ).toDouble( &alphaOk );
372 if ( redOk && greenOk && blueOk && alphaOk )
375 properties.insert(
"style",
"solid" );
378 if ( itemElem.hasAttribute(
"transparentFill" ) )
381 bool hasOldTransparentFill = itemElem.attribute(
"transparentFill",
"0" ).toInt();
382 if ( hasOldTransparentFill )
384 properties.insert(
"style",
"no" );
406 QRectF rectangle = rect();
410 prepareGeometryChange();
QRectF mCurrentRectangle
Current bounding rectangle of shape.
void setShapeStyleSymbol(QgsFillSymbolV2 *symbol)
Sets the QgsFillSymbolV2 used to draw the shape.
void setForceVectorOutput(bool force)
Added in QGIS v1.5.
QgsComposition::AtlasMode atlasMode() const
Returns the current atlas mode of the composition.
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
void drawShapeUsingSymbol(QPainter *p)
void updateBoundingRect()
Updates the bounding rect of this item.
Shape mShape
Ellipse, rectangle or triangle.
virtual void drawFrame(QPainter *p)
Draw black frame around item.
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
static QgsFillSymbolV2 * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
A item that forms part of a map composition.
void createDefaultShapeStyleSymbol()
bool enabled() const
Returns whether the atlas generation is enabled.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool writeXML(QDomElement &elem, QDomDocument &doc) const
stores state in Dom element
QMap< QString, QString > QgsStringMap
static QString encodeColor(QColor color)
The QgsMapSettings class contains configuration for rendering of the map.
void itemChanged()
Used e.g.
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
static QDomElement saveSymbol(QString symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
void frameChanged()
Emitted if the item's frame style changes.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint - draw on canvas.
void startRender(QgsRenderContext &context, const QgsFields *fields=0)
virtual void drawSelectionBoxes(QPainter *p)
Draw selection boxes around item.
QgsFillSymbolV2 * mShapeStyleSymbol
void setCornerRadius(double radius)
Sets radius for rounded rectangle corners.
void setUseSymbolV2(bool useSymbolV2)
Controls whether the shape should be drawn using a QgsFillSymbolV2.
bool mFrame
True if item fram needs to be painted.
void drawShape(QPainter *p)
void setPainter(QPainter *p)
static double estimateMaxSymbolBleed(QgsSymbolV2 *symbol)
Returns the maximum estimated bleed for the symbol.
virtual double estimatedFrameBleed() const
reimplement estimatedFrameBleed, since frames on shapes are drawn using symbology rather than the ite...
QgsComposition * mComposition
Graphics scene for map printing.
QgsFeature * currentFeature()
Returns the current atlas feature.
virtual void setItemRotation(double r, bool adjustPosition=false)
Sets the item rotation.
void refreshSymbol()
Should be called after the shape's symbol is changed.
Contains information about the context of a rendering operation.
void stopRender(QgsRenderContext &context)
QRectF boundingRect() const
Depending on the symbol style, the bounding rectangle can be larger than the shape.
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
virtual void drawBackground(QPainter *p)
Draw background.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
bool hasFrame() const
Whether this item has a frame or not.
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
bool hasBackground() const
Whether this item has a Background or not.
QgsAtlasComposition & atlasComposition()
static QgsSymbolV2 * loadSymbol(QDomElement &element)
void setFrameEnabled(bool drawFrame)
Set whether this item has a frame drawn around it or not.
bool mBackground
True if item background needs to be painted.
QgsComposerShape(QgsComposition *composition)
void setSceneRect(const QRectF &rectangle)
Sets new scene rectangle bounds and recalculates hight and extent.