Skip to content

Commit

Permalink
Fix api break, unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 11, 2018
1 parent 0708d84 commit 06d7725
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/core/layout/qgslayoutitemscalebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,19 @@ void QgsLayoutItemScaleBar::setFont( const QFont &font )
emit changed();
}

QColor QgsLayoutItemScaleBar::fontColor() const
{
QColor color = mSettings.textFormat().color();
color.setAlphaF( mSettings.textFormat().opacity() );
return color;
}

void QgsLayoutItemScaleBar::setFontColor( const QColor &color )
{
mSettings.textFormat().setColor( color );
mSettings.textFormat().setOpacity( color.alphaF() );
}

bool QgsLayoutItemScaleBar::writePropertiesToElement( QDomElement &composerScaleBarElem, QDomDocument &doc, const QgsReadWriteContext &rwContext ) const
{
composerScaleBarElem.setAttribute( QStringLiteral( "height" ), QString::number( mSettings.height() ) );
Expand Down
4 changes: 2 additions & 2 deletions src/core/layout/qgslayoutitemscalebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ class CORE_EXPORT QgsLayoutItemScaleBar: public QgsLayoutItem
* \see font()
* \deprecated use textFormat() instead
*/
Q_DECL_DEPRECATED QColor fontColor() const SIP_DEPRECATED { return mSettings.textFormat().color(); }
Q_DECL_DEPRECATED QColor fontColor() const SIP_DEPRECATED;

/**
* Sets the \a color used for drawing text in the scalebar.
* \see fontColor()
* \see setFont()
* \deprecated use setTextFormat() instead
*/
Q_DECL_DEPRECATED void setFontColor( const QColor &color ) SIP_DEPRECATED { mSettings.textFormat().setColor( color ); }
Q_DECL_DEPRECATED void setFontColor( const QColor &color ) SIP_DEPRECATED;

/**
* Returns the color used for fills in the scalebar.
Expand Down
3 changes: 2 additions & 1 deletion tests/src/core/testqgslayoutscalebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ void TestQgsLayoutScaleBar::singleBoxAlpha()
l.addLayoutItem( scalebar );
scalebar->setLinkedMap( map );
QgsTextFormat format = QgsTextFormat::fromQFont( QgsFontUtils::getStandardTestFont() );
format.setColor( QColor( 255, 0, 255, 100 ) );
format.setColor( QColor( 255, 0, 255 ) );
format.setOpacity( 100.0 / 255 );
scalebar->setTextFormat( format );
scalebar->setUnits( QgsUnitTypes::DistanceMeters );
scalebar->setUnitsPerSegment( 2000 );
Expand Down

0 comments on commit 06d7725

Please sign in to comment.