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;
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 );
150 if ( mCornerRadius > 0 )
170 void QgsComposerShape::drawShapeUsingSymbol(
QPainter* p )
187 delete expressionContext;
189 p->
scale( 1 / dotsPerMM, 1 / dotsPerMM );
209 shapePolygon = ti.
map( ellipsePoly );
215 if ( mCornerRadius > 0 )
218 roundedRectPath.
addRoundedRect(
QRectF( 0, 0,
rect().width() * dotsPerMM,
rect().height() * dotsPerMM ), mCornerRadius * dotsPerMM, mCornerRadius * dotsPerMM );
220 shapePolygon = ti.
map( roundedPoly );
230 shapePolygon <<
QPointF( 0,
rect().height() * dotsPerMM );
231 shapePolygon <<
QPointF(
rect().width() * dotsPerMM,
rect().height() * dotsPerMM );
232 shapePolygon <<
QPointF(
rect().width() / 2.0 * dotsPerMM, 0 );
233 shapePolygon <<
QPointF( 0,
rect().height() * dotsPerMM );
239 mShapeStyleSymbol->
renderPolygon( shapePolygon, &rings, 0, context );
248 if (
mFrame && p && !mUseSymbolV2 )
270 return mMaxSymbolBleed;
277 composerShapeElem.
setAttribute(
"cornerRadius", mCornerRadius );
283 return _writeXML( composerShapeElem, doc );
293 if ( composerItemList.
size() > 0 )
308 if ( !shapeStyleSymbolElem.
isNull() )
310 delete mShapeStyleSymbol;
311 mShapeStyleSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( shapeStyleSymbolElem );
316 delete mShapeStyleSymbol;
321 properties.
insert(
"style",
"solid" );
325 properties.
insert(
"style",
"no" );
329 properties.
insert(
"style_border",
"solid" );
333 properties.
insert(
"style_border",
"no" );
340 if ( outlineColorList.
size() > 0 )
343 bool redOk, greenOk, blueOk, alphaOk, widthOk;
344 int penRed, penGreen, penBlue, penAlpha;
353 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
360 if ( fillColorList.
size() > 0 )
363 bool redOk, greenOk, blueOk, alphaOk;
364 int fillRed, fillGreen, fillBlue, fillAlpha;
371 if ( redOk && greenOk && blueOk && alphaOk )
374 properties.
insert(
"style",
"solid" );
380 bool hasOldTransparentFill = itemElem.
attribute(
"transparentFill",
"0" ).
toInt();
381 if ( hasOldTransparentFill )
383 properties.
insert(
"style",
"no" );
411 mCornerRadius = radius;
416 return mCurrentRectangle;
419 void QgsComposerShape::updateBoundingRect()
422 rectangle.
adjust( -mMaxSymbolBleed, -mMaxSymbolBleed, mMaxSymbolBleed, mMaxSymbolBleed );
423 if ( rectangle != mCurrentRectangle )
426 mCurrentRectangle = rectangle;
438 updateBoundingRect();
444 if ( !
id().isEmpty() )
452 return tr(
"<ellipse>" );
455 return tr(
"<rectangle>" );
458 return tr(
"<triangle>" );
462 return tr(
"<shape>" );
void addEllipse(const QRectF &boundingRectangle)
void setShapeStyleSymbol(QgsFillSymbolV2 *symbol)
Sets the QgsFillSymbolV2 used to draw the shape.
void setForceVectorOutput(bool force)
void setShapeType(QgsComposerShape::Shape s)
QDomNodeList elementsByTagName(const QString &tagname) const
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.
void setRenderHint(RenderHint hint, bool on)
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const
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.
static QString encodeColor(const QColor &color)
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
void scale(qreal sx, qreal sy)
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 addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
static QDomElement saveSymbol(const QString &symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
virtual void setFrameEnabled(const bool drawFrame)
Set whether this item has a frame drawn around it or not.
QPolygonF toFillPolygon(const QMatrix &matrix) const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
double toDouble(bool *ok) const
virtual QgsExpressionContext * createExpressionContext() const override
Creates an expression context relating to the objects's current state.
QString tr(const char *sourceText, const char *disambiguation, int n)
void adjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2)
virtual void drawBackground(QPainter *p) override
Draw background.
void update(const QRectF &rect)
void updateItemDisplayName(QgsComposerItem *item)
Must be called when an item's display name is modified.
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.
QDomElement toElement() const
void drawRect(const QRectF &rectangle)
void frameChanged()
Emitted if the item's frame style changes.
QString number(int n, int base)
bool hasAttribute(const QString &name) const
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.
void setPen(const QColor &color)
bool mFrame
True if item fram needs to be painted.
void drawEllipse(const QRectF &rectangle)
void setAttribute(const QString &name, const QString &value)
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
int toInt(bool *ok, int base) const
virtual void drawFrame(QPainter *p) override
Draw black frame around item.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false, const QgsExpressionContext *context=0)
Evaluates an item's bounding rect to consider data defined position and size of item and reference po...
QPaintDevice * device() const
void setBrush(const QBrush &brush)
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.
void prepareGeometryChange()
Graphics scene for map printing.
virtual QgsSymbolV2 * clone() const override
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
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.
QDomElement firstChildElement(const QString &tagName) const
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()
iterator insert(const Key &key, const T &value)
QDomElement createElement(const QString &tagName)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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)
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QDomNode at(int index) const
QString id() const
Get item's id (which is not necessarly unique)