Skip to content
Permalink
Browse files

Fix some Qt 5.13 deprecation warnings

  • Loading branch information
nyalldawson committed Jan 14, 2020
1 parent 527eca9 commit 6bbe28bcf71b8e30a602d9128c5e69c9ceda9aec
@@ -195,7 +195,7 @@ QgsLayoutGuideCollection::QgsLayoutGuideCollection( QgsLayout *layout, QgsLayout
, mPageCollection( pageCollection )
{
QFont f;
mHeaderSize = QFontMetrics( f ).width( QStringLiteral( "XX" ) );
mHeaderSize = QFontMetrics( f ).boundingRect( QStringLiteral( "XX" ) ).width();

connect( mPageCollection, &QgsLayoutPageCollection::pageAboutToBeRemoved, this, &QgsLayoutGuideCollection::pageAboutToBeRemoved );
}
@@ -42,7 +42,7 @@ QgsLayoutItemPage::QgsLayoutItemPage( QgsLayout *layout )

QFont font;
QFontMetrics fm( font );
mMaximumShadowWidth = fm.width( QStringLiteral( "X" ) );
mMaximumShadowWidth = fm.boundingRect( QStringLiteral( "X" ) ).width();

mGrid.reset( new QgsLayoutItemPageGrid( pos().x(), pos().y(), rect().width(), rect().height(), mLayout ) );
mGrid->setParentItem( this );
@@ -111,7 +111,11 @@ void QgsFeatureListViewDelegate::paint( QPainter *painter, const QStyleOptionVie
if ( conditionalIcon.isValid() )
{
const QPixmap pixmap = conditionalIcon.value< QPixmap >();
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
iconLayoutBounds.moveLeft( iconLayoutBounds.x() + icon.width() + QFontMetrics( textOption.font ).width( 'X' ) );
#else
iconLayoutBounds.moveLeft( iconLayoutBounds.x() + icon.width() + QFontMetrics( textOption.font ).horizontalAdvance( 'X' ) );
#endif
iconLayoutBounds.setTop( option.rect.y() + ( option.rect.height() - pixmap.height() ) / 2.0 );
iconLayoutBounds.setHeight( pixmap.height() );
drawDecoration( painter, iconOption, iconLayoutBounds, pixmap );
@@ -192,7 +192,12 @@ void QgsFieldConditionalFormatWidget::reloadStyles()

const auto constGetStyles = getStyles();

#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
const QSize size( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 10, Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 2 );
#else
const QSize size( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 10, Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 2 );
#endif

listView->setIconSize( size );

for ( const QgsConditionalStyle &style : constGetStyles )
@@ -63,7 +63,13 @@ QgsColorRampShaderWidget::QgsColorRampShaderWidget( QWidget *parent )

mSwatchDelegate = new QgsColorSwatchDelegate( this );
mColormapTreeWidget->setItemDelegateForColumn( ColorColumn, mSwatchDelegate );

#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
mColormapTreeWidget->setColumnWidth( ColorColumn, Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 6.6 );
#else
mColormapTreeWidget->setColumnWidth( ColorColumn, Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 6.6 );
#endif

mColormapTreeWidget->setContextMenuPolicy( Qt::CustomContextMenu );
mColormapTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
connect( mColormapTreeWidget, &QTreeView::customContextMenuRequested, this, [ = ]( QPoint ) { contextMenu->exec( QCursor::pos() ); } );
@@ -66,7 +66,12 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, con

mSwatchDelegate = new QgsColorSwatchDelegate( this );
mTreeView->setItemDelegateForColumn( QgsPalettedRendererModel::ColorColumn, mSwatchDelegate );

#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
mTreeView->setColumnWidth( QgsPalettedRendererModel::ColorColumn, Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 6.6 );
#else
mTreeView->setColumnWidth( QgsPalettedRendererModel::ColorColumn, Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 6.6 );
#endif
mTreeView->setContextMenuPolicy( Qt::CustomContextMenu );
mTreeView->setSelectionMode( QAbstractItemView::ExtendedSelection );
mTreeView->setDragEnabled( true );
@@ -1381,7 +1381,7 @@ void QgsRasterLayerProperties::adjustTransparencyCellWidth( int row, int column
QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( tableTransparency->cellWidget( row, column ) );
if ( !lineEdit ) return;

int width = std::max( lineEdit->fontMetrics().width( lineEdit->text() ) + 10, 100 );
int width = std::max( lineEdit->fontMetrics().boundingRect( lineEdit->text() ).width() + 10, 100 );
width = std::max( width, tableTransparency->columnWidth( column ) );

lineEdit->setFixedWidth( width );
@@ -668,7 +668,7 @@ void QgsRasterTransparencyWidget::adjustTransparencyCellWidth( int row, int colu
QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( tableTransparency->cellWidget( row, column ) );
if ( !lineEdit ) return;

int width = std::max( lineEdit->fontMetrics().width( lineEdit->text() ) + 10, 100 );
int width = std::max( lineEdit->fontMetrics().boundingRect( lineEdit->text() ).width() + 10, 100 );
width = std::max( width, tableTransparency->columnWidth( column ) );

lineEdit->setFixedWidth( width );
@@ -271,7 +271,7 @@ void CharacterWidget::paintEvent( QPaintEvent *event )

if ( fontMetrics.inFont( QChar( key ) ) )
{
painter.drawText( column * mSquareSize + ( mSquareSize / 2 ) - fontMetrics.width( QChar( key ) ) / 2,
painter.drawText( column * mSquareSize + ( mSquareSize / 2 ) - fontMetrics.boundingRect( QChar( key ) ).width() / 2,
row * mSquareSize + 4 + fontMetrics.ascent(),
QString( QChar( key ) ) );
}
@@ -68,7 +68,11 @@ QgsEllipseSymbolLayerWidget::QgsEllipseSymbolLayerWidget( QgsVectorLayer *vl, QW
names << QStringLiteral( "circle" ) << QStringLiteral( "rectangle" ) << QStringLiteral( "diamond" ) << QStringLiteral( "cross" ) << QStringLiteral( "triangle" ) << QStringLiteral( "right_half_triangle" ) << QStringLiteral( "left_half_triangle" ) << QStringLiteral( "semi_circle" );

int size = mShapeListWidget->iconSize().width();
size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXX" ) ) ) ) );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 3 ) ) );
#else
size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 3 ) ) );
#endif
mShapeListWidget->setGridSize( QSize( size * 1.2, size * 1.2 ) );
mShapeListWidget->setIconSize( QSize( size, size ) );

@@ -118,7 +118,11 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle *style, QWidget
mModel = new QgsStyleModel( mStyle, this );
}

#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
double iconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 10;
#else
double iconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 10;
#endif
listItems->setIconSize( QSize( static_cast< int >( iconSize ), static_cast< int >( iconSize * 0.9 ) ) ); // ~100, 90 on low dpi

mModel->addDesiredIconSize( listItems->iconSize() );
@@ -244,9 +244,17 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent,
connect( exportAction, &QAction::triggered, this, &QgsStyleManagerDialog::exportItems );
btnShare->setMenu( shareMenu );

#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
double iconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 10;
#else
double iconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 10;
#endif
listItems->setIconSize( QSize( static_cast< int >( iconSize ), static_cast< int >( iconSize * 0.9 ) ) ); // ~100, 90 on low dpi
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
double treeIconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 2;
#else
double treeIconSize = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 2;
#endif
mSymbolTreeView->setIconSize( QSize( static_cast< int >( treeIconSize ), static_cast< int >( treeIconSize ) ) );

mModel = mStyle == QgsStyle::defaultStyle() ? new QgsCheckableStyleModel( QgsApplication::defaultStyleModel(), this, mReadOnly )
@@ -278,14 +278,17 @@ QVariant QgsSvgSelectorListModel::data( const QModelIndex &index, int role ) con

if ( role == Qt::DecorationRole ) // icon
{
QPixmap pixmap;
if ( !QPixmapCache::find( entry, pixmap ) )
QPixmap *pixmap = nullptr;
if ( !QPixmapCache::find( entry, pixmap ) || !pixmap )
{
pixmap = createPreview( entry );
QPixmapCache::insert( entry, pixmap );
QPixmap newPixmap = createPreview( entry );
QPixmapCache::insert( entry, newPixmap );
return newPixmap;
}
else
{
return *pixmap;
}

return pixmap;
}
else if ( role == Qt::UserRole || role == Qt::ToolTipRole )
{
@@ -382,7 +385,11 @@ QgsSvgSelectorWidget::QgsSvgSelectorWidget( QWidget *parent )

connect( mSvgSourceLineEdit, &QgsAbstractFileContentSourceLineEdit::sourceChanged, this, &QgsSvgSelectorWidget::svgSourceChanged );

mIconSize = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXX" ) ) ) ) );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
mIconSize = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 3 ) ) );
#else
mIconSize = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 3 ) ) );
#endif
mImagesListView->setGridSize( QSize( mIconSize * 1.2, mIconSize * 1.2 ) );

