Skip to content

Commit 3aaeb81

Browse files
committedJan 30, 2020
Deprecation warning fixes
1 parent 4ca2bbb commit 3aaeb81

10 files changed

+70
-4
lines changed
 

‎src/gui/editorwidgets/qgshtmlwidgetwrapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "qgsexpressioncontextutils.h"
2020
#include "qgsapplication.h"
2121
#include "qgswebframe.h"
22-
22+
#include <QScreen>
2323

2424
QgsHtmlWidgetWrapper::QgsHtmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent )
2525
: QgsWidgetWrapper( layer, editor, parent )
@@ -46,7 +46,14 @@ void QgsHtmlWidgetWrapper::initWidget( QWidget *editor )
4646

4747
mWidget->setHtml( mHtmlCode );
4848
#ifdef WITH_QTWEBKIT
49+
50+
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
4951
const int horizontalDpi = qApp->desktop()->screen()->logicalDpiX();
52+
#else
53+
QScreen *screen = QGuiApplication::screenAt( mWidget->mapToGlobal( QPoint( mWidget->width() / 2, 0 ) ) );
54+
const int horizontalDpi = screen->logicalDotsPerInchX();
55+
#endif
56+
5057
mWidget->setZoomFactor( horizontalDpi / 96.0 );
5158

5259
QWebPage *page = mWidget->page();

‎src/gui/layout/qgslayoutitemslistview.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ void QgsLayoutItemsListView::setCurrentLayout( QgsLayout *layout )
100100

101101
header()->setSectionResizeMode( 0, QHeaderView::Fixed );
102102
header()->setSectionResizeMode( 1, QHeaderView::Fixed );
103+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
103104
setColumnWidth( 0, Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "xxxx" ) ) );
104105
setColumnWidth( 1, Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "xxxx" ) ) );
106+
#else
107+
setColumnWidth( 0, Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'x' ) * 4 );
108+
setColumnWidth( 1, Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'x' ) * 4 );
109+
#endif
105110
header()->setSectionsMovable( false );
106111

107112
connect( selectionModel(), &QItemSelectionModel::currentChanged, mModel, &QgsLayoutItemsListViewModel::setSelected );

‎src/gui/qgscolorschemelist.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,12 @@ void QgsColorSwatchDelegate::paint( QPainter *painter, const QStyleOptionViewIte
710710
}
711711

712712
QRect rect = option.rect;
713+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
713714
const int iconSize = Qgis::UI_SCALE_FACTOR * option.fontMetrics.width( 'X' ) * 4;
715+
#else
716+
const int iconSize = Qgis::UI_SCALE_FACTOR * option.fontMetrics.horizontalAdvance( 'X' ) * 4;
717+
#endif
718+
714719
const int cornerSize = iconSize / 6;
715720
//center it
716721
rect.setLeft( option.rect.center().x() - iconSize / 2 );
@@ -749,7 +754,11 @@ QSize QgsColorSwatchDelegate::sizeHint( const QStyleOptionViewItem &option, cons
749754
{
750755
Q_UNUSED( index )
751756

757+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
752758
const int iconSize = Qgis::UI_SCALE_FACTOR * option.fontMetrics.width( 'X' ) * 4;
759+
#else
760+
const int iconSize = Qgis::UI_SCALE_FACTOR * option.fontMetrics.horizontalAdvance( 'X' ) * 4;
761+
#endif
753762
return QSize( iconSize, iconSize * 32 / 30.0 );
754763
}
755764

‎src/gui/qgscolorwidgets.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,11 @@ QgsColorWheel::~QgsColorWheel()
392392

393393
QSize QgsColorWheel::sizeHint() const
394394
{
395+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
395396
int size = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) );
397+
#else
398+
int size = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 22;
399+
#endif
396400
return QSize( size, size );
397401
}
398402

@@ -750,7 +754,11 @@ QgsColorBox::~QgsColorBox()
750754

751755
QSize QgsColorBox::sizeHint() const
752756
{
757+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
753758
int size = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) );
759+
#else
760+
int size = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 22;
761+
#endif
754762
return QSize( size, size );
755763
}
756764

@@ -981,12 +989,20 @@ QSize QgsColorRampWidget::sizeHint() const
981989
if ( mOrientation == QgsColorRampWidget::Horizontal )
982990
{
983991
//horizontal
992+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
984993
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ), Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.3 );
994+
#else
995+
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 22, Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.3 );
996+
#endif
985997
}
986998
else
987999
{
9881000
//vertical
1001+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
9891002
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.3, Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ) );
1003+
#else
1004+
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.3, Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 22 );
1005+
#endif
9901006
}
9911007
}
9921008

