Skip to content
Permalink
Browse files

Fix some qt deprecation warnings

  • Loading branch information
nyalldawson committed Jan 28, 2020
1 parent ba42420 commit 459f9a4293a297e6a6884d706293876b6213fe6c
@@ -53,7 +53,7 @@ QgsAuthMethodRegistry::QgsAuthMethodRegistry( const QString &pluginPath )
QString baseDir = appDir.left( bin );
QString mLibraryDirectory = baseDir + "/lib";
#endif
mLibraryDirectory = pluginPath;
mLibraryDirectory.setPath( pluginPath );
mLibraryDirectory.setSorting( QDir::Name | QDir::IgnoreCase );
mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );

@@ -435,7 +435,7 @@ QString QgsFontUtils::translateNamedStyle( const QString &namedStyle )
QStringList words = namedStyle.split( ' ', QString::SkipEmptyParts );
for ( int i = 0, n = words.length(); i < n; ++i )
{
words[i] = QCoreApplication::translate( "QFontDatabase", words[i].toUtf8(), nullptr, QCoreApplication::UnicodeUTF8 );
words[i] = QCoreApplication::translate( "QFontDatabase", words[i].toLocal8Bit().constData() );
}
return words.join( QStringLiteral( " " ) );
}
@@ -94,7 +94,7 @@ QgsProviderRegistry::QgsProviderRegistry( const QString &pluginPath )
QString baseDir = appDir.left( bin );
QString mLibraryDirectory = baseDir + "/lib";
#endif
mLibraryDirectory = pluginPath;
mLibraryDirectory.setPath( pluginPath );
init();
}

@@ -127,7 +127,11 @@ QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const
std::unique_ptr< QgsSymbol > symbol( mStyle->symbol( name ) );
if ( symbol )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 23 );
#else
int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).horizontalAdvance( 'X' ) * 23 );
#endif
int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), QSize( width, height ), height / 20, nullptr, false, mExpressionContext.get() );
QByteArray data;
@@ -140,7 +144,11 @@ QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const

case QgsStyle::TextFormatEntity:
{
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 23 );
#else
int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).horizontalAdvance( 'X' ) * 23 );
#endif
int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
const QgsTextFormat format = mStyle->textFormat( name );
QPixmap pm = QgsTextFormat::textFormatPreviewPixmap( format, QSize( width, height ), QString(), height / 20 );
@@ -153,7 +161,11 @@ QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const

case QgsStyle::LabelSettingsEntity:
{
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 23 );
#else
int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).horizontalAdvance( 'X' ) * 23 );
#endif
int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
const QgsPalLayerSettings settings = mStyle->labelSettings( name );
QPixmap pm = QgsPalLayerSettings::labelSettingsPreviewPixmap( settings, QSize( width, height ), QString(), height / 20 );
@@ -43,7 +43,7 @@ QgsLayoutRuler::QgsLayoutRuler( QWidget *parent, Qt::Orientation orientation )
//calculate ruler sizes and marker separations

//minimum gap required between major ticks is 3 digits * 250%, based on appearance
mScaleMinPixelsWidth = mRulerFontMetrics->width( QStringLiteral( "000" ) ) * 2.5;
mScaleMinPixelsWidth = mRulerFontMetrics->boundingRect( QStringLiteral( "000" ) ).width() * 2.5;
//minimum ruler height is twice the font height in pixels
mRulerMinSize = mRulerFontMetrics->height() * 1.5;

@@ -56,7 +56,11 @@ QgsLayoutRuler::QgsLayoutRuler( QWidget *parent, Qt::Orientation orientation )
mTextBaseline = mRulerMinSize / 1.667;
mMinSpacingVerticalLabels = mRulerMinSize / 5;