mGroupsTreeView->setHeaderHidden( true );
@@ -473,7 +473,11 @@ void QgsSimpleLineSymbolLayerWidget::updatePatternIcon()

// set tooltip
// create very large preview image
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 23 );
#else
int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 23 );
#endif
int height = static_cast< int >( width / 1.61803398875 ); // golden ratio

QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( previewSymbol.get(), QSize( width, height ), height / 20 );
@@ -539,7 +543,13 @@ QgsSimpleMarkerSymbolLayerWidget::QgsSimpleMarkerSymbolLayerWidget( QgsVectorLay
mSizeDDBtn->setSymbol( mAssistantPreviewSymbol );

int size = lstNames->iconSize().width();
size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXX" ) ) ) ) );

#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 3 ) ) );
#else
size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 3 ) ) );
#endif

lstNames->setGridSize( QSize( size * 1.2, size * 1.2 ) );
lstNames->setIconSize( QSize( size, size ) );

@@ -969,7 +979,11 @@ QgsFilledMarkerSymbolLayerWidget::QgsFilledMarkerSymbolLayerWidget( QgsVectorLay
mSizeDDBtn->setSymbol( mAssistantPreviewSymbol );

int size = lstNames->iconSize().width();
size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXX" ) ) ) ) );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 3 ) ) );
#else
size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 3 ) ) );
#endif
lstNames->setGridSize( QSize( size * 1.2, size * 1.2 ) );
lstNames->setIconSize( QSize( size, size ) );

@@ -2260,7 +2274,11 @@ QgsSvgMarkerSymbolLayerWidget::QgsSvgMarkerSymbolLayerWidget( QgsVectorLayer *vl
spinOffsetY->setClearValue( 0.0 );
spinAngle->setClearValue( 0.0 );

mIconSize = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXX" ) ) ) ) );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
mIconSize = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 4 ) ) );
#else
mIconSize = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 4 ) ) );
#endif
viewImages->setGridSize( QSize( mIconSize * 1.2, mIconSize * 1.2 ) );

populateList();

0 comments on commit 6bbe28b

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