29 , mUseSymbolV2( false )
30 , mShapeStyleSymbol( nullptr )
31 , mMaxSymbolBleed( 0 )
34 createDefaultShapeStyleSymbol();
48 , mUseSymbolV2( false )
49 , mShapeStyleSymbol( nullptr )
50 , mMaxSymbolBleed( 0 )
54 createDefaultShapeStyleSymbol();
66 delete mShapeStyleSymbol;
71 mUseSymbolV2 = useSymbolV2;
77 delete mShapeStyleSymbol;
91 void QgsComposerShape::createDefaultShapeStyleSymbol()
93 delete mShapeStyleSymbol;
95 properties.
insert(
"color",
"white" );
96 properties.
insert(
"style",
"solid" );
97 properties.
insert(
"style_border",
"solid" );
98 properties.
insert(
"color_border",
"black" );
99 properties.
insert(
"width_border",
"0.3" );
100 properties.
insert(
"joinstyle",
"miter" );
104 updateBoundingRect();
111 Q_UNUSED( itemStyle );
132 void QgsComposerShape::drawShape(
QPainter* p )
136 drawShapeUsingSymbol( p );
151 if ( mCornerRadius > 0 )
163 triangle << QPointF(
rect().width(),
rect().height() );
164 triangle << QPointF(
rect().width() / 2.0, 0 );
171 void QgsComposerShape::drawShapeUsingSymbol(
QPainter* p )
188 delete expressionContext;
190 p->
scale( 1 / dotsPerMM, 1 / dotsPerMM );
210 shapePolygon = ti.
map( ellipsePoly );
216 if ( mCornerRadius > 0 )
219 roundedRectPath.
addRoundedRect(
QRectF( 0, 0,
rect().width() * dotsPerMM,
rect().height() * dotsPerMM ), mCornerRadius * dotsPerMM, mCornerRadius * dotsPerMM );
221 shapePolygon = ti.
map( roundedPoly );
231 shapePolygon <<
QPointF( 0,
rect().height() * dotsPerMM );
232 shapePolygon << QPointF(
rect().width() * dotsPerMM,
rect().height() * dotsPerMM );
233 shapePolygon << QPointF(
rect().width() / 2.0 * dotsPerMM, 0 );
234 shapePolygon << QPointF( 0,
rect().height() * dotsPerMM );
240 mShapeStyleSymbol->
renderPolygon( shapePolygon, &rings,
nullptr, context );
249 if (
mFrame && p && !mUseSymbolV2 )
271 return mMaxSymbolBleed;
278 composerShapeElem.
setAttribute(
"cornerRadius", mCornerRadius );
284 return _writeXML( composerShapeElem, doc );
294 if ( !composerItemList.
isEmpty() )
309 if ( !shapeStyleSymbolElem.
isNull() )
311 delete mShapeStyleSymbol;
312 mShapeStyleSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( shapeStyleSymbolElem );
317 delete mShapeStyleSymbol;
322 properties.
insert(
"style",
"solid" );
326 properties.
insert(
"style",
"no" );
330 properties.
insert(
"style_border",
"solid" );
334 properties.
insert(
"style_border",
"no" );
341 if ( !outlineColorList.
isEmpty() )
344 bool redOk, greenOk, blueOk, alphaOk, widthOk;
345 int penRed, penGreen, penBlue, penAlpha;
354 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
361 if ( !fillColorList.
isEmpty() )
364 bool redOk, greenOk, blueOk, alphaOk;
365 int fillRed, fillGreen, fillBlue, fillAlpha;
372 if ( redOk && greenOk && blueOk && alphaOk )
375 properties.
insert(
"style",
"solid" );
381 bool hasOldTransparentFill = itemElem.
attribute(
"transparentFill",
"0" ).
toInt();
382 if ( hasOldTransparentFill )
384 properties.
insert(
"style",
"no" );
412 mCornerRadius = radius;
417 return mCurrentRectangle;
420 void QgsComposerShape::updateBoundingRect()
423 rectangle.
adjust( -mMaxSymbolBleed, -mMaxSymbolBleed, mMaxSymbolBleed, mMaxSymbolBleed );
424 if ( rectangle != mCurrentRectangle )
427 mCurrentRectangle = rectangle;
439 updateBoundingRect();
445 if ( !
id().isEmpty() )
453 return tr(
"<ellipse>" );
455 return tr(
"<rectangle>" );
457 return tr(
"<triangle>" );
460 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.
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
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 itemChanged()
Emitted when the item changes.
static QString encodeColor(const QColor &color)
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)
void setOutputDpi(double dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false, const QgsExpressionContext *context=nullptr)
Evaluates an item's bounding rect to consider data defined position and size of item and reference po...
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...
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
double toDouble(bool *ok) const
virtual QgsExpressionContext * createExpressionContext() const override
Creates an expression context relating to the item's current state.
QString tr(const char *sourceText, const char *disambiguation, int n)
void adjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
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)
void startRender(QgsRenderContext &context, const QgsFields *fields=nullptr)
bool hasAttribute(const QString &name) const
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...
QPaintDevice * device() const
void setBrush(const QBrush &brush)
void setPainter(QPainter *p)
bool hasBackground() const
Whether this item has a Background or not.
static double estimateMaxSymbolBleed(QgsSymbolV2 *symbol)
Returns the maximum estimated bleed for the symbol.
void prepareGeometryChange()
Graphics scene for map printing.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
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.
virtual QgsFillSymbolV2 * clone() const override
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)
const QgsComposition * composition() const
Returns the composition the item is attached to.
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
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...
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)
bool hasFrame() const
Whether this item has a frame or not.
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.
QString id() const
Get item's id (which is not necessarly unique)
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