@@ -1277,7 +1293,11 @@ QgsColorSliderWidget::QgsColorSliderWidget( QWidget *parent, const ColorComponen
12771293

12781294
mSpinBox = new QSpinBox();
12791295
//set spinbox to a reasonable width
1296+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
12801297
int largestCharWidth = mSpinBox->fontMetrics().width( QStringLiteral( "888%" ) );
1298+
#else
1299+
int largestCharWidth = mSpinBox->fontMetrics().horizontalAdvance( QStringLiteral( "888%" ) );
1300+
#endif
12811301
mSpinBox->setMinimumWidth( largestCharWidth + 35 );
12821302
mSpinBox->setMinimum( 0 );
12831303
mSpinBox->setMaximum( convertRealToDisplay( componentRange() ) );
@@ -1588,7 +1608,11 @@ void QgsColorPreviewWidget::paintEvent( QPaintEvent *event )
15881608

15891609
QSize QgsColorPreviewWidget::sizeHint() const
15901610
{
1611+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
15911612
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ), Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ) * 0.75 );
1613+
#else
1614+
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 22, Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 22 * 0.75 );
1615+
#endif
15921616
}
15931617

15941618
void QgsColorPreviewWidget::setColor2( const QColor &color )

‎src/gui/qgscompoundcolorwidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor &c
6565
QgsSettings settings;
6666

6767
mSchemeList->header()->hide();
68+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
6869
mSchemeList->setColumnWidth( 0, static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 6 ) );
70+
#else
71+
mSchemeList->setColumnWidth( 0, static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 6 ) );
72+
#endif
73+
6974

7075
//get schemes with ShowInColorDialog set
7176
refreshSchemeComboBox();

‎src/gui/qgsdetaileditemdelegate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ void QgsDetailedItemDelegate::paintAsWidget( QPainter *thepPainter,
253253
{
254254
drawHighlight( option, thepPainter, height( option, data ) );
255255
}
256-
QPixmap myPixmap = QPixmap::grabWidget( mpWidget );
256+
QPixmap myPixmap = mpWidget->grab();
257257
thepPainter->drawPixmap( option.rect.x(),
258258
option.rect.y(),
259259
myPixmap );
@@ -348,7 +348,7 @@ QStringList QgsDetailedItemDelegate::wordWrap( const QString &string,
348348
myPreviousSpacePos = i;
349349
}
350350
myCumulativeLine += myChar;
351-
if ( metrics.width( myCumulativeLine ) >= width )
351+
if ( metrics.boundingRect( myCumulativeLine ).width() >= width )
352352
{
353353
//time to wrap
354354
//TODO deal with long strings that have no spaces

‎src/gui/qgsfieldexpressionwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void QgsFieldExpressionWidget::currentFieldChanged()
323323

324324
// display tooltip if widget is shorter than expression
325325
QFontMetrics metrics( mCombo->lineEdit()->font() );
326-
if ( metrics.width( fieldName ) > mCombo->lineEdit()->width() )
326+
if ( metrics.boundingRect( fieldName ).width() > mCombo->lineEdit()->width() )
327327
{
328328
mCombo->setToolTip( fieldName );
329329
}

‎src/gui/qgsfontbutton.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ QgsFontButton::QgsFontButton( QWidget *parent, const QString &dialogTitle )
5353
//make sure height of button looks good under different platforms
5454
QSize size = QToolButton::minimumSizeHint();
5555
int fontHeight = Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.4;
56+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
5657
int minWidth = Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 20;
58+
#else
59+
int minWidth = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 20;
60+
#endif
5761
mSizeHint = QSize( std::max( minWidth, size.width() ), std::max( size.height(), fontHeight ) );
5862
}
5963

‎src/gui/qgsratiolockbutton.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ QgsRatioLockButton::QgsRatioLockButton( QWidget *parent )
2727
: QToolButton( parent )
2828
{
2929
setMinimumSize( QSize( 24, 24 ) );
30+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
3031
setMaximumWidth( fontMetrics().width( QStringLiteral( "000" ) ) );
32+
#else
33+
setMaximumWidth( fontMetrics().horizontalAdvance( '0' ) * 3 );
34+
#endif
3135
setCheckable( true );
3236
setAutoRaise( true );
3337
connect( this, &QPushButton::clicked, this, &QgsRatioLockButton::buttonClicked );

‎src/gui/raster/qgsrasterlayerproperties.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include <QVector>
7777
#include <QUrl>
7878
#include <QMenu>
79+
#include <QScreen>
7980

8081
QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanvas *canvas, QWidget *parent, Qt::WindowFlags fl )
8182
: QgsOptionsDialogBase( QStringLiteral( "RasterLayerProperties" ), parent, fl )
@@ -440,7 +441,14 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
440441

441442
#ifdef WITH_QTWEBKIT
442443
// Setup information tab
444+
445+
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
443446
const int horizontalDpi = qApp->desktop()->screen()->logicalDpiX();
447+
#else
448+
QScreen *screen = QGuiApplication::screenAt( mapToGlobal( QPoint( width() / 2, 0 ) ) );
449+
const int horizontalDpi = screen->logicalDotsPerInchX();
450+
#endif
451+
444452
// Adjust zoom: text is ok, but HTML seems rather big at least on Linux/KDE
445453
if ( horizontalDpi > 96 )
446454
{

0 commit comments

Comments
 (0)
Please sign in to comment.