Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix some Qt 5.15 deprecation warnings
  • Loading branch information
nyalldawson committed Oct 8, 2020
1 parent 2207c30 commit 43a181b
Show file tree
Hide file tree
Showing 29 changed files with 252 additions and 21 deletions.
5 changes: 5 additions & 0 deletions src/core/auth/qgsauthcertutils.cpp
Expand Up @@ -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();
}
Expand Down
24 changes: 23 additions & 1 deletion src/core/auth/qgsauthmanager.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions src/core/classification/qgsclassificationjenks.cpp
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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 ];
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/effects/qgsgloweffect.cpp
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/core/locator/qgslocator.cpp
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/core/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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( ";;" ) ) + ";;";

Expand Down
46 changes: 44 additions & 2 deletions src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp
Expand Up @@ -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" ),
Expand All @@ -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" ),
Expand All @@ -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" ),
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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" ),
Expand All @@ -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" ),
Expand All @@ -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 )
{
Expand All @@ -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 )
Expand Down
9 changes: 8 additions & 1 deletion src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsapplication.cpp
Expand Up @@ -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( "." ) );
Expand Down Expand Up @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsbrowsermodel.cpp
Expand Up @@ -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 );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgscoordinatetransform.cpp
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgscredentials.cpp
Expand Up @@ -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: ";
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsdartmeasurement.cpp
Expand Up @@ -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 )
Expand Down

0 comments on commit 43a181b

Please sign in to comment.