Switch QString ref functions to QStringView

This commit is contained in:
Matthias Kuhn 2021-03-24 16:07:50 +01:00 committed by Nyall Dawson
parent 08c1275e0e
commit ce2bce52fd
10 changed files with 64 additions and 8 deletions

View File

@ -1434,7 +1434,11 @@ int main( int argc, char *argv[] )
break; break;
} }
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
coords[i] = myInitialExtent.midRef( posOld, pos - posOld ).toDouble( &ok ); coords[i] = myInitialExtent.midRef( posOld, pos - posOld ).toDouble( &ok );
#else
coords[i] = QStringView {myInitialExtent}.mid( posOld, pos - posOld ).toDouble( &ok );
#endif
if ( !ok ) if ( !ok )
break; break;
@ -1443,7 +1447,13 @@ int main( int argc, char *argv[] )
// parse last coordinate // parse last coordinate
if ( ok ) if ( ok )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok ); coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok );
#else
coords[3] = QStringView {myInitialExtent}.mid( posOld ).toDouble( &ok );
#endif
}
if ( !ok ) if ( !ok )
{ {

View File

@ -452,7 +452,11 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
if ( exp.hasParserError() ) if ( exp.hasParserError() )
{ {
QgsDebugMsg( "Expression parser error: " + exp.parserErrorString() ); QgsDebugMsg( "Expression parser error: " + exp.parserErrorString() );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
expr_action += action.midRef( start, index - start ); expr_action += action.midRef( start, index - start );
#else
expr_action += QStringView {action}.mid( start, index - start );
#endif
continue; continue;
} }
@ -467,7 +471,11 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
if ( exp.hasEvalError() ) if ( exp.hasEvalError() )
{ {
QgsDebugMsg( "Expression parser eval error: " + exp.evalErrorString() ); QgsDebugMsg( "Expression parser eval error: " + exp.evalErrorString() );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
expr_action += action.midRef( start, index - start ); expr_action += action.midRef( start, index - start );
#else
expr_action += QStringView {action}.mid( start, index - start );
#endif
continue; continue;
} }
@ -475,7 +483,11 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
expr_action += action.mid( start, pos - start ) + result.toString(); expr_action += action.mid( start, pos - start ) + result.toString();
} }
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
expr_action += action.midRef( index ); expr_action += action.midRef( index );
#else
expr_action += QStringView {action}.mid( index ).toString();
#endif
return expr_action; return expr_action;
} }

View File

@ -75,7 +75,11 @@ QgsColorRamp *QgsGradientColorRamp::create( const QVariantMap &props )
continue; continue;
QColor c = QgsSymbolLayerUtils::decodeColor( stop.mid( i + 1 ) ); 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 ) ); stops.append( QgsGradientStop( stop.leftRef( i ).toDouble(), c ) );
#else
stops.append( QgsGradientStop( QStringView {stop}.left( i ).toDouble(), c ) );
#endif
} }
} }

View File

@ -42,7 +42,7 @@ QVariantMap QgsHstoreUtils::parse( const QString &string )
while ( i < string.length() && string.at( i ).isSpace() ) while ( i < string.length() && string.at( i ).isSpace() )
++i; ++i;
if ( string.midRef( i ).startsWith( sep ) ) if ( QStringView{string}.mid( i ).startsWith( sep ) )
{ {
i += sep.length(); i += sep.length();
} }

View File

