From ce2bce52fd16a79cbb432e6dfd36c016df4c0f4b Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Wed, 24 Mar 2021 16:07:50 +0100 Subject: [PATCH] Switch QString ref functions to QStringView --- src/app/main.cpp | 10 ++++++++++ src/core/expression/qgsexpression.cpp | 12 ++++++++++++ src/core/qgscolorramp.cpp | 4 ++++ src/core/qgshstoreutils.cpp | 2 +- src/core/qgsogcutils.cpp | 10 ++++++++++ src/core/qgspostgresstringutils.cpp | 2 +- src/core/qgsstringutils.cpp | 8 ++++++++ src/providers/postgres/qgspostgresprovider.cpp | 10 +++++----- src/server/services/wms/qgswmsparameters.cpp | 4 ++++ tests/bench/main.cpp | 10 +++++++++- 10 files changed, 64 insertions(+), 8 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index 159495b024d..7883dba272d 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -1434,7 +1434,11 @@ int main( int argc, char *argv[] ) break; } +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) coords[i] = myInitialExtent.midRef( posOld, pos - posOld ).toDouble( &ok ); +#else + coords[i] = QStringView {myInitialExtent}.mid( posOld, pos - posOld ).toDouble( &ok ); +#endif if ( !ok ) break; @@ -1443,7 +1447,13 @@ int main( int argc, char *argv[] ) // parse last coordinate if ( ok ) + { +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok ); +#else + coords[3] = QStringView {myInitialExtent}.mid( posOld ).toDouble( &ok ); +#endif + } if ( !ok ) { diff --git a/src/core/expression/qgsexpression.cpp b/src/core/expression/qgsexpression.cpp index 8e8f734f51c..ef382089a8a 100644 --- a/src/core/expression/qgsexpression.cpp +++ b/src/core/expression/qgsexpression.cpp @@ -452,7 +452,11 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx if ( exp.hasParserError() ) { QgsDebugMsg( "Expression parser error: " + exp.parserErrorString() ); +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) expr_action += action.midRef( start, index - start ); +#else + expr_action += QStringView {action}.mid( start, index - start ); +#endif continue; } @@ -467,7 +471,11 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx if ( exp.hasEvalError() ) { QgsDebugMsg( "Expression parser eval error: " + exp.evalErrorString() ); +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) expr_action += action.midRef( start, index - start ); +#else + expr_action += QStringView {action}.mid( start, index - start ); +#endif continue; } @@ -475,7 +483,11 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx expr_action += action.mid( start, pos - start ) + result.toString(); } +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) expr_action += action.midRef( index ); +#else + expr_action += QStringView {action}.mid( index ).toString(); +#endif return expr_action; } diff --git a/src/core/qgscolorramp.cpp b/src/core/qgscolorramp.cpp index d03b1d4559c..c7036a75c6d 100644 --- a/src/core/qgscolorramp.cpp +++ b/src/core/qgscolorramp.cpp @@ -75,7 +75,11 @@ QgsColorRamp *QgsGradientColorRamp::create( const QVariantMap &props ) continue; QColor c = QgsSymbolLayerUtils::decodeColor( stop.mid( i + 1 ) ); +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) stops.append( QgsGradientStop( stop.leftRef( i ).toDouble(), c ) ); +#else + stops.append( QgsGradientStop( QStringView {stop}.left( i ).toDouble(), c ) ); +#endif } } diff --git a/src/core/qgshstoreutils.cpp b/src/core/qgshstoreutils.cpp index 0ac890251a4..e28bdb04c9d 100644 --- a/src/core/qgshstoreutils.cpp +++ b/src/core/qgshstoreutils.cpp @@ -42,7 +42,7 @@ QVariantMap QgsHstoreUtils::parse( const QString &string ) while ( i < string.length() && string.at( i ).isSpace() ) ++i; - if ( string.midRef( i ).startsWith( sep ) ) + if ( QStringView{string}.mid( i ).startsWith( sep ) ) { i += sep.length(); } diff --git a/src/core/qgsogcutils.cpp b/src/core/qgsogcutils.cpp index 51dd28111f1..be0cac77d72 100644 --- a/src/core/qgsogcutils.cpp +++ b/src/core/qgsogcutils.cpp @@ -2680,8 +2680,13 @@ QDomElement QgsOgcUtilsSQLStatementToFilter::toOgcFilter( const QgsSQLStatement: static QString mapBinarySpatialToOgc( const QString &name ) { QString nameCompare( name ); +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) if ( name.size() > 3 && name.midRef( 0, 3 ).compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 ) nameCompare = name.mid( 3 ); +#else + if ( name.size() > 3 && QStringView {name}.mid( 0, 3 ).toString().compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 ) + nameCompare = name.mid( 3 ); +#endif QStringList spatialOps; spatialOps << QStringLiteral( "BBOX" ) << QStringLiteral( "Intersects" ) << QStringLiteral( "Contains" ) << QStringLiteral( "Crosses" ) << QStringLiteral( "Equals" ) << QStringLiteral( "Disjoint" ) << QStringLiteral( "Overlaps" ) << QStringLiteral( "Touches" ) << QStringLiteral( "Within" ); @@ -2697,8 +2702,13 @@ static QString mapBinarySpatialToOgc( const QString &name ) static QString mapTernarySpatialToOgc( const QString &name ) { QString nameCompare( name ); +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) if ( name.size() > 3 && name.midRef( 0, 3 ).compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 ) nameCompare = name.mid( 3 ); +#else + if ( name.size() > 3 && QStringView {name}.mid( 0, 3 ).compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 ) + nameCompare = name.mid( 3 ); +#endif if ( nameCompare.compare( QLatin1String( "DWithin" ), Qt::CaseInsensitive ) == 0 ) return QStringLiteral( "DWithin" ); if ( nameCompare.compare( QLatin1String( "Beyond" ), Qt::CaseInsensitive ) == 0 ) diff --git a/src/core/qgspostgresstringutils.cpp b/src/core/qgspostgresstringutils.cpp index f347caece8a..f2bf5e62441 100644 --- a/src/core/qgspostgresstringutils.cpp +++ b/src/core/qgspostgresstringutils.cpp @@ -40,7 +40,7 @@ QString QgsPostgresStringUtils::getNextString( const QString &txt, int &i, const } i += stringRe.cap( 1 ).length() + 2; jumpSpace( txt, i ); - if ( !txt.midRef( i ).startsWith( sep ) && i < txt.length() ) + if ( !QStringView{txt}.mid( i ).startsWith( sep ) && i < txt.length() ) { QgsMessageLog::logMessage( QObject::tr( "Cannot find separator: %1" ).arg( txt.mid( i ) ), QObject::tr( "PostgresStringUtils" ) ); return QString(); diff --git a/src/core/qgsstringutils.cpp b/src/core/qgsstringutils.cpp index 86295a3e9aa..13f90e5f77e 100644 --- a/src/core/qgsstringutils.cpp +++ b/src/core/qgsstringutils.cpp @@ -635,13 +635,21 @@ QString QgsStringUtils::wordWrap( const QString &string, const int length, const } if ( strHit > -1 ) { +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) newstr.append( lines.at( i ).midRef( strCurrent, strHit - strCurrent ) ); +#else + newstr.append( QStringView {lines.at( i )}.mid( strCurrent, strHit - strCurrent ) ); +#endif newstr.append( '\n' ); strCurrent = strHit + delimiterLength; } else { +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) newstr.append( lines.at( i ).midRef( strCurrent ) ); +#else + newstr.append( QStringView {lines.at( i )}.mid( strCurrent ) ); +#endif strCurrent = strLength; } } diff --git a/src/providers/postgres/qgspostgresprovider.cpp b/src/providers/postgres/qgspostgresprovider.cpp index dc9afaec967..ddab1ae2209 100644 --- a/src/providers/postgres/qgspostgresprovider.cpp +++ b/src/providers/postgres/qgspostgresprovider.cpp @@ -4739,7 +4739,7 @@ QString QgsPostgresProvider::getNextString( const QString &txt, int &i, const QS } i += stringRe.cap( 1 ).length() + 2; jumpSpace( txt, i ); - if ( !txt.midRef( i ).startsWith( sep ) && i < txt.length() ) + if ( !QStringView{txt}.mid( i ).startsWith( sep ) && i < txt.length() ) { QgsMessageLog::logMessage( tr( "Cannot find separator: %1" ).arg( txt.mid( i ) ), tr( "PostGIS" ) ); return QString(); @@ -4752,14 +4752,14 @@ QString QgsPostgresProvider::getNextString( const QString &txt, int &i, const QS int start = i; for ( ; i < txt.length(); i++ ) { - if ( txt.midRef( i ).startsWith( sep ) ) + if ( QStringView{txt}.mid( i ).startsWith( sep ) ) { - QStringRef r( txt.midRef( start, i - start ) ); + QStringView v( QStringView{txt}.mid( start, i - start ) ); i += sep.length(); - return r.trimmed().toString(); + return v.trimmed().toString(); } } - return txt.midRef( start, i - start ).trimmed().toString(); + return QStringView{txt}.mid( start, i - start ).trimmed().toString(); } } diff --git a/src/server/services/wms/qgswmsparameters.cpp b/src/server/services/wms/qgswmsparameters.cpp index b18b76610fb..b07b3005f7f 100644 --- a/src/server/services/wms/qgswmsparameters.cpp +++ b/src/server/services/wms/qgswmsparameters.cpp @@ -570,7 +570,11 @@ namespace QgsWms const QRegExp composerParamRegExp( QStringLiteral( "^MAP\\d+:" ), Qt::CaseInsensitive ); if ( key.contains( composerParamRegExp ) ) { +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) const int mapId = key.midRef( 3, key.indexOf( ':' ) - 3 ).toInt(); +#else + const int mapId = QStringView {key}.mid( 3, key.indexOf( ':' ) - 3 ).toInt(); +#endif const QString theKey = key.mid( key.indexOf( ':' ) + 1 ); const QgsWmsParameter::Name name = QgsWmsParameter::name( theKey ); diff --git a/tests/bench/main.cpp b/tests/bench/main.cpp index 455653936eb..dcaaec6cd04 100644 --- a/tests/bench/main.cpp +++ b/tests/bench/main.cpp @@ -562,8 +562,11 @@ int main( int argc, char *argv[] ) ok = false; break; } - +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) coords[i] = myInitialExtent.midRef( posOld, pos - posOld ).toDouble( &ok ); +#else + coords[i] = QStringView {myInitialExtent}.mid( posOld, pos - posOld ).toDouble( &ok ); +#endif if ( !ok ) break; @@ -571,8 +574,13 @@ int main( int argc, char *argv[] ) } // parse last coordinate +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) if ( ok ) coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok ); +#else + if ( ok ) + coords[3] = QStringView {myInitialExtent}.mid( posOld ).toDouble( &ok ); +#endif if ( !ok ) {