Skip to content

Commit 03efcac

Browse files
committed
[composer] Default to no backgrounds for new labels, pictures, scalebars, and arrows. Fix some items not drawing using antialiasing if background disabled.
1 parent 1eff31a commit 03efcac

14 files changed

+54
-5
lines changed

src/core/composer/qgscomposerarrow.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ void QgsComposerArrow::initGraphicsSettings()
6161
mPen.setColor( QColor( 0, 0, 0 ) );
6262
mPen.setWidthF( 1 );
6363

64-
//set composer item brush and pen to transparent white by default
65-
setPen( QPen( QColor( 255, 255, 255, 0 ) ) );
66-
setBrush( QBrush( QColor( 255, 255, 255, 0 ) ) );
64+
//default to no background
65+
setBackgroundEnabled( false );
6766
}
6867

6968
void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
@@ -77,6 +76,10 @@ void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem
7776

7877
drawBackground( painter );
7978

79+
painter->save();
80+
//antialiasing on
81+
painter->setRenderHint( QPainter::Antialiasing, true );
82+
8083
//draw arrow
8184
QPen arrowPen = mPen;
8285
if ( mBoundsBehaviour == 22 )
@@ -99,6 +102,8 @@ void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem
99102
drawSVGMarker( painter, EndMarker, mEndMarkerFile );
100103
}
101104

105+
painter->restore();
106+
102107
drawFrame( painter );
103108
if ( isSelected() )
104109
{

src/core/composer/qgscomposerhtml.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ void QgsComposerHtml::render( QPainter* p, const QRectF& renderExtent )
134134
}
135135

136136
p->save();
137+
p->setRenderHint( QPainter::Antialiasing );
137138
p->scale( 1.0 / mHtmlUnitsToMM, 1.0 / mHtmlUnitsToMM );
138139
p->translate( 0.0, -renderExtent.top() * mHtmlUnitsToMM );
139140
mWebPage->mainFrame()->render( p, QRegion( renderExtent.left(), renderExtent.top() * mHtmlUnitsToMM, renderExtent.width() * mHtmlUnitsToMM, renderExtent.height() * mHtmlUnitsToMM ) );

src/core/composer/qgscomposeritem.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,12 @@ void QgsComposerItem::drawFrame( QPainter* p )
478478
{
479479
if ( mFrame && p )
480480
{
481+
p->save();
481482
p->setPen( pen() );
482483
p->setBrush( Qt::NoBrush );
483484
p->setRenderHint( QPainter::Antialiasing, true );
484485
p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
486+
p->restore();
485487
}
486488
}
487489

@@ -624,10 +626,12 @@ void QgsComposerItem::drawBackground( QPainter* p )
624626
{
625627
if ( mBackground && p )
626628
{
629+
p->save();
627630
p->setBrush( brush() );//this causes a problem in atlas generation
628631
p->setPen( Qt::NoPen );
629632
p->setRenderHint( QPainter::Antialiasing, true );
630633
p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
634+
p->restore();
631635
}
632636
}
633637

src/core/composer/qgscomposerlabel.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ):
4949
//default to a 10 point font size
5050
mFont.setPointSizeF( 10 );
5151

52+
//default to no background
53+
setBackgroundEnabled( false );
54+
5255
if ( mComposition && mComposition->atlasMode() == QgsComposition::PreviewAtlas )
5356
{
5457
//a label added while atlas preview is enabled needs to have the expression context set,
@@ -78,6 +81,9 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
7881
drawBackground( painter );
7982
painter->save();
8083

84+
//antialiasing on
85+
painter->setRenderHint( QPainter::Antialiasing, true );
86+
8187
double penWidth = hasFrame() ? pen().widthF() : 0;
8288
QRectF painterRect( penWidth + mMargin, penWidth + mMargin, rect().width() - 2 * penWidth - 2 * mMargin, rect().height() - 2 * penWidth - 2 * mMargin );
8389

src/core/composer/qgscomposerlegend.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
9090

9191
if ( painter )
9292
{
93-
painter->save();
9493
drawBackground( painter );
94+
painter->save();
95+
//antialiasing on
96+
painter->setRenderHint( QPainter::Antialiasing, true );
9597
painter->setPen( QPen( QColor( 0, 0, 0 ) ) );
9698
}
9799

src/core/composer/qgscomposermap.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,9 @@ void QgsComposerMap::drawGrid( QPainter* p )
15411541

15421542
void QgsComposerMap::drawGridFrame( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines )
15431543
{
1544+
p->save();
1545+
p->setRenderHint( QPainter::Antialiasing );
1546+
15441547
//Sort the coordinate positions for each side
15451548
QMap< double, double > leftGridFrame;
15461549
QMap< double, double > rightGridFrame;
@@ -1553,6 +1556,8 @@ void QgsComposerMap::drawGridFrame( QPainter* p, const QList< QPair< double, QLi
15531556
drawGridFrameBorder( p, rightGridFrame, QgsComposerMap::Right );
15541557
drawGridFrameBorder( p, topGridFrame, QgsComposerMap::Top );
15551558
drawGridFrameBorder( p, bottomGridFrame, QgsComposerMap::Bottom );
1559+
1560+
p->restore();
15561561
}
15571562

15581563
void QgsComposerMap::drawGridLine( const QLineF& line, QgsRenderContext& context )
@@ -1632,6 +1637,8 @@ void QgsComposerMap::drawCoordinateAnnotations( QPainter* p, const QList< QPair<
16321637
return;
16331638
}
16341639

1640+
p->save();
1641+
p->setRenderHint( QPainter::Antialiasing );
16351642

16361643
QString currentAnnotationString;
16371644
QList< QPair< double, QLineF > >::const_iterator it = hLines.constBegin();
@@ -1649,6 +1656,7 @@ void QgsComposerMap::drawCoordinateAnnotations( QPainter* p, const QList< QPair<
16491656
drawCoordinateAnnotation( p, it->second.p1(), currentAnnotationString );
16501657
drawCoordinateAnnotation( p, it->second.p2(), currentAnnotationString );
16511658
}
1659+
p->restore();
16521660
}
16531661

16541662
void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos, QString annotationString )
@@ -2368,6 +2376,7 @@ void QgsComposerMap::drawCanvasItem( QGraphicsItem* item, QPainter* painter, con
23682376
}
23692377

