Skip to content
Permalink
Browse files

Deprecation warning fixes

  • Loading branch information
nyalldawson committed Jan 30, 2020
1 parent 4ca2bbb commit 3aaeb81df016164af6b280a7a77eb8f595d1fbe3
@@ -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 )
@@ -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();
@@ -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 );
@@ -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 );
@@ -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 );
}

@@ -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 );
}

@@ -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 );
}

@@ -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
}
}

@@ -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() ) );
@@ -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 )
@@ -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();
@@ -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 );
@@ -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
@@ -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 );
}
@@ -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 ) );
}

@@ -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 );
@@ -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 )
@@ -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 )
{

0 comments on commit 3aaeb81

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