@ -2680,8 +2680,13 @@ QDomElement QgsOgcUtilsSQLStatementToFilter::toOgcFilter( const QgsSQLStatement:
static QString mapBinarySpatialToOgc( const QString &name ) static QString mapBinarySpatialToOgc( const QString &name )
{ {
QString nameCompare( 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 ) if ( name.size() > 3 && name.midRef( 0, 3 ).compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 )
nameCompare = name.mid( 3 ); 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; QStringList spatialOps;
spatialOps << QStringLiteral( "BBOX" ) << QStringLiteral( "Intersects" ) << QStringLiteral( "Contains" ) << QStringLiteral( "Crosses" ) << QStringLiteral( "Equals" ) spatialOps << QStringLiteral( "BBOX" ) << QStringLiteral( "Intersects" ) << QStringLiteral( "Contains" ) << QStringLiteral( "Crosses" ) << QStringLiteral( "Equals" )
<< QStringLiteral( "Disjoint" ) << QStringLiteral( "Overlaps" ) << QStringLiteral( "Touches" ) << QStringLiteral( "Within" ); << QStringLiteral( "Disjoint" ) << QStringLiteral( "Overlaps" ) << QStringLiteral( "Touches" ) << QStringLiteral( "Within" );
@ -2697,8 +2702,13 @@ static QString mapBinarySpatialToOgc( const QString &name )
static QString mapTernarySpatialToOgc( const QString &name ) static QString mapTernarySpatialToOgc( const QString &name )
{ {
QString nameCompare( 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 ) if ( name.size() > 3 && name.midRef( 0, 3 ).compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 )
nameCompare = name.mid( 3 ); 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 ) if ( nameCompare.compare( QLatin1String( "DWithin" ), Qt::CaseInsensitive ) == 0 )
return QStringLiteral( "DWithin" ); return QStringLiteral( "DWithin" );
if ( nameCompare.compare( QLatin1String( "Beyond" ), Qt::CaseInsensitive ) == 0 ) if ( nameCompare.compare( QLatin1String( "Beyond" ), Qt::CaseInsensitive ) == 0 )

View File

@ -40,7 +40,7 @@ QString QgsPostgresStringUtils::getNextString( const QString &txt, int &i, const
} }
i += stringRe.cap( 1 ).length() + 2; i += stringRe.cap( 1 ).length() + 2;
jumpSpace( txt, i ); 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" ) ); QgsMessageLog::logMessage( QObject::tr( "Cannot find separator: %1" ).arg( txt.mid( i ) ), QObject::tr( "PostgresStringUtils" ) );
return QString(); return QString();

View File

@ -635,13 +635,21 @@ QString QgsStringUtils::wordWrap( const QString &string, const int length, const
} }
if ( strHit > -1 ) if ( strHit > -1 )
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
newstr.append( lines.at( i ).midRef( strCurrent, strHit - strCurrent ) ); newstr.append( lines.at( i ).midRef( strCurrent, strHit - strCurrent ) );
#else
newstr.append( QStringView {lines.at( i )}.mid( strCurrent, strHit - strCurrent ) );
#endif
newstr.append( '\n' ); newstr.append( '\n' );
strCurrent = strHit + delimiterLength; strCurrent = strHit + delimiterLength;
} }
else else
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
newstr.append( lines.at( i ).midRef( strCurrent ) ); newstr.append( lines.at( i ).midRef( strCurrent ) );
#else
newstr.append( QStringView {lines.at( i )}.mid( strCurrent ) );
#endif
strCurrent = strLength; strCurrent = strLength;
} }
} }

View File

@ -4739,7 +4739,7 @@ QString QgsPostgresProvider::getNextString( const QString &txt, int &i, const QS
} }
i += stringRe.cap( 1 ).length() + 2; i += stringRe.cap( 1 ).length() + 2;
jumpSpace( txt, i ); 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" ) ); QgsMessageLog::logMessage( tr( "Cannot find separator: %1" ).arg( txt.mid( i ) ), tr( "PostGIS" ) );
return QString(); return QString();
@ -4752,14 +4752,14 @@ QString QgsPostgresProvider::getNextString( const QString &txt, int &i, const QS
int start = i; int start = i;
for ( ; i < txt.length(); 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(); 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();
} }
} }

View File

@ -570,7 +570,11 @@ namespace QgsWms
const QRegExp composerParamRegExp( QStringLiteral( "^MAP\\d+:" ), Qt::CaseInsensitive ); const QRegExp composerParamRegExp( QStringLiteral( "^MAP\\d+:" ), Qt::CaseInsensitive );
if ( key.contains( composerParamRegExp ) ) if ( key.contains( composerParamRegExp ) )
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
const int mapId = key.midRef( 3, key.indexOf( ':' ) - 3 ).toInt(); 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 QString theKey = key.mid( key.indexOf( ':' ) + 1 );
const QgsWmsParameter::Name name = QgsWmsParameter::name( theKey ); const QgsWmsParameter::Name name = QgsWmsParameter::name( theKey );

View File

@ -562,8 +562,11 @@ int main( int argc, char *argv[] )
ok = false; ok = false;
break; break;
} }
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
coords[i] = myInitialExtent.midRef( posOld, pos - posOld ).toDouble( &ok ); coords[i] = myInitialExtent.midRef( posOld, pos - posOld ).toDouble( &ok );
#else
coords[i] = QStringView {myInitialExtent}.mid( posOld, pos - posOld ).toDouble( &ok );
#endif
if ( !ok ) if ( !ok )
break; break;
@ -571,8 +574,13 @@ int main( int argc, char *argv[] )
} }
// parse last coordinate // parse last coordinate
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
if ( ok ) if ( ok )
coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok ); coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok );
#else
if ( ok )
coords[3] = QStringView {myInitialExtent}.mid( posOld ).toDouble( &ok );
#endif
if ( !ok ) if ( !ok )
{ {