23702378
painter->save();
2379+
painter->setRenderHint( QPainter::Antialiasing );
23712380

23722381
//determine scale factor according to graphics view dpi
23732382
double scaleFactor = 1.0 / mMapCanvas->logicalDpiX() * 25.4;
@@ -2392,7 +2401,6 @@ void QgsComposerMap::drawCanvasItem( QGraphicsItem* item, QPainter* painter, con
23922401
}
23932402
painter->translate( itemX, itemY );
23942403

2395-
23962404
painter->scale( scaleFactor, scaleFactor );
23972405

23982406
//a little trick to let the item know that the paint request comes from the composer

src/core/composer/qgscomposerpicture.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ QgsComposerPicture::QgsComposerPicture() : QgsComposerItem( 0 ),
6060

6161
void QgsComposerPicture::init()
6262
{
63+
//default to no background
64+
setBackgroundEnabled( false );
65+
6366
//connect some signals
6467

6568
//connect to atlas feature changing
@@ -123,6 +126,8 @@ void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsIte
123126
rect().height() * mComposition->printResolution() / 25.4 );
124127
}
125128
painter->save();
129+
//antialiasing on
130+
painter->setRenderHint( QPainter::Antialiasing, true );
126131

127132
//zoom mode - calculate anchor point and rotation
128133
if ( mResizeMode == Zoom )

src/core/composer/qgscomposerscalebar.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ void QgsComposerScaleBar::applyDefaultSettings()
270270

271271
mHeight = 3;
272272

273+
//default to no background
274+
setBackgroundEnabled( false );
275+
273276
mPen = QPen( Qt::black );
274277
mPen.setJoinStyle( mLineJoinStyle );
275278
mPen.setCapStyle( mLineCapStyle );

src/core/composer/qgscomposertable.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
7979
}
8080

8181
drawBackground( painter );
82+
painter->save();
83+
//antialiasing on
84+
painter->setRenderHint( QPainter::Antialiasing, true );
85+
8286
painter->setPen( Qt::SolidLine );
8387

8488
//now draw the text
@@ -153,6 +157,8 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
153157
drawVerticalGridLines( painter, mMaxColumnWidthMap );
154158
}
155159

160+
painter->restore();
161+
156162
//draw frame and selection boxes if necessary
157163
drawFrame( painter );
158164
if ( isSelected() )

src/core/composer/qgsdoubleboxscalebarstyle.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ void QgsDoubleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
4949
double segmentHeight = mScaleBar->height() / 2;
5050

5151
p->save();
52+
//antialiasing on
53+
p->setRenderHint( QPainter::Antialiasing, true );
5254
p->setPen( mScaleBar->pen() );
5355

5456
QList<QPair<double, double> > segmentInfo;

src/core/composer/qgsnumericscalebarstyle.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ void QgsNumericScaleBarStyle::draw( QPainter* p, double xOffset ) const
4949
}
5050

5151
p->save();
52+
//antialiasing on
53+
p->setRenderHint( QPainter::Antialiasing, true );
5254
p->setFont( mScaleBar->font() );
5355
p->setPen( mScaleBar->fontColor() );
5456

src/core/composer/qgssingleboxscalebarstyle.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ void QgsSingleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
4343
double barTopPosition = mScaleBar->fontAscentMillimeters( mScaleBar->font() ) + mScaleBar->labelBarSpace() + mScaleBar->boxContentSpace();
4444

4545
p->save();
46+
//antialiasing on
47+
p->setRenderHint( QPainter::Antialiasing, true );
4648
p->setPen( mScaleBar->pen() );
4749

4850

src/core/composer/qgsticksscalebarstyle.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ void QgsTicksScaleBarStyle::draw( QPainter* p, double xOffset ) const
5858
double bottomPosition = barTopPosition + mScaleBar->height();
5959

6060
p->save();
61+
//antialiasing on
62+
p->setRenderHint( QPainter::Antialiasing, true );
6163
p->setPen( mScaleBar->pen() );
6264

6365
QList<QPair<double, double> > segmentInfo;

tests/src/core/testqgscomposerrotation.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void TestQgsComposerRotation::initTestCase()
9191
mComposerLabel->setPos( 70, 70 );
9292
mComposerLabel->adjustSizeToText();
9393
mComposerLabel->setBackgroundColor( QColor::fromRgb( 255, 150, 0 ) );
94+
mComposerLabel->setBackgroundEnabled( true );
9495

9596
mComposerMap = new QgsComposerMap( mComposition, 20, 20, 200, 100 );
9697
mComposerMap->setFrameEnabled( true );

0 commit comments

Comments
 (0)