28 mUseSymbolV2( false ),
29 mShapeStyleSymbol( 0 ),
33 createDefaultShapeStyleSymbol();
47 mUseSymbolV2( false ),
48 mShapeStyleSymbol( 0 ),
53 createDefaultShapeStyleSymbol();
65 delete mShapeStyleSymbol;
70 mUseSymbolV2 = useSymbolV2;
76 delete mShapeStyleSymbol;
77 mShapeStyleSymbol = symbol;
90 void QgsComposerShape::createDefaultShapeStyleSymbol()
92 delete mShapeStyleSymbol;
94 properties.insert(
"color",
"white" );
95 properties.insert(
"style",
"solid" );
96 properties.insert(
"style_border",
"solid" );
97 properties.insert(
"color_border",
"black" );
98 properties.insert(
"width_border",
"0.3" );
99 properties.insert(
"joinstyle",
"miter" );
103 updateBoundingRect();
110 Q_UNUSED( itemStyle );
131 void QgsComposerShape::drawShape( QPainter* p )
135 drawShapeUsingSymbol( p );
141 p->setRenderHint( QPainter::Antialiasing );
146 p->drawEllipse( QRectF( 0, 0, rect().width(), rect().height() ) );
150 if ( mCornerRadius > 0 )
152 p->drawRoundedRect( QRectF( 0, 0, rect().width(), rect().height() ), mCornerRadius, mCornerRadius );
156 p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
161 triangle << QPointF( 0, rect().height() );
162 triangle << QPointF( rect().width(), rect().height() );
163 triangle << QPointF( rect().width() / 2.0, 0 );
164 p->drawPolygon( triangle );
170 void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
173 p->setRenderHint( QPainter::Antialiasing );
176 double dotsPerMM = p->device()->logicalDpiX() / 25.4;
185 p->scale( 1 / dotsPerMM, 1 / dotsPerMM );
188 QList<QPolygonF> rings;
189 QPolygonF shapePolygon;
193 QTransform t = QTransform::fromScale( 100, 100 );
195 QTransform ti = t.inverted();
202 QPainterPath ellipsePath;
203 ellipsePath.addEllipse( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ) );
204 QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
205 shapePolygon = ti.map( ellipsePoly );
211 if ( mCornerRadius > 0 )
213 QPainterPath roundedRectPath;
214 roundedRectPath.addRoundedRect( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ), mCornerRadius * dotsPerMM, mCornerRadius * dotsPerMM );
215 QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t );
216 shapePolygon = ti.map( roundedPoly );
220 shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ) );
226 shapePolygon << QPointF( 0, rect().height() * dotsPerMM );
227 shapePolygon << QPointF( rect().width() * dotsPerMM, rect().height() * dotsPerMM );
228 shapePolygon << QPointF( rect().width() / 2.0 * dotsPerMM, 0 );
229 shapePolygon << QPointF( 0, rect().height() * dotsPerMM );
245 mShapeStyleSymbol->
renderPolygon( shapePolygon, &rings, 0, context );
255 if (
mFrame && p && !mUseSymbolV2 )
258 p->setBrush( Qt::NoBrush );
259 p->setRenderHint( QPainter::Antialiasing,
true );
268 p->setBrush( brush() );
269 p->setPen( Qt::NoPen );
270 p->setRenderHint( QPainter::Antialiasing,
true );
277 return mMaxSymbolBleed;
282 QDomElement composerShapeElem = doc.createElement(
"ComposerShape" );
283 composerShapeElem.setAttribute(
"shapeType", mShape );
284 composerShapeElem.setAttribute(
"cornerRadius", mCornerRadius );
287 composerShapeElem.appendChild( shapeStyleElem );
289 elem.appendChild( composerShapeElem );
290 return _writeXML( composerShapeElem, doc );
296 mCornerRadius = itemElem.attribute(
"cornerRadius",
"0" ).toDouble();
299 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
300 if ( composerItemList.size() > 0 )
302 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
305 if ( composerItemElem.attribute(
"rotation",
"0" ).toDouble() != 0 )
308 setItemRotation( composerItemElem.attribute(
"rotation",
"0" ).toDouble() );
314 QDomElement shapeStyleSymbolElem = itemElem.firstChildElement(
"symbol" );
315 if ( !shapeStyleSymbolElem.isNull() )
317 delete mShapeStyleSymbol;
318 mShapeStyleSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( shapeStyleSymbolElem );
323 delete mShapeStyleSymbol;
328 properties.insert(
"style",
"solid" );
332 properties.insert(
"style",
"no" );
336 properties.insert(
"style_border",
"solid" );
340 properties.insert(
"style_border",
"no" );
343 properties.insert(
"width_border", QString::number( pen().widthF() ) );
346 QDomNodeList outlineColorList = itemElem.elementsByTagName(
"OutlineColor" );
347 if ( outlineColorList.size() > 0 )
349 QDomElement frameColorElem = outlineColorList.at( 0 ).toElement();
350 bool redOk, greenOk, blueOk, alphaOk, widthOk;
351 int penRed, penGreen, penBlue, penAlpha;
354 penWidth = itemElem.attribute(
"outlineWidth" ).toDouble( &widthOk );
355 penRed = frameColorElem.attribute(
"red" ).toDouble( &redOk );
356 penGreen = frameColorElem.attribute(
"green" ).toDouble( &greenOk );
357 penBlue = frameColorElem.attribute(
"blue" ).toDouble( &blueOk );
358 penAlpha = frameColorElem.attribute(
"alpha" ).toDouble( &alphaOk );
360 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
363 properties.insert(
"width_border", QString::number( penWidth ) );
366 QDomNodeList fillColorList = itemElem.elementsByTagName(
"FillColor" );
367 if ( fillColorList.size() > 0 )
369 QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
370 bool redOk, greenOk, blueOk, alphaOk;
371 int fillRed, fillGreen, fillBlue, fillAlpha;
373 fillRed = fillColorElem.attribute(
"red" ).toDouble( &redOk );
374 fillGreen = fillColorElem.attribute(
"green" ).toDouble( &greenOk );
375 fillBlue = fillColorElem.attribute(
"blue" ).toDouble( &blueOk );
376 fillAlpha = fillColorElem.attribute(
"alpha" ).toDouble( &alphaOk );
378 if ( redOk && greenOk && blueOk && alphaOk )
381 properties.insert(
"style",
"solid" );
384 if ( itemElem.hasAttribute(
"transparentFill" ) )
387 bool hasOldTransparentFill = itemElem.attribute(
"transparentFill",
"0" ).toInt();
388 if ( hasOldTransparentFill )
390 properties.insert(
"style",
"no" );
418 mCornerRadius = radius;
423 return mCurrentRectangle;
426 void QgsComposerShape::updateBoundingRect()
428 QRectF rectangle = rect();
429 rectangle.adjust( -mMaxSymbolBleed, -mMaxSymbolBleed, mMaxSymbolBleed, mMaxSymbolBleed );
430 if ( rectangle != mCurrentRectangle )
432 prepareGeometryChange();
433 mCurrentRectangle = rectangle;
445 updateBoundingRect();
451 if ( !
id().isEmpty() )
459 return tr(
"<ellipse>" );
462 return tr(
"<rectangle>" );
465 return tr(
"<triangle>" );
469 return tr(
"<shape>" );
void setShapeStyleSymbol(QgsFillSymbolV2 *symbol)
Sets the QgsFillSymbolV2 used to draw the shape.
void setForceVectorOutput(bool force)
void setShapeType(QgsComposerShape::Shape s)
QgsComposition::AtlasMode atlasMode() const
Returns the current atlas mode of the composition.
void setSceneRect(const QRectF &rectangle) override
Sets new scene rectangle bounds and recalculates hight and extent.
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
virtual QString displayName() const override
Get item display name.
QgsComposerModel * itemsModel()
Returns the items model attached to the composition.
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
void itemChanged()
Emitted when the item changes.
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.
bool enabled() const
Returns whether the atlas generation is enabled.
virtual void setFrameEnabled(const bool drawFrame)
Set whether this item has a frame drawn around it or not.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QMap< QString, QString > QgsStringMap
virtual void drawBackground(QPainter *p) override
Draw background.
void updateItemDisplayName(QgsComposerItem *item)
Must be called when an item's display name is modified.
static QString encodeColor(QColor color)
The QgsMapSettings class contains configuration for rendering of the map.
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 startRender(QgsRenderContext &context, const QgsFields *fields=0)
virtual void drawSelectionBoxes(QPainter *p)
Draws additional graphics on selected items.
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.
const QgsComposition * composition() const
Returns the composition the item is attached to.
virtual void drawFrame(QPainter *p) override
Draw black frame around item.
void setPainter(QPainter *p)
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
static double estimateMaxSymbolBleed(QgsSymbolV2 *symbol)
Returns the maximum estimated bleed for the symbol.
Graphics scene for map printing.
QgsFeature * currentFeature()
Returns the current atlas feature.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
sets state from Dom document
void refreshSymbol()
Should be called after the shape's symbol is changed.
bool writeXML(QDomElement &elem, QDomDocument &doc) const override
stores state in Dom element
QgsComposition * mComposition
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false)
Evaluates an item's bounding rect to consider data defined position and size of item and reference po...
Contains information about the context of a rendering operation.
void stopRender(QgsRenderContext &context)
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
virtual void setItemRotation(const double r, const bool adjustPosition=false)
Sets the item rotation.
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.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Reimplementation of QCanvasItem::paint - draw on canvas.
QgsAtlasComposition & atlasComposition()
bool mBackground
True if item background needs to be painted.
virtual double estimatedFrameBleed() const override
reimplement estimatedFrameBleed, since frames on shapes are drawn using symbology rather than the ite...
QRectF boundingRect() const override
Depending on the symbol style, the bounding rectangle can be larger than the shape.
QgsComposerShape(QgsComposition *composition)
QString id() const
Get item's id (which is not necessarly unique)