Skip to content

Commit 2b3108f

Browse files
committed
Fix high cpu usage with win32 builds when using shapes in composer (fix #9933, #9957, #9734)
1 parent d398560 commit 2b3108f

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

src/core/composer/qgscomposershape.cpp

100644100755
+30-12
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ QgsComposerShape::QgsComposerShape( QgsComposition* composition ): QgsComposerIt
2525
mShape( Ellipse ),
2626
mCornerRadius( 0 ),
2727
mUseSymbolV2( false ), //default to not using SymbolV2 for shapes, to preserve 2.0 api
28-
mShapeStyleSymbol( 0 )
28+
mShapeStyleSymbol( 0 ),
29+
mMaxSymbolBleed( 0 )
2930
{
3031
setFrameEnabled( true );
3132
createDefaultShapeStyleSymbol();
@@ -36,7 +37,8 @@ QgsComposerShape::QgsComposerShape( qreal x, qreal y, qreal width, qreal height,
3637
mShape( Ellipse ),
3738
mCornerRadius( 0 ),
3839
mUseSymbolV2( false ), //default to not using SymbolV2 for shapes, to preserve 2.0 api
39-
mShapeStyleSymbol( 0 )
40+
mShapeStyleSymbol( 0 ),
41+
mMaxSymbolBleed( 0 )
4042
{
4143
setSceneRect( QRectF( x, y, width, height ) );
4244
setFrameEnabled( true );
@@ -58,12 +60,14 @@ void QgsComposerShape::setShapeStyleSymbol( QgsFillSymbolV2* symbol )
5860
{
5961
delete mShapeStyleSymbol;
6062
mShapeStyleSymbol = symbol;
61-
update();
62-
emit frameChanged();
63+
refreshSymbol();
6364
}
6465

6566
void QgsComposerShape::refreshSymbol()
6667
{
68+
mMaxSymbolBleed = QgsSymbolLayerV2Utils::estimateMaxSymbolBleed( mShapeStyleSymbol );
69+
updateBoundingRect();
70+
6771
update();
6872
emit frameChanged();
6973
}
@@ -78,6 +82,11 @@ void QgsComposerShape::createDefaultShapeStyleSymbol()
7882
properties.insert( "color_border", "black" );
7983
properties.insert( "width_border", "0.3" );
8084
mShapeStyleSymbol = QgsFillSymbolV2::createSimple( properties );
85+
86+
mMaxSymbolBleed = QgsSymbolLayerV2Utils::estimateMaxSymbolBleed( mShapeStyleSymbol );
87+
updateBoundingRect();
88+
89+
emit frameChanged();
8190
}
8291

8392
void QgsComposerShape::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
@@ -205,13 +214,6 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
205214

206215
mShapeStyleSymbol->startRender( context );
207216

208-
double maxBleed = QgsSymbolLayerV2Utils::estimateMaxSymbolBleed( mShapeStyleSymbol );
209-
210-
//even though we aren't going to use it to draw the shape, set the pen width as 2 * symbol bleed
211-
//so that the item is fully rendered within it's scene rect
212-
//(QGraphicsRectItem considers the pen width when calculating an item's scene rect)
213-
setPen( QPen( QBrush( Qt::NoBrush ), maxBleed * 2.0 ) );
214-
215217
//need to render using atlas feature properties?
216218
if ( mComposition->atlasComposition().enabled() && mComposition->atlasMode() != QgsComposition::AtlasOff )
217219
{
@@ -253,7 +255,7 @@ void QgsComposerShape::drawBackground( QPainter* p )
253255

254256
double QgsComposerShape::estimatedFrameBleed() const
255257
{
256-
return QgsSymbolLayerV2Utils::estimateMaxSymbolBleed( mShapeStyleSymbol );
258+
return mMaxSymbolBleed;
257259
}
258260

259261
bool QgsComposerShape::writeXML( QDomElement& elem, QDomDocument & doc ) const
@@ -330,3 +332,19 @@ void QgsComposerShape::setCornerRadius( double radius )
330332
{
331333
mCornerRadius = radius;
332334
}
335+
336+
QRectF QgsComposerShape::boundingRect() const
337+
{
338+
return mCurrentRectangle;
339+
}
340+
341+
void QgsComposerShape::updateBoundingRect()
342+
{
343+
QRectF rectangle = rect();
344+
rectangle.adjust( -mMaxSymbolBleed, -mMaxSymbolBleed, mMaxSymbolBleed, mMaxSymbolBleed );
345+
if ( rectangle != mCurrentRectangle )
346+
{
347+
prepareGeometryChange();
348+
mCurrentRectangle = rectangle;
349+
}
350+
}

src/core/composer/qgscomposershape.h

100644100755
+10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class CORE_EXPORT QgsComposerShape: public QgsComposerItem
8080
* Note: Added in v2.1 */
8181
void setUseSymbolV2( bool useSymbolV2 );
8282

83+
/**Depending on the symbol style, the bounding rectangle can be larger than the shape
84+
@note this function was added in version 2.3*/
85+
QRectF boundingRect() const;
86+
8387
protected:
8488
/* reimplement drawFrame, since it's not a rect, but a custom shape */
8589
virtual void drawFrame( QPainter* p );
@@ -104,6 +108,9 @@ class CORE_EXPORT QgsComposerShape: public QgsComposerItem
104108
bool mUseSymbolV2;
105109

106110
QgsFillSymbolV2* mShapeStyleSymbol;
111+
double mMaxSymbolBleed;
112+
/**Current bounding rectangle of shape*/
113+
QRectF mCurrentRectangle;
107114

108115
/* draws the custom shape */
109116
void drawShape( QPainter* p );
@@ -116,6 +123,9 @@ class CORE_EXPORT QgsComposerShape: public QgsComposerItem
116123

117124
/**Returns a point on the line from startPoint to directionPoint that is a certain distance away from the starting point*/
118125
QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance ) const;
126+
127+
/**Updates the bounding rect of this item*/
128+
void updateBoundingRect();
119129
};
120130

121131
#endif // QGSCOMPOSERSHAPEITEM_H

0 commit comments

Comments
 (0)