Skip to content
Permalink
Browse files

Fix some more Qt deprecation warnings

  • Loading branch information
nyalldawson committed Oct 7, 2020
1 parent 1af2e51 commit 8efcb5caf187e354389f7409c31b19004c2fa78c
@@ -87,7 +87,11 @@ void QgsPointRotationItem::setSymbol( const QImage &symbolImage )
p.drawLine( halfItemWidth, 0, mPixmap.width() * 0.75, quarterItemHeight );

//set item size
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
mItemSize.setWidth( mPixmap.width() + fm.width( QStringLiteral( "360" ) ) );
#else
mItemSize.setWidth( mPixmap.width() + fm.horizontalAdvance( QStringLiteral( "360" ) ) );
#endif
double pixmapHeight = mPixmap.height();
double fontHeight = fm.height();
if ( pixmapHeight >= fontHeight )
@@ -208,7 +208,11 @@ void QgsTextDiagram::renderDiagram( const QgsFeature &feature, QgsRenderContext
QString val = expression->evaluate( &expressionContext ).toString();

//find out dimensions
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
double textWidth = fontMetrics.width( val );
#else
double textWidth = fontMetrics.horizontalAdvance( val );
#endif
double textHeight = fontMetrics.height();

mPen.setColor( s.categoryColors.at( i ) );
@@ -222,7 +222,11 @@ double QgsLayoutUtils::textWidthMM( const QFont &font, const QString &text )
//ref: http://osgeo-org.1560.x6.nabble.com/Multi-line-labels-and-font-bug-td4157152.html
QFont metricsFont = scaledFontPixelSize( font );
QFontMetricsF fontMetrics( metricsFont );
return ( fontMetrics.width( text ) / FONT_WORKAROUND_SCALE );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
return ( fontMetrics.width( text ).width() / FONT_WORKAROUND_SCALE );
#else
return ( fontMetrics.horizontalAdvance( text ) / FONT_WORKAROUND_SCALE );
#endif
}

double QgsLayoutUtils::textHeightMM( const QFont &font, const QString &text, double multiLineHeight )
@@ -157,7 +157,11 @@ double QgsLegendSettings::textWidthMillimeters( const QFont &font, const QString
{
QFont metricsFont = scaledFontPixelSize( font );
QFontMetricsF fontMetrics( metricsFont );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
return ( fontMetrics.width( text ) / FONT_WORKAROUND_SCALE );
#else
return ( fontMetrics.horizontalAdvance( text ) / FONT_WORKAROUND_SCALE );
#endif
}

double QgsLegendSettings::fontHeightCharacterMM( const QFont &font, QChar c ) const
@@ -43,7 +43,11 @@ void QgsScaleBarRenderer::drawDefaultLabels( QgsRenderContext &context, const Qg

QString firstLabel = firstLabelString( settings );
QFontMetricsF fontMetrics = QgsTextRenderer::fontMetrics( context, format );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
double xOffset = fontMetrics.width( firstLabel ) / 2.0;
#else
double xOffset = fontMetrics.horizontalAdvance( firstLabel ) / 2.0;
#endif

double scaledBoxContentSpace = context.convertToPainterUnits( settings.boxContentSpace(), QgsUnitTypes::RenderMillimeters );
double scaledLabelBarSpace = context.convertToPainterUnits( settings.labelBarSpace(), QgsUnitTypes::RenderMillimeters );
@@ -144,8 +148,13 @@ void QgsScaleBarRenderer::drawDefaultLabels( QgsRenderContext &context, const Qg
}
else
{
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
pos.setX( context.convertToPainterUnits( positions.at( positions.size() - 1 ) + scaleContext.segmentWidth, QgsUnitTypes::RenderMillimeters ) + xOffset
- fontMetrics.width( currentNumericLabel ) / 2.0 );
#else
pos.setX( context.convertToPainterUnits( positions.at( positions.size() - 1 ) + scaleContext.segmentWidth, QgsUnitTypes::RenderMillimeters ) + xOffset
- fontMetrics.horizontalAdvance( currentNumericLabel ) / 2.0 );
#endif
QgsTextRenderer::drawText( pos, 0, QgsTextRenderer::AlignLeft, QStringList() << ( currentNumericLabel + ' ' + settings.unitLabel() ), context, format );
}
}
@@ -428,7 +428,11 @@ void QgsPointDistanceRenderer::drawLabels( QPointF centerPoint, QgsSymbolRenderC
currentLabelShift = *labelPosIt;
if ( currentLabelShift.x() < 0 )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
currentLabelShift.setX( currentLabelShift.x() - fontMetrics.width( groupIt->label ) );
#else
currentLabelShift.setX( currentLabelShift.x() - fontMetrics.horizontalAdvance( groupIt->label ) );
#endif
}
if ( currentLabelShift.y() > 0 )
{
@@ -35,7 +35,11 @@ QgsLayerTreeOpacityWidget::QgsLayerTreeOpacityWidget( QgsMapLayer *layer )
QLabel *l = new QLabel( tr( "Opacity" ), this );
mSlider = new QSlider( Qt::Horizontal, this );
mSlider->setRange( 0, 1000 );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int sliderW = static_cast< int >( QFontMetricsF( font() ).width( 'X' ) * 16 * Qgis::UI_SCALE_FACTOR );
#else
int sliderW = static_cast< int >( QFontMetricsF( font() ).horizontalAdvance( 'X' ) * 16 * Qgis::UI_SCALE_FACTOR );
#endif
mSlider->setMinimumWidth( sliderW / 2 );
mSlider->setMaximumWidth( sliderW );
QHBoxLayout *lay = new QHBoxLayout();
@@ -61,7 +61,11 @@ QgsLayerTreeView::QgsLayerTreeView( QWidget *parent )
setItemDelegate( new QgsLayerTreeViewItemDelegate( this ) );
setStyle( new QgsLayerTreeViewProxyStyle( this ) );

#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
setLayerMarkWidth( static_cast< int >( QFontMetricsF( font() ).width( 'l' ) * Qgis::UI_SCALE_FACTOR ) );
#else
setLayerMarkWidth( static_cast< int >( QFontMetricsF( font() ).horizontalAdvance( 'l' ) * Qgis::UI_SCALE_FACTOR ) );
#endif

connect( this, &QTreeView::collapsed, this, &QgsLayerTreeView::updateExpandedStateToNode );
connect( this, &QTreeView::expanded, this, &QgsLayerTreeView::updateExpandedStateToNode );
@@ -26,7 +26,7 @@ QgsMenuHeader::QgsMenuHeader( const QString &text, QWidget *parent )
{
int textMinWidth = fontMetrics().boundingRect( mText ).width();
mTextHeight = fontMetrics().height();
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
mLabelMargin = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "." ) );
#else
mLabelMargin = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( '.' );

0 comments on commit 8efcb5c

Please sign in to comment.
You can’t perform that action at this time.