Skip to content

Commit ce2bce5

Browse files
m-kuhnnyalldawson
authored andcommittedMar 26, 2021
Switch QString ref functions to QStringView
1 parent 08c1275 commit ce2bce5

File tree

10 files changed

+64
-8
lines changed

10 files changed

+64
-8
lines changed
 

‎src/app/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,11 @@ int main( int argc, char *argv[] )
14341434
break;
14351435
}
14361436

1437+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
14371438
coords[i] = myInitialExtent.midRef( posOld, pos - posOld ).toDouble( &ok );
1439+
#else
1440+
coords[i] = QStringView {myInitialExtent}.mid( posOld, pos - posOld ).toDouble( &ok );
1441+
#endif
14381442
if ( !ok )
14391443
break;
14401444

@@ -1443,7 +1447,13 @@ int main( int argc, char *argv[] )
14431447

14441448
// parse last coordinate
14451449
if ( ok )
1450+
{
1451+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
14461452
coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok );
1453+
#else
1454+
coords[3] = QStringView {myInitialExtent}.mid( posOld ).toDouble( &ok );
1455+
#endif
1456+
}
14471457

14481458
if ( !ok )
14491459
{

‎src/core/expression/qgsexpression.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,11 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
452452
if ( exp.hasParserError() )
453453
{
454454
QgsDebugMsg( "Expression parser error: " + exp.parserErrorString() );
455+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
455456
expr_action += action.midRef( start, index - start );
457+
#else
458+
expr_action += QStringView {action}.mid( start, index - start );
459+
#endif
456460
continue;
457461
}
458462

@@ -467,15 +471,23 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
467471
if ( exp.hasEvalError() )
468472
{
469473
QgsDebugMsg( "Expression parser eval error: " + exp.evalErrorString() );
474+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
470475
expr_action += action.midRef( start, index - start );
476+
#else
477+
expr_action += QStringView {action}.mid( start, index - start );
478+
#endif
471479
continue;
472480
}
473481

474482
QgsDebugMsgLevel( "Expression result is: " + result.toString(), 3 );
475483
expr_action += action.mid( start, pos - start ) + result.toString();
476484
}
477485

486+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
478487
expr_action += action.midRef( index );
488+
#else
489+
expr_action += QStringView {action}.mid( index ).toString();
490+
#endif
479491

480492
return expr_action;
481493
}

‎src/core/qgscolorramp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ QgsColorRamp *QgsGradientColorRamp::create( const QVariantMap &props )
7575
continue;
7676

7777
QColor c = QgsSymbolLayerUtils::decodeColor( stop.mid( i + 1 ) );
78+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
7879
stops.append( QgsGradientStop( stop.leftRef( i ).toDouble(), c ) );
80+
#else
81+
stops.append( QgsGradientStop( QStringView {stop}.left( i ).toDouble(), c ) );
82+
#endif
7983
}
8084
}
8185

‎src/core/qgshstoreutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ QVariantMap QgsHstoreUtils::parse( const QString &string )
4242
while ( i < string.length() && string.at( i ).isSpace() )
4343
++i;
4444

45-
if ( string.midRef( i ).startsWith( sep ) )
45+
if ( QStringView{string}.mid( i ).startsWith( sep ) )
4646
{
4747
i += sep.length();
4848
}

