Skip to content

Commit

Permalink
Deprecation warning fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 30, 2020
1 parent 4ca2bbb commit 3aaeb81
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/gui/editorwidgets/qgshtmlwidgetwrapper.cpp
Expand Up @@ -19,7 +19,7 @@
#include "qgsexpressioncontextutils.h"
#include "qgsapplication.h"
#include "qgswebframe.h"

#include <QScreen>

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

mWidget->setHtml( mHtmlCode );
#ifdef WITH_QTWEBKIT

#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
const int horizontalDpi = qApp->desktop()->screen()->logicalDpiX();
#else
QScreen *screen = QGuiApplication::screenAt( mWidget->mapToGlobal( QPoint( mWidget->width() / 2, 0 ) ) );
const int horizontalDpi = screen->logicalDotsPerInchX();
#endif

mWidget->setZoomFactor( horizontalDpi / 96.0 );

QWebPage *page = mWidget->page();
Expand Down
5 changes: 5 additions & 0 deletions src/gui/layout/qgslayoutitemslistview.cpp
Expand Up @@ -100,8 +100,13 @@ void QgsLayoutItemsListView::setCurrentLayout( QgsLayout *layout )

header()->setSectionResizeMode( 0, QHeaderView::Fixed );
header()->setSectionResizeMode( 1, QHeaderView::Fixed );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
setColumnWidth( 0, Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "xxxx" ) ) );
setColumnWidth( 1, Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "xxxx" ) ) );
#else
setColumnWidth( 0, Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'x' ) * 4 );
setColumnWidth( 1, Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'x' ) * 4 );
#endif
header()->setSectionsMovable( false );

connect( selectionModel(), &QItemSelectionModel::currentChanged, mModel, &QgsLayoutItemsListViewModel::setSelected );
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgscolorschemelist.cpp
Expand Up @@ -710,7 +710,12 @@ void QgsColorSwatchDelegate::paint( QPainter *painter, const QStyleOptionViewIte
}

QRect rect = option.rect;
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
const int iconSize = Qgis::UI_SCALE_FACTOR * option.fontMetrics.width( 'X' ) * 4;
#else
const int iconSize = Qgis::UI_SCALE_FACTOR * option.fontMetrics.horizontalAdvance( 'X' ) * 4;
#endif

const int cornerSize = iconSize / 6;
//center it
rect.setLeft( option.rect.center().x() - iconSize / 2 );
Expand Down Expand Up @@ -749,7 +754,11 @@ QSize QgsColorSwatchDelegate::sizeHint( const QStyleOptionViewItem &option, cons
{
Q_UNUSED( index )

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

Expand Down
24 changes: 24 additions & 0 deletions src/gui/qgscolorwidgets.cpp
Expand Up @@ -392,7 +392,11 @@ QgsColorWheel::~QgsColorWheel()

QSize QgsColorWheel::sizeHint() const
{
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int size = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) );
#else
int size = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 22;
#endif
return QSize( size, size );
}

Expand Down Expand Up @@ -750,7 +754,11 @@ QgsColorBox::~QgsColorBox()

QSize QgsColorBox::sizeHint() const
{
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int size = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) );
#else
int size = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 22;
#endif
return QSize( size, size );
}

Expand Down Expand Up @@ -981,12 +989,20 @@ QSize QgsColorRampWidget::sizeHint() const
if ( mOrientation == QgsColorRampWidget::Horizontal )
{
//horizontal
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ), Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.3 );
#else
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 22, Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.3 );
#endif
}
else
{
//vertical
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.3, Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ) );
#else
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.3, Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 22 );
#endif
}
}

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

mSpinBox = new QSpinBox();
//set spinbox to a reasonable width
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int largestCharWidth = mSpinBox->fontMetrics().width( QStringLiteral( "888%" ) );
#else
int largestCharWidth = mSpinBox->fontMetrics().horizontalAdvance( QStringLiteral( "888%" ) );
#endif
mSpinBox->setMinimumWidth( largestCharWidth + 35 );
mSpinBox->setMinimum( 0 );
mSpinBox->setMaximum( convertRealToDisplay( componentRange() ) );
Expand Down Expand Up @@ -1588,7 +1608,11 @@ void QgsColorPreviewWidget::paintEvent( QPaintEvent *event )

