Skip to content
Permalink
Browse files

Fix some Qt 5.15 deprecation warnings

  • Loading branch information
nyalldawson committed Oct 8, 2020
1 parent 2207c30 commit 43a181b07b30acfc1deb4df3a13b336ffe03a369
@@ -39,14 +39,19 @@ QString QgsAuthCertUtils::getSslProtocolName( QSsl::SslProtocol protocol )
{
case QSsl::SecureProtocols:
return QObject::tr( "SecureProtocols" );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
case QSsl::TlsV1SslV3:
return QObject::tr( "TlsV1SslV3" );
#endif
case QSsl::TlsV1_0:
return QObject::tr( "TlsV1" );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
// not supported by Qt 5.15+
case QSsl::SslV3:
return QObject::tr( "SslV3" );
case QSsl::SslV2:
return QObject::tr( "SslV2" );
#endif
default:
return QString();
}
@@ -32,6 +32,10 @@
#include <QVariant>
#include <QSqlDriver>

#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#include <QRandomGenerator>
#endif

#include <QtCrypto>

#ifndef QT_NO_SSL
@@ -847,21 +851,35 @@ const QString QgsAuthManager::uniqueConfigId() const
QTimer::singleShot( 3, &loop, &QEventLoop::quit );
loop.exec();

#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
uint seed = static_cast< uint >( QTime::currentTime().msec() );
qsrand( seed );
#endif

while ( true )
{
id.clear();
for ( int i = 0; i < len; i++ )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
switch ( qrand() % 2 )
#else
switch ( QRandomGenerator::system()->generate() % 2 )
#endif
{
case 0:
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
id += ( '0' + qrand() % 10 );
#else
id += ( '0' + QRandomGenerator::system()->generate() % 10 );
#endif
break;
case 1:
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
id += ( 'a' + qrand() % 26 );
#else
id += ( 'a' + QRandomGenerator::system()->generate() % 26 );
#endif
break;
}
}
@@ -997,7 +1015,7 @@ QString QgsAuthManager::configAuthMethodKey( const QString &authcfg ) const

QStringList QgsAuthManager::authMethodsKeys( const QString &dataprovider )
{
return authMethodsMap( dataprovider.toLower() ).uniqueKeys();
return authMethodsMap( dataprovider.toLower() ).keys();
}

QgsAuthMethod *QgsAuthManager::authMethod( const QString &authMethodKey )
@@ -2966,7 +2984,11 @@ void QgsAuthManager::writeToConsole( const QString &message,
msg += message;

QTextStream out( stdout, QIODevice::WriteOnly );
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
out << msg << endl;
#else
out << msg << Qt::endl;
#endif
}

void QgsAuthManager::tryToStartDbErase()
@@ -17,6 +17,10 @@
#include "qgsclassificationjenks.h"
#include "qgsapplication.h"

#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#include <QRandomGenerator>
#endif

