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 );
150 if ( mCornerRadius > 0 )
170 void QgsComposerShape::drawShapeUsingSymbol(
QPainter* p )
185 p->
scale( 1 / dotsPerMM, 1 / dotsPerMM );
205 shapePolygon = ti.
map( ellipsePoly );
211 if ( mCornerRadius > 0 )
214 roundedRectPath.
addRoundedRect(
QRectF( 0, 0,
rect().width() * dotsPerMM,
rect().height() * dotsPerMM ), mCornerRadius * dotsPerMM, mCornerRadius * dotsPerMM );
216 shapePolygon = ti.
map( roundedPoly );
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 )
277 return mMaxSymbolBleed;
284 composerShapeElem.
setAttribute(
"cornerRadius", mCornerRadius );
290 return _writeXML( composerShapeElem, doc );
300 if ( composerItemList.
size() > 0 )
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" );
347 if ( outlineColorList.
size() > 0 )
350 bool redOk, greenOk, blueOk, alphaOk, widthOk;
351 int penRed, penGreen, penBlue, penAlpha;
360 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
367 if ( fillColorList.
size() > 0 )
370 bool redOk, greenOk, blueOk, alphaOk;
371 int fillRed, fillGreen, fillBlue, fillAlpha;
378 if ( redOk && greenOk && blueOk && alphaOk )
381 properties.
insert(
"style",
"solid" );
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()
429 rectangle.
adjust( -mMaxSymbolBleed, -mMaxSymbolBleed, mMaxSymbolBleed, mMaxSymbolBleed );
430 if ( rectangle != mCurrentRectangle )
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 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)
QgsComposition::AtlasMode atlasMode() const
Returns the current atlas mode of the composition.
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.
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)
bool enabled() const
Returns whether the atlas generation is enabled.
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
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.
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.
QDomElement toElement() const
static QDomElement saveSymbol(QString symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
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.
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.
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.
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)
QDomNode at(int index) const
QString id() const
Get item's id (which is not necessarly unique)