QSize QgsColorPreviewWidget::sizeHint() const
{
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ), Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXX" ) ) * 0.75 );
#else
return QSize( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 22, Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 22 * 0.75 );
#endif
}

void QgsColorPreviewWidget::setColor2( const QColor &color )
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgscompoundcolorwidget.cpp
Expand Up @@ -65,7 +65,12 @@ QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor &c
QgsSettings settings;

mSchemeList->header()->hide();
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
mSchemeList->setColumnWidth( 0, static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 6 ) );
#else
mSchemeList->setColumnWidth( 0, static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 6 ) );
#endif


//get schemes with ShowInColorDialog set
refreshSchemeComboBox();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsdetaileditemdelegate.cpp
Expand Up @@ -253,7 +253,7 @@ void QgsDetailedItemDelegate::paintAsWidget( QPainter *thepPainter,
{
drawHighlight( option, thepPainter, height( option, data ) );
}
QPixmap myPixmap = QPixmap::grabWidget( mpWidget );
QPixmap myPixmap = mpWidget->grab();
thepPainter->drawPixmap( option.rect.x(),
option.rect.y(),
myPixmap );
Expand Down Expand Up @@ -348,7 +348,7 @@ QStringList QgsDetailedItemDelegate::wordWrap( const QString &string,
myPreviousSpacePos = i;
}
myCumulativeLine += myChar;
if ( metrics.width( myCumulativeLine ) >= width )
if ( metrics.boundingRect( myCumulativeLine ).width() >= width )
{
//time to wrap
//TODO deal with long strings that have no spaces
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsfieldexpressionwidget.cpp
Expand Up @@ -323,7 +323,7 @@ void QgsFieldExpressionWidget::currentFieldChanged()

// display tooltip if widget is shorter than expression
QFontMetrics metrics( mCombo->lineEdit()->font() );
if ( metrics.width( fieldName ) > mCombo->lineEdit()->width() )
if ( metrics.boundingRect( fieldName ).width() > mCombo->lineEdit()->width() )
{
mCombo->setToolTip( fieldName );
}
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsfontbutton.cpp
Expand Up @@ -53,7 +53,11 @@ QgsFontButton::QgsFontButton( QWidget *parent, const QString &dialogTitle )
//make sure height of button looks good under different platforms
QSize size = QToolButton::minimumSizeHint();
int fontHeight = Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.4;
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int minWidth = Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 20;
#else
int minWidth = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 20;
#endif
mSizeHint = QSize( std::max( minWidth, size.width() ), std::max( size.height(), fontHeight ) );
}

Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsratiolockbutton.cpp
Expand Up @@ -27,7 +27,11 @@ QgsRatioLockButton::QgsRatioLockButton( QWidget *parent )
: QToolButton( parent )
{
setMinimumSize( QSize( 24, 24 ) );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
setMaximumWidth( fontMetrics().width( QStringLiteral( "000" ) ) );
#else
setMaximumWidth( fontMetrics().horizontalAdvance( '0' ) * 3 );
#endif
setCheckable( true );
setAutoRaise( true );
connect( this, &QPushButton::clicked, this, &QgsRatioLockButton::buttonClicked );
Expand Down
8 changes: 8 additions & 0 deletions src/gui/raster/qgsrasterlayerproperties.cpp
Expand Up @@ -76,6 +76,7 @@
#include <QVector>
#include <QUrl>
#include <QMenu>
#include <QScreen>

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

#ifdef WITH_QTWEBKIT
// Setup information tab

#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
const int horizontalDpi = qApp->desktop()->screen()->logicalDpiX();
#else
QScreen *screen = QGuiApplication::screenAt( mapToGlobal( QPoint( width() / 2, 0 ) ) );
const int horizontalDpi = screen->logicalDotsPerInchX();
#endif

// Adjust zoom: text is ok, but HTML seems rather big at least on Linux/KDE
if ( horizontalDpi > 96 )
{
Expand Down

0 comments on commit 3aaeb81

Please sign in to comment.