QgsClassificationJenks::QgsClassificationJenks()
: QgsClassificationMethod()
{
@@ -88,10 +92,16 @@ QList<double> QgsClassificationJenks::calculateBreaks( double &minimum, double &

sample[ 0 ] = minimum;
sample[ 1 ] = maximum;

for ( int i = 2; i < sample.size(); i++ )
{
// pick a random integer from 0 to n

#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
double r = QRandomGenerator::global()->generate();
#else
double r = qrand();
#endif
int j = std::floor( r / RAND_MAX * ( values.size() - 1 ) );
sample[ i ] = values[ j ];
}
@@ -115,7 +115,11 @@ QgsStringMap QgsGlowEffect::properties() const

if ( mRamp )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
props.unite( mRamp->properties() );
#else
props.insert( mRamp->properties() );
#endif
}

return props;
@@ -78,7 +78,11 @@ QMap<QString, QgsLocatorFilter *> QgsLocator::prefixedFilters() const
{
if ( !filter->activePrefix().isEmpty() && filter->enabled() )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
filters.insertMulti( filter->activePrefix(), filter );
#else
filters.insert( filter->activePrefix(), filter );
#endif
}
}
return filters;
@@ -2446,7 +2446,11 @@ void buildSupportedRasterFileFilterAndExtensions( QString &fileFiltersString, QS
// the next driver
if ( !( myGdalDriverExtensions.isEmpty() || myGdalDriverLongName.isEmpty() ) )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
const QStringList splitExtensions = myGdalDriverExtensions.split( ' ', QString::SkipEmptyParts );
#else
const QStringList splitExtensions = myGdalDriverExtensions.split( ' ', Qt::SkipEmptyParts );
#endif

// XXX add check for SDTS; in that case we want (*CATD.DDF)
QString glob;
@@ -2524,7 +2528,11 @@ void buildSupportedRasterFileFilterAndExtensions( QString &fileFiltersString, QS
} // each loaded GDAL driver

// sort file filters alphabetically
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QStringList filters = fileFiltersString.split( QStringLiteral( ";;" ), QString::SkipEmptyParts );
#else
QStringList filters = fileFiltersString.split( QStringLiteral( ";;" ), Qt::SkipEmptyParts );
#endif
filters.sort();
fileFiltersString = filters.join( QStringLiteral( ";;" ) ) + ";;";

@@ -80,7 +80,11 @@ QgsMeshMemoryDataProvider *QgsMeshMemoryDataProvider::createProvider( const QStr

bool QgsMeshMemoryDataProvider::splitMeshSections( const QString &uri )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
const QStringList sections = uri.split( QStringLiteral( "---" ), QString::SkipEmptyParts );
#else
const QStringList sections = uri.split( QStringLiteral( "---" ), Qt::SkipEmptyParts );
#endif
if ( sections.size() != 2 )
{
setError( QgsError( tr( "Invalid mesh definition, does not contain 2 sections" ),
@@ -98,10 +102,18 @@ bool QgsMeshMemoryDataProvider::addMeshVertices( const QString &def )
{
QVector<QgsMeshVertex> vertices;

#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
const QStringList verticesCoords = def.split( '\n', QString::SkipEmptyParts );
#else
const QStringList verticesCoords = def.split( '\n', Qt::SkipEmptyParts );
#endif
for ( int i = 0; i < verticesCoords.size(); ++i )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
const QStringList coords = verticesCoords[i].split( ',', QString::SkipEmptyParts );
#else
const QStringList coords = verticesCoords[i].split( ',', Qt::SkipEmptyParts );
#endif
if ( coords.size() != 2 )
{
setError( QgsError( tr( "Invalid mesh definition, vertex definition does not contain x, y" ),
@@ -123,10 +135,18 @@ bool QgsMeshMemoryDataProvider::addMeshFacesOrEdges( const QString &def )
QVector<QgsMeshFace> faces;
QVector<QgsMeshEdge> edges;

#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
const QStringList elements = def.split( '\n', QString::SkipEmptyParts );
#else
const QStringList elements = def.split( '\n', Qt::SkipEmptyParts );
#endif
for ( int i = 0; i < elements.size(); ++i )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
const QStringList vertices = elements[i].split( ',', QString::SkipEmptyParts );
#else
const QStringList vertices = elements[i].split( ',', Qt::SkipEmptyParts );
#endif
if ( vertices.size() < 2 )
{
setError( QgsError( tr( "Invalid mesh definition, edge must contain at least 2 vertices" ),
@@ -171,8 +191,11 @@ bool QgsMeshMemoryDataProvider::addMeshFacesOrEdges( const QString &def )

bool QgsMeshMemoryDataProvider::splitDatasetSections( const QString &uri, QgsMeshMemoryDatasetGroup &datasetGroup )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
const QStringList sections = uri.split( QStringLiteral( "---" ), QString::SkipEmptyParts );

#else
const QStringList sections = uri.split( QStringLiteral( "---" ), Qt::SkipEmptyParts );
#endif
bool success = sections.size() > 2;
if ( !success )
{
@@ -202,8 +225,11 @@ bool QgsMeshMemoryDataProvider::splitDatasetSections( const QString &uri, QgsMes

bool QgsMeshMemoryDataProvider::setDatasetGroupType( const QString &def, QgsMeshMemoryDatasetGroup &datasetGroup )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
const QStringList types = def.split( ' ', QString::SkipEmptyParts );

#else
const QStringList types = def.split( ' ', Qt::SkipEmptyParts );
#endif
if ( types.size() != 3 )
{
setError( QgsError( tr( "Invalid type definition, must be Vertex/Edge/Face Vector/Scalar Name" ),
@@ -228,10 +254,18 @@ bool QgsMeshMemoryDataProvider::setDatasetGroupType( const QString &def, QgsMesh

bool QgsMeshMemoryDataProvider::addDatasetGroupMetadata( const QString &def, QgsMeshMemoryDatasetGroup &datasetGroup )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
const QStringList metadataLines = def.split( '\n', QString::SkipEmptyParts );
#else
const QStringList metadataLines = def.split( '\n', Qt::SkipEmptyParts );
#endif
for ( int i = 0; i < metadataLines.size(); ++i )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
const QStringList keyVal = metadataLines[i].split( ':', QString::SkipEmptyParts );
#else
const QStringList keyVal = metadataLines[i].split( ':', Qt::SkipEmptyParts );
#endif
if ( keyVal.size() != 2 )
{
setError( QgsError( tr( "Invalid dataset definition, dataset metadata does not contain key: value" ),
@@ -246,7 +280,11 @@ bool QgsMeshMemoryDataProvider::addDatasetGroupMetadata( const QString &def, Qgs

bool QgsMeshMemoryDataProvider::addDatasetValues( const QString &def, std::shared_ptr<QgsMeshMemoryDataset> &dataset, bool isScalar )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
const QStringList valuesLines = def.split( '\n', QString::SkipEmptyParts );
#else
const QStringList valuesLines = def.split( '\n', Qt::SkipEmptyParts );
#endif
// first line is time
if ( valuesLines.size() < 2 )
{
@@ -259,7 +297,11 @@ bool QgsMeshMemoryDataProvider::addDatasetValues( const QString &def, std::share

for ( int i = 1; i < valuesLines.size(); ++i )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
const QStringList values = valuesLines[i].split( ',', QString::SkipEmptyParts );
#else
const QStringList values = valuesLines[i].split( ',', Qt::SkipEmptyParts );
#endif
QgsMeshDatasetValue point;

if ( isScalar )
@@ -3304,8 +3304,11 @@ QString createFilters( const QString &type )
QString myGdalDriverLongName = GDALGetMetadataItem( driver, GDAL_DMD_LONGNAME, "" );
if ( !( myGdalDriverExtensions.isEmpty() || myGdalDriverLongName.isEmpty() ) )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
const QStringList splitExtensions = myGdalDriverExtensions.split( ' ', QString::SkipEmptyParts );

#else
const QStringList splitExtensions = myGdalDriverExtensions.split( ' ', Qt::SkipEmptyParts );
#endif
QString glob;

for ( const QString &ext : splitExtensions )
@@ -3339,7 +3342,11 @@ QString createFilters( const QString &type )

// sort file filters alphabetically
QgsDebugMsgLevel( "myFileFilters: " + sFileFilters, 2 );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QStringList filters = sFileFilters.split( QStringLiteral( ";;" ), QString::SkipEmptyParts );
#else
QStringList filters = sFileFilters.split( QStringLiteral( ";;" ), Qt::SkipEmptyParts );
#endif
filters.sort();
sFileFilters = filters.join( QStringLiteral( ";;" ) ) + ";;";
QgsDebugMsgLevel( "myFileFilters: " + sFileFilters, 2 );
@@ -1542,8 +1542,13 @@ QString QgsApplication::absolutePathToRelativePath( const QString &aPath, const
const Qt::CaseSensitivity cs = Qt::CaseSensitive;
#endif

#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QStringList targetElems = tPathUrl.split( '/', QString::SkipEmptyParts );
QStringList aPathElems = aPathUrl.split( '/', QString::SkipEmptyParts );
#else
QStringList targetElems = tPathUrl.split( '/', Qt::SkipEmptyParts );
QStringList aPathElems = aPathUrl.split( '/', Qt::SkipEmptyParts );
#endif

targetElems.removeAll( QStringLiteral( "." ) );
aPathElems.removeAll( QStringLiteral( "." ) );
@@ -1601,8 +1606,13 @@ QString QgsApplication::relativePathToAbsolutePath( const QString &rpath, const
bool uncPath = targetPathUrl.startsWith( "//" );
#endif

#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QStringList srcElems = rPathUrl.split( '/', QString::SkipEmptyParts );
QStringList targetElems = targetPathUrl.split( '/', QString::SkipEmptyParts );
#else
QStringList srcElems = rPathUrl.split( '/', Qt::SkipEmptyParts );
QStringList targetElems = targetPathUrl.split( '/', Qt::SkipEmptyParts );
#endif

#if defined(Q_OS_WIN)
if ( uncPath )
@@ -132,14 +132,14 @@ void QgsBrowserModel::addRootItems()
#endif

// container for displaying providers as sorted groups (by QgsDataProvider::DataCapability enum)
QMap<int, QgsDataItem *> providerMap;
QMultiMap<int, QgsDataItem *> providerMap;

const auto constProviders = QgsApplication::dataItemProviderRegistry()->providers();
for ( QgsDataItemProvider *pr : constProviders )
{
if ( QgsDataItem *item = addProviderRootItem( pr ) )
{
providerMap.insertMulti( pr->capabilities(), item );
providerMap.insert( pr->capabilities(), item );
}
}

@@ -1047,7 +1047,7 @@ void QgsCoordinateTransform::addToCache()
if ( sDisableCache )
return;

sTransforms.insertMulti( qMakePair( sourceKey, destKey ), *this );
sTransforms.insert( qMakePair( sourceKey, destKey ), *this );
}

int QgsCoordinateTransform::sourceDatumTransformId() const
@@ -131,9 +131,17 @@ bool QgsCredentialsConsole::request( const QString &realm, QString &username, QS
QTextStream in( stdin, QIODevice::ReadOnly );
QTextStream out( stdout, QIODevice::WriteOnly );

#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
out << "credentials for " << realm << endl;
#else
out << "credentials for " << realm << Qt::endl;
#endif
if ( !message.isEmpty() )
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
out << "message: " << message << endl;
#else
out << "message: " << message << Qt::endl;
#endif
out << "username: ";
in >> username;
out << "password: ";
@@ -43,7 +43,11 @@ const QString QgsDartMeasurement::toString() const
void QgsDartMeasurement::send() const
{
QTextStream out( stdout );
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
out << toString() << endl;
#else
out << toString() << Qt::endl;
#endif
}

const QString QgsDartMeasurement::typeToString( QgsDartMeasurement::Type type )

0 comments on commit 43a181b

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