Skip to content
Permalink
Browse files
Fix regression in word wrapping
The switch to QRegularExpression mean that word wrapping was ALWAYS
being applied, even when the string was short enough to not require it
  • Loading branch information
nyalldawson committed Oct 20, 2021
1 parent ffc4eac commit 320260a3d3953441c380e93c1070df7b50d61dda
Showing with 5 additions and 3 deletions.
  1. +3 −3 src/core/qgsstringutils.cpp
  2. +2 −0 tests/src/core/testqgsstringutils.cpp
@@ -633,17 +633,17 @@ QString QgsStringUtils::wordWrap( const QString &string, const int length, const
if ( useMaxLineLength )
{
//first try to locate delimiter backwards
strHit = lines.at( i ).lastIndexOf( rx, strCurrent + length );
strHit = ( strCurrent + length >= strLength ) ? -1 : lines.at( i ).lastIndexOf( rx, strCurrent + length );
if ( strHit == lastHit || strHit == -1 )
{
//if no new backward delimiter found, try to locate forward
strHit = lines.at( i ).indexOf( rx, strCurrent + std::abs( length ) );
strHit = ( strCurrent + std::abs( length ) >= strLength ) ? -1 : lines.at( i ).indexOf( rx, strCurrent + std::abs( length ) );
}
lastHit = strHit;
}
else
{
strHit = lines.at( i ).indexOf( rx, strCurrent + std::abs( length ) );
strHit = ( strCurrent + std::abs( length ) >= strLength ) ? -1 : lines.at( i ).indexOf( rx, strCurrent + std::abs( length ) );
}
if ( strHit > -1 )
{
@@ -239,6 +239,8 @@ void TestQgsStringUtils::wordWrap_data()
QTest::addColumn<QString>( "expected" );

QTest::newRow( "wordwrap" ) << "university of qgis" << 13 << true << QString() << "university of\nqgis";
QTest::newRow( "wordwrap not possible" ) << "universityofqgis" << 13 << true << QString() << "universityofqgis";
QTest::newRow( "wordwrap not required" ) << "uni of qgis" << 13 << true << QString() << "uni of qgis";
QTest::newRow( "optional parameters unspecified" ) << "test string" << 5 << true << QString() << "test\nstring";
QTest::newRow( "wordwrap with delim" ) << "university of qgis" << 13 << true << QStringLiteral( " " ) << "university of\nqgis";
QTest::newRow( "wordwrap min" ) << "university of qgis" << 3 << false << QStringLiteral( " " ) << "university\nof qgis";

0 comments on commit 320260a

Please sign in to comment.