#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
double guideMarkerSize = mRulerFontMetrics->width( QStringLiteral( "*" ) );
#else
double guideMarkerSize = mRulerFontMetrics->horizontalAdvance( '*' );
#endif
mDragGuideTolerance = guideMarkerSize;
switch ( mOrientation )
{
@@ -187,7 +191,7 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
p.drawLine( 0, pixelCoord, mRulerMinSize, pixelCoord );
//calc size of label
QString label = QString::number( beforePageCoord );
int labelSize = mRulerFontMetrics->width( label );
int labelSize = mRulerFontMetrics->boundingRect( label ).width();

//draw label only if it fits in before start of next page
if ( pixelCoord + labelSize + 8 < firstPageY )
@@ -235,7 +239,7 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
p.drawLine( 0, pixelCoord, mRulerMinSize, pixelCoord );
//calc size of label
QString label = QString::number( pageCoord );
int labelSize = mRulerFontMetrics->width( label );
int labelSize = mRulerFontMetrics->boundingRect( label ).width();

//draw label only if it fits in before start of next page
if ( ( pixelCoord + labelSize + 8 < nextPageStartPixel )
@@ -1263,7 +1263,11 @@ QgsLayoutViewSnapMarker::QgsLayoutViewSnapMarker()
{
QFont f;
QFontMetrics fm( f );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
mSize = fm.width( QStringLiteral( "X" ) );
#else
mSize = fm.horizontalAdvance( 'X' );
#endif
setPen( QPen( Qt::transparent, mSize ) );

setFlags( flags() | QGraphicsItem::ItemIgnoresTransformations );
@@ -41,7 +41,7 @@ QgsLocatorWidget::QgsLocatorWidget( QWidget *parent )
mLineEdit->setPlaceholderText( tr( "Type to locate (Ctrl+K)" ) );
#endif

int placeholderMinWidth = mLineEdit->fontMetrics().width( mLineEdit->placeholderText() );
int placeholderMinWidth = mLineEdit->fontMetrics().boundingRect( mLineEdit->placeholderText() ).width();
int minWidth = std::max( 200, static_cast< int >( placeholderMinWidth * 1.8 ) );
resize( minWidth, 30 );
QSizePolicy sizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
@@ -856,7 +856,11 @@ QWidget *QgsProcessingDistanceWidgetWrapper::createWidget()
mUnitsCombo->addItem( QgsUnitTypes::toString( QgsUnitTypes::DistanceMiles ), QgsUnitTypes::DistanceMiles );
mUnitsCombo->addItem( QgsUnitTypes::toString( QgsUnitTypes::DistanceYards ), QgsUnitTypes::DistanceYards );

#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
const int labelMargin = static_cast< int >( std::round( mUnitsCombo->fontMetrics().width( 'X' ) ) );
#else
const int labelMargin = static_cast< int >( std::round( mUnitsCombo->fontMetrics().horizontalAdvance( 'X' ) ) );
#endif
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget( spin, 1 );
layout->insertSpacing( 1, labelMargin / 2 );
@@ -183,7 +183,11 @@ bool QgsColorButton::event( QEvent *e )
int saturation = c.saturation();

// create very large preview swatch
#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

int margin = static_cast< int >( height * 0.1 );
@@ -41,10 +41,24 @@ QgsColorSwatchGrid::QgsColorSwatchGrid( QgsColorScheme *scheme, const QString &c
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );

mLabelHeight = Qgis::UI_SCALE_FACTOR * fontMetrics().height();

#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( '.' );
#endif

#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
mSwatchSize = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "X" ) ) * 1.75;
#else
mSwatchSize = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 1.75;
#endif

#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
mSwatchOutlineSize = std::max( fontMetrics().width( QStringLiteral( "." ) ) * 0.4, 1.0 );
#else
mSwatchOutlineSize = std::max( fontMetrics().horizontalAdvance( '.' ) * 0.4, 1.0 );
#endif

mSwatchSpacing = mSwatchSize * 0.3;
mSwatchMargin = mLabelMargin;
@@ -123,7 +137,11 @@ void QgsColorSwatchGrid::updateTooltip( const int colorIdx )
QString colorName = mColors.at( colorIdx ).second;

// create very large preview swatch, because the grid itself has only tiny preview icons
#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
int margin = static_cast< int >( height * 0.1 );
QImage icon = QImage( width + 2 * margin, height + 2 * margin, QImage::Format_ARGB32 );
@@ -862,7 +862,7 @@ void QgsRasterLayerSaveAsDialog::adjustNoDataCellWidth( int row, int column )
QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( mNoDataTableWidget->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, mNoDataTableWidget->columnWidth( column ) );

lineEdit->setFixedWidth( width );
@@ -191,11 +191,11 @@ class SymbolLayerItem : public QStandardItem
switch ( mSymbol->type() )
{
case QgsSymbol::Marker :
return QCoreApplication::translate( "SymbolLayerItem", "Marker", nullptr, QCoreApplication::UnicodeUTF8 );
return QCoreApplication::translate( "SymbolLayerItem", "Marker" );
case QgsSymbol::Fill :
return QCoreApplication::translate( "SymbolLayerItem", "Fill", nullptr, QCoreApplication::UnicodeUTF8 );
return QCoreApplication::translate( "SymbolLayerItem", "Fill" );
case QgsSymbol::Line :
return QCoreApplication::translate( "SymbolLayerItem", "Line", nullptr, QCoreApplication::UnicodeUTF8 );
return QCoreApplication::translate( "SymbolLayerItem", "Line" );
default:
return "Symbol";
}

0 comments on commit 459f9a4

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