‎src/core/qgsogcutils.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,8 +2680,13 @@ QDomElement QgsOgcUtilsSQLStatementToFilter::toOgcFilter( const QgsSQLStatement:
26802680
static QString mapBinarySpatialToOgc( const QString &name )
26812681
{
26822682
QString nameCompare( name );
2683+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
26832684
if ( name.size() > 3 && name.midRef( 0, 3 ).compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 )
26842685
nameCompare = name.mid( 3 );
2686+
#else
2687+
if ( name.size() > 3 && QStringView {name}.mid( 0, 3 ).toString().compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 )
2688+
nameCompare = name.mid( 3 );
2689+
#endif
26852690
QStringList spatialOps;
26862691
spatialOps << QStringLiteral( "BBOX" ) << QStringLiteral( "Intersects" ) << QStringLiteral( "Contains" ) << QStringLiteral( "Crosses" ) << QStringLiteral( "Equals" )
26872692
<< QStringLiteral( "Disjoint" ) << QStringLiteral( "Overlaps" ) << QStringLiteral( "Touches" ) << QStringLiteral( "Within" );
@@ -2697,8 +2702,13 @@ static QString mapBinarySpatialToOgc( const QString &name )
26972702
static QString mapTernarySpatialToOgc( const QString &name )
26982703
{
26992704
QString nameCompare( name );
2705+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
27002706
if ( name.size() > 3 && name.midRef( 0, 3 ).compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 )
27012707
nameCompare = name.mid( 3 );
2708+
#else
2709+
if ( name.size() > 3 && QStringView {name}.mid( 0, 3 ).compare( QLatin1String( "ST_" ), Qt::CaseInsensitive ) == 0 )
2710+
nameCompare = name.mid( 3 );
2711+
#endif
27022712
if ( nameCompare.compare( QLatin1String( "DWithin" ), Qt::CaseInsensitive ) == 0 )
27032713
return QStringLiteral( "DWithin" );
27042714
if ( nameCompare.compare( QLatin1String( "Beyond" ), Qt::CaseInsensitive ) == 0 )

‎src/core/qgspostgresstringutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ QString QgsPostgresStringUtils::getNextString( const QString &txt, int &i, const
4040
}
4141
i += stringRe.cap( 1 ).length() + 2;
4242
jumpSpace( txt, i );
43-
if ( !txt.midRef( i ).startsWith( sep ) && i < txt.length() )
43+
if ( !QStringView{txt}.mid( i ).startsWith( sep ) && i < txt.length() )
4444
{
4545
QgsMessageLog::logMessage( QObject::tr( "Cannot find separator: %1" ).arg( txt.mid( i ) ), QObject::tr( "PostgresStringUtils" ) );
4646
return QString();

‎src/core/qgsstringutils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,21 @@ QString QgsStringUtils::wordWrap( const QString &string, const int length, const
635635
}
636636
if ( strHit > -1 )
637637
{
638+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
638639
newstr.append( lines.at( i ).midRef( strCurrent, strHit - strCurrent ) );
640+
#else
641+
newstr.append( QStringView {lines.at( i )}.mid( strCurrent, strHit - strCurrent ) );
642+
#endif
639643
newstr.append( '\n' );
640644
strCurrent = strHit + delimiterLength;
641645
}
642646
else
643647
{
648+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
644649
newstr.append( lines.at( i ).midRef( strCurrent ) );
650+
#else
651+
newstr.append( QStringView {lines.at( i )}.mid( strCurrent ) );
652+
#endif
645653
strCurrent = strLength;
646654
}
647655
}

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4739,7 +4739,7 @@ QString QgsPostgresProvider::getNextString( const QString &txt, int &i, const QS
47394739
}
47404740
i += stringRe.cap( 1 ).length() + 2;
47414741
jumpSpace( txt, i );
4742-
if ( !txt.midRef( i ).startsWith( sep ) && i < txt.length() )
4742+
if ( !QStringView{txt}.mid( i ).startsWith( sep ) && i < txt.length() )
47434743
{
47444744
QgsMessageLog::logMessage( tr( "Cannot find separator: %1" ).arg( txt.mid( i ) ), tr( "PostGIS" ) );
47454745
return QString();
@@ -4752,14 +4752,14 @@ QString QgsPostgresProvider::getNextString( const QString &txt, int &i, const QS
47524752
int start = i;
47534753
for ( ; i < txt.length(); i++ )
47544754
{
4755-
if ( txt.midRef( i ).startsWith( sep ) )
4755+
if ( QStringView{txt}.mid( i ).startsWith( sep ) )
47564756
{
4757-
QStringRef r( txt.midRef( start, i - start ) );
4757+
QStringView v( QStringView{txt}.mid( start, i - start ) );
47584758
i += sep.length();
4759-
return r.trimmed().toString();
4759+
return v.trimmed().toString();
47604760
}
47614761
}
4762-
return txt.midRef( start, i - start ).trimmed().toString();
4762+
return QStringView{txt}.mid( start, i - start ).trimmed().toString();
47634763
}
47644764
}
47654765

‎src/server/services/wms/qgswmsparameters.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,11 @@ namespace QgsWms
570570
const QRegExp composerParamRegExp( QStringLiteral( "^MAP\\d+:" ), Qt::CaseInsensitive );
571571
if ( key.contains( composerParamRegExp ) )
572572
{
573+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
573574
const int mapId = key.midRef( 3, key.indexOf( ':' ) - 3 ).toInt();
575+
#else
576+
const int mapId = QStringView {key}.mid( 3, key.indexOf( ':' ) - 3 ).toInt();
577+
#endif
574578
const QString theKey = key.mid( key.indexOf( ':' ) + 1 );
575579
const QgsWmsParameter::Name name = QgsWmsParameter::name( theKey );
576580

‎tests/bench/main.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,17 +562,25 @@ int main( int argc, char *argv[] )
562562
ok = false;
563563
break;
564564
}
565-
565+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
566566
coords[i] = myInitialExtent.midRef( posOld, pos - posOld ).toDouble( &ok );
567+
#else
568+
coords[i] = QStringView {myInitialExtent}.mid( posOld, pos - posOld ).toDouble( &ok );
569+
#endif
567570
if ( !ok )
568571
break;
569572

570573
posOld = pos + 1;
571574
}
572575

573576
// parse last coordinate
577+
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2)
574578
if ( ok )
575579
coords[3] = myInitialExtent.midRef( posOld ).toDouble( &ok );
580+
#else
581+
if ( ok )
582+
coords[3] = QStringView {myInitialExtent}.mid( posOld ).toDouble( &ok );
583+
#endif
576584

577585
if ( !ok )
578586
{

0 commit comments

Comments
 (0)
Please sign in to comment.