Skip to content
Permalink
Browse files
[composer] Default to no backgrounds for new labels, pictures, scaleb…
…ars, and arrows. Fix some items not drawing using antialiasing if background disabled.
  • Loading branch information
nyalldawson committed Jun 30, 2014
1 parent 1eff31a commit 03efcac527c393bd1d093bc6ac15f21fda820b52
@@ -61,9 +61,8 @@ void QgsComposerArrow::initGraphicsSettings()
mPen.setColor( QColor( 0, 0, 0 ) );
mPen.setWidthF( 1 );

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

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

drawBackground( painter );

painter->save();
//antialiasing on
painter->setRenderHint( QPainter::Antialiasing, true );

//draw arrow
QPen arrowPen = mPen;
if ( mBoundsBehaviour == 22 )
@@ -99,6 +102,8 @@ void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem
drawSVGMarker( painter, EndMarker, mEndMarkerFile );
}

painter->restore();

drawFrame( painter );
if ( isSelected() )
{
@@ -134,6 +134,7 @@ void QgsComposerHtml::render( QPainter* p, const QRectF& renderExtent )
}

p->save();
p->setRenderHint( QPainter::Antialiasing );
p->scale( 1.0 / mHtmlUnitsToMM, 1.0 / mHtmlUnitsToMM );
p->translate( 0.0, -renderExtent.top() * mHtmlUnitsToMM );
mWebPage->mainFrame()->render( p, QRegion( renderExtent.left(), renderExtent.top() * mHtmlUnitsToMM, renderExtent.width() * mHtmlUnitsToMM, renderExtent.height() * mHtmlUnitsToMM ) );
@@ -478,10 +478,12 @@ void QgsComposerItem::drawFrame( QPainter* p )
{
if ( mFrame && p )
{
p->save();
p->setPen( pen() );
p->setBrush( Qt::NoBrush );
p->setRenderHint( QPainter::Antialiasing, true );
p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
p->restore();
}
}

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

@@ -49,6 +49,9 @@ QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ):
//default to a 10 point font size
mFont.setPointSizeF( 10 );

//default to no background
setBackgroundEnabled( false );

if ( mComposition && mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
//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*
drawBackground( painter );
painter->save();

//antialiasing on
painter->setRenderHint( QPainter::Antialiasing, true );

double penWidth = hasFrame() ? pen().widthF() : 0;
QRectF painterRect( penWidth + mMargin, penWidth + mMargin, rect().width() - 2 * penWidth - 2 * mMargin, rect().height() - 2 * penWidth - 2 * mMargin );

@@ -90,8 +90,10 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )

if ( painter )
{
painter->save();
drawBackground( painter );
painter->save();
//antialiasing on
painter->setRenderHint( QPainter::Antialiasing, true );
painter->setPen( QPen( QColor( 0, 0, 0 ) ) );
}

@@ -1541,6 +1541,9 @@ void QgsComposerMap::drawGrid( QPainter* p )

void QgsComposerMap::drawGridFrame( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines )
{
p->save();
p->setRenderHint( QPainter::Antialiasing );

//Sort the coordinate positions for each side
QMap< double, double > leftGridFrame;
QMap< double, double > rightGridFrame;
@@ -1553,6 +1556,8 @@ void QgsComposerMap::drawGridFrame( QPainter* p, const QList< QPair< double, QLi
drawGridFrameBorder( p, rightGridFrame, QgsComposerMap::Right );
drawGridFrameBorder( p, topGridFrame, QgsComposerMap::Top );
drawGridFrameBorder( p, bottomGridFrame, QgsComposerMap::Bottom );

p->restore();
}

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

p->save();
p->setRenderHint( QPainter::Antialiasing );

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

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

painter->save();
painter->setRenderHint( QPainter::Antialiasing );

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


painter->scale( scaleFactor, scaleFactor );

//a little trick to let the item know that the paint request comes from the composer
@@ -60,6 +60,9 @@ QgsComposerPicture::QgsComposerPicture() : QgsComposerItem( 0 ),

void QgsComposerPicture::init()
{
//default to no background
setBackgroundEnabled( false );

//connect some signals

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

//zoom mode - calculate anchor point and rotation
if ( mResizeMode == Zoom )
@@ -270,6 +270,9 @@ void QgsComposerScaleBar::applyDefaultSettings()

mHeight = 3;

//default to no background
setBackgroundEnabled( false );

mPen = QPen( Qt::black );
mPen.setJoinStyle( mLineJoinStyle );
mPen.setCapStyle( mLineCapStyle );
@@ -79,6 +79,10 @@ void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem*
}

drawBackground( painter );
painter->save();
//antialiasing on
painter->setRenderHint( QPainter::Antialiasing, true );

painter->setPen( Qt::SolidLine );

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

painter->restore();

//draw frame and selection boxes if necessary
drawFrame( painter );
if ( isSelected() )
@@ -49,6 +49,8 @@ void QgsDoubleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
double segmentHeight = mScaleBar->height() / 2;

p->save();
//antialiasing on
p->setRenderHint( QPainter::Antialiasing, true );
p->setPen( mScaleBar->pen() );

QList<QPair<double, double> > segmentInfo;
@@ -49,6 +49,8 @@ void QgsNumericScaleBarStyle::draw( QPainter* p, double xOffset ) const
}

p->save();
//antialiasing on
p->setRenderHint( QPainter::Antialiasing, true );
p->setFont( mScaleBar->font() );
p->setPen( mScaleBar->fontColor() );

@@ -43,6 +43,8 @@ void QgsSingleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
double barTopPosition = mScaleBar->fontAscentMillimeters( mScaleBar->font() ) + mScaleBar->labelBarSpace() + mScaleBar->boxContentSpace();

p->save();
//antialiasing on
p->setRenderHint( QPainter::Antialiasing, true );
p->setPen( mScaleBar->pen() );


@@ -58,6 +58,8 @@ void QgsTicksScaleBarStyle::draw( QPainter* p, double xOffset ) const
double bottomPosition = barTopPosition + mScaleBar->height();

p->save();
//antialiasing on
p->setRenderHint( QPainter::Antialiasing, true );
p->setPen( mScaleBar->pen() );

QList<QPair<double, double> > segmentInfo;
@@ -91,6 +91,7 @@ void TestQgsComposerRotation::initTestCase()
mComposerLabel->setPos( 70, 70 );
mComposerLabel->adjustSizeToText();
mComposerLabel->setBackgroundColor( QColor::fromRgb( 255, 150, 0 ) );
mComposerLabel->setBackgroundEnabled( true );

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

0 comments on commit 03efcac

Please sign in to comment.