Skip to content
Permalink
Browse files

Fix some qt deprecation warnings

  • Loading branch information
nyalldawson committed Jan 28, 2020
1 parent 8950b8c commit 92de4c72cbc3469e43d0a5f337c547d127101c4a
@@ -2535,7 +2535,11 @@ bool QgsAuthManager::removeCertAuthority( const QSslCertificate &cert )
const QList<QSslCertificate> QgsAuthManager::systemRootCAs()
{
#ifndef Q_OS_MAC
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
return QSslSocket::systemCaCertificates();
#else
return QSslConfiguration::systemCaCertificates();
#endif
#else
QNetworkRequest req;
return req.sslConfiguration().caCertificates();
@@ -37,10 +37,11 @@ QgsMemoryProvider::QgsMemoryProvider( const QString &uri, const ProviderOptions
// Initialize the geometry with the uri to support old style uri's
// (ie, just 'point', 'line', 'polygon')
QUrl url = QUrl::fromEncoded( uri.toUtf8() );
const QUrlQuery query( url );
QString geometry;
if ( url.hasQueryItem( QStringLiteral( "geometry" ) ) )
if ( query.hasQueryItem( QStringLiteral( "geometry" ) ) )
{
geometry = url.queryItemValue( QStringLiteral( "geometry" ) );
geometry = query.queryItemValue( QStringLiteral( "geometry" ) );
}
else
{
@@ -56,9 +57,9 @@ QgsMemoryProvider::QgsMemoryProvider( const QString &uri, const ProviderOptions
mWkbType = QgsWkbTypes::parseType( geometry );
}

if ( url.hasQueryItem( QStringLiteral( "crs" ) ) )
if ( query.hasQueryItem( QStringLiteral( "crs" ) ) )
{
QString crsDef = url.queryItemValue( QStringLiteral( "crs" ) );
QString crsDef = query.queryItemValue( QStringLiteral( "crs" ) );
mCrs.createFromString( crsDef );
}
else
@@ -108,7 +109,7 @@ QgsMemoryProvider::QgsMemoryProvider( const QString &uri, const ProviderOptions

);

if ( url.hasQueryItem( QStringLiteral( "field" ) ) )
if ( query.hasQueryItem( QStringLiteral( "field" ) ) )
{
QList<QgsField> attributes;
QRegExp reFieldDef( "\\:"
@@ -117,7 +118,7 @@ QgsMemoryProvider::QgsMemoryProvider( const QString &uri, const ProviderOptions
"(?:\\,(\\-?\\d+))?" // precision
"\\))?(\\[\\])?" // array
"$", Qt::CaseInsensitive );
QStringList fields = url.allQueryItemValues( QStringLiteral( "field" ) );
QStringList fields = query.allQueryItemValues( QStringLiteral( "field" ) );
for ( int i = 0; i < fields.size(); i++ )
{
QString name = QUrl::fromPercentEncoding( fields.at( i ).toUtf8() );
@@ -203,7 +204,7 @@ QgsMemoryProvider::QgsMemoryProvider( const QString &uri, const ProviderOptions
addAttributes( attributes );
}

if ( url.hasQueryItem( QStringLiteral( "index" ) ) && url.queryItemValue( QStringLiteral( "index" ) ) == QLatin1String( "yes" ) )
if ( query.hasQueryItem( QStringLiteral( "index" ) ) && query.queryItemValue( QStringLiteral( "index" ) ) == QLatin1String( "yes" ) )
{
createSpatialIndex();
}
@@ -240,8 +241,9 @@ QString QgsMemoryProvider::dataSourceUri( bool expandAuthConfig ) const
Q_UNUSED( expandAuthConfig )

QUrl uri( QStringLiteral( "memory" ) );
QUrlQuery query;
QString geometry = QgsWkbTypes::displayString( mWkbType );
uri.addQueryItem( QStringLiteral( "geometry" ), geometry );
query.addQueryItem( QStringLiteral( "geometry" ), geometry );

if ( mCrs.isValid() )
{
@@ -255,11 +257,11 @@ QString QgsMemoryProvider::dataSourceUri( bool expandAuthConfig ) const
{
crsDef = QStringLiteral( "wkt:%1" ).arg( mCrs.toWkt( QgsCoordinateReferenceSystem::WKT2_2018 ) );
}
uri.addQueryItem( QStringLiteral( "crs" ), crsDef );
query.addQueryItem( QStringLiteral( "crs" ), crsDef );
}
if ( mSpatialIndex )
{
uri.addQueryItem( QStringLiteral( "index" ), QStringLiteral( "yes" ) );
query.addQueryItem( QStringLiteral( "index" ), QStringLiteral( "yes" ) );
}

QgsAttributeList attrs = const_cast<QgsMemoryProvider *>( this )->attributeIndexes();
@@ -268,8 +270,9 @@ QString QgsMemoryProvider::dataSourceUri( bool expandAuthConfig ) const
QgsField field = mFields.at( attrs[i] );
QString fieldDef = field.name();
fieldDef.append( QStringLiteral( ":%2(%3,%4)" ).arg( field.typeName() ).arg( field.length() ).arg( field.precision() ) );
uri.addQueryItem( QStringLiteral( "field" ), fieldDef );
query.addQueryItem( QStringLiteral( "field" ), fieldDef );
}
uri.setQuery( query );

return QString( uri.toEncoded() );

@@ -591,9 +591,17 @@ QString QgsDataSourceUri::uri( bool expandAuthConfig ) const
return uri;
}

// from qurl.h
QByteArray toLatin1_helper( const QString &string )
{
if ( string.isEmpty() )
return string.isNull() ? QByteArray() : QByteArray( "" );
return string.toLatin1();
}

QByteArray QgsDataSourceUri::encodedUri() const
{
QUrl url;
QUrlQuery url;
for ( auto it = mParams.constBegin(); it != mParams.constEnd(); ++it )
{
url.addQueryItem( it.key(), it.value() );
@@ -608,7 +616,7 @@ QByteArray QgsDataSourceUri::encodedUri() const
if ( !mAuthConfigId.isEmpty() )
url.addQueryItem( QStringLiteral( "authcfg" ), mAuthConfigId );

return url.encodedQuery();
return toLatin1_helper( url.toString( QUrl::FullyEncoded ) );
}

void QgsDataSourceUri::setEncodedUri( const QByteArray &uri )
@@ -619,9 +627,10 @@ void QgsDataSourceUri::setEncodedUri( const QByteArray &uri )
mAuthConfigId.clear();

QUrl url;
url.setEncodedQuery( uri );
url.setQuery( QString::fromLatin1( uri ) );
const QUrlQuery query( url );

const auto constQueryItems = url.queryItems();
const auto constQueryItems = query.queryItems();
for ( const QPair<QString, QString> &item : constQueryItems )
{
if ( item.first == QLatin1String( "username" ) )
@@ -1891,7 +1891,7 @@ QString QgsVectorLayer::encodedSource( const QString &source, const QgsReadWrite
{
QUrl urlSource = QUrl::fromEncoded( src.toLatin1() );
QUrl urlDest = QUrl::fromLocalFile( context.pathResolver().writePath( urlSource.toLocalFile() ) );
urlDest.setQueryItems( urlSource.queryItems() );
urlDest.setQuery( urlSource.query() );
src = QString::fromLatin1( urlDest.toEncoded() );
}
else if ( providerType() == QLatin1String( "memory" ) )
@@ -1970,7 +1970,7 @@ QString QgsVectorLayer::decodedSource( const QString &source, const QString &pro
}

QUrl urlDest = QUrl::fromLocalFile( context.pathResolver().readPath( urlSource.toLocalFile() ) );
urlDest.setQueryItems( urlSource.queryItems() );
urlDest.setQuery( urlSource.query() );
src = QString::fromLatin1( urlDest.toEncoded() );
}
else if ( provider == QLatin1String( "virtual" ) )
@@ -39,7 +39,8 @@ QgsVirtualLayerDefinition QgsVirtualLayerDefinition::fromUrl( const QUrl &url )
QgsFields fields;

int layerIdx = 0;
QList<QPair<QByteArray, QByteArray> > items = url.encodedQueryItems();

const QList<QPair<QString, QString> > items = QUrlQuery( url ).queryItems( QUrl::FullyEncoded );
for ( int i = 0; i < items.size(); i++ )
{
QString key = items.at( i ).first;
@@ -463,7 +463,11 @@ QByteArray QgsRasterBlock::data() const
if ( mData )
return QByteArray::fromRawData( static_cast<const char *>( mData ), typeSize( mDataType ) * mWidth * mHeight );
else if ( mImage && mImage->constBits() )
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
return QByteArray::fromRawData( reinterpret_cast<const char *>( mImage->constBits() ), mImage->byteCount() );
#else
return QByteArray::fromRawData( reinterpret_cast<const char *>( mImage->constBits() ), mImage->sizeInBytes() );
#endif
else
return QByteArray();
}
@@ -480,7 +484,11 @@ void QgsRasterBlock::setData( const QByteArray &data, int offset )
}
else if ( mImage && mImage->constBits() )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
int len = std::min( data.size(), mImage->byteCount() - offset );
#else
qsizetype len = std::min( static_cast< qsizetype >( data.size() ), mImage->sizeInBytes() - offset );
#endif
::memcpy( mImage->bits() + offset, data.constData(), len );
}
}
@@ -2260,7 +2260,7 @@ void QgsSymbolLayerUtils::parametricSvgToSld( QDomDocument &doc, QDomElement &gr

QString QgsSymbolLayerUtils::getSvgParametricPath( const QString &basePath, const QColor &fillColor, const QColor &strokeColor, double strokeWidth )
{
QUrl url = QUrl();
QUrlQuery url;
if ( fillColor.isValid() )
{
url.addQueryItem( QStringLiteral( "fill" ), fillColor.name() );
@@ -2282,7 +2282,7 @@ QString QgsSymbolLayerUtils::getSvgParametricPath( const QString &basePath, cons
url.addQueryItem( QStringLiteral( "outline-opacity" ), QStringLiteral( "1" ) );
}
url.addQueryItem( QStringLiteral( "outline-width" ), QString::number( strokeWidth ) );
QString params = url.encodedQuery();
QString params = url.toString( QUrl::FullyEncoded );
if ( params.isEmpty() )
{
return basePath;
@@ -24,9 +24,13 @@ QgsMenuHeader::QgsMenuHeader( const QString &text, QWidget *parent )
: QWidget( parent )
, mText( text )
{
int textMinWidth = fontMetrics().width( mText );
int textMinWidth = fontMetrics().boundingRect( mText ).width();
mTextHeight = fontMetrics().height();
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
mLabelMargin = Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "." ) );
#else
mLabelMargin = Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( '.' );
#endif
mMinWidth = 2 * mLabelMargin + textMinWidth;
setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
updateGeometry();
@@ -221,7 +221,11 @@ QDBusArgument &operator<<( QDBusArgument &arg, const QImage &image )
int channels = i.isGrayscale() ? 1 : ( i.hasAlphaChannel() ? 4 : 3 );
arg << i.depth() / channels;
arg << channels;
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
arg << QByteArray( reinterpret_cast<const char *>( i.bits() ), i.numBytes() );
#else
arg << QByteArray( reinterpret_cast<const char *>( i.bits() ), i.sizeInBytes() );
#endif
arg.endStructure();
return arg;
}
@@ -172,15 +172,12 @@ bool QgsPostgresRasterProvider::hasSufficientPermsAndCapabilities()
return false;
}

bool inRecovery = false;

if ( connectionRO()->pgVersion() >= 90000 )
{
testAccess = connectionRO()->PQexec( QStringLiteral( "SELECT pg_is_in_recovery()" ) );
if ( testAccess.PQresultStatus() != PGRES_TUPLES_OK || testAccess.PQgetvalue( 0, 0 ) == QLatin1String( "t" ) )
{
QgsMessageLog::logMessage( tr( "PostgreSQL is still in recovery after a database crash\n(or you are connected to a (read-only) slave).\nWrite accesses will be denied." ), tr( "PostGIS" ) );
inRecovery = true;
}
}
}

0 comments on commit 92de4c7

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