Skip to content

Commit 06d7725

Browse files
committedMay 11, 2018
Fix api break, unit test
1 parent 0708d84 commit 06d7725

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed
 

‎src/core/layout/qgslayoutitemscalebar.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,19 @@ void QgsLayoutItemScaleBar::setFont( const QFont &font )
574574
emit changed();
575575
}
576576

577+
QColor QgsLayoutItemScaleBar::fontColor() const
578+
{
579+
QColor color = mSettings.textFormat().color();
580+
color.setAlphaF( mSettings.textFormat().opacity() );
581+
return color;
582+
}
583+
584+
void QgsLayoutItemScaleBar::setFontColor( const QColor &color )
585+
{
586+
mSettings.textFormat().setColor( color );
587+
mSettings.textFormat().setOpacity( color.alphaF() );
588+
}
589+
577590
bool QgsLayoutItemScaleBar::writePropertiesToElement( QDomElement &composerScaleBarElem, QDomDocument &doc, const QgsReadWriteContext &rwContext ) const
578591
{
579592
composerScaleBarElem.setAttribute( QStringLiteral( "height" ), QString::number( mSettings.height() ) );

‎src/core/layout/qgslayoutitemscalebar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ class CORE_EXPORT QgsLayoutItemScaleBar: public QgsLayoutItem
208208
* \see font()
209209
* \deprecated use textFormat() instead
210210
*/
211-
Q_DECL_DEPRECATED QColor fontColor() const SIP_DEPRECATED { return mSettings.textFormat().color(); }
211+
Q_DECL_DEPRECATED QColor fontColor() const SIP_DEPRECATED;
212212

213213
/**
214214
* Sets the \a color used for drawing text in the scalebar.
215215
* \see fontColor()
216216
* \see setFont()
217217
* \deprecated use setTextFormat() instead
218218
*/
219-
Q_DECL_DEPRECATED void setFontColor( const QColor &color ) SIP_DEPRECATED { mSettings.textFormat().setColor( color ); }
219+
Q_DECL_DEPRECATED void setFontColor( const QColor &color ) SIP_DEPRECATED;
220220

221221
/**
222222
* Returns the color used for fills in the scalebar.

‎tests/src/core/testqgslayoutscalebar.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ void TestQgsLayoutScaleBar::singleBoxAlpha()
142142
l.addLayoutItem( scalebar );
143143
scalebar->setLinkedMap( map );
144144
QgsTextFormat format = QgsTextFormat::fromQFont( QgsFontUtils::getStandardTestFont() );
145-
format.setColor( QColor( 255, 0, 255, 100 ) );
145+
format.setColor( QColor( 255, 0, 255 ) );
146+
format.setOpacity( 100.0 / 255 );
146147
scalebar->setTextFormat( format );
147148
scalebar->setUnits( QgsUnitTypes::DistanceMeters );
148149
scalebar->setUnitsPerSegment( 2000 );

0 commit comments

Comments
 (0)