Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't add extra linebreak in print composer tables
Check if remaining text is short enough to go in one line. Fixes #20546
  • Loading branch information
mhugent authored and nyalldawson committed Feb 7, 2019
1 parent 32b6599 commit a774499
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/layout/qgslayouttable.cpp
Expand Up @@ -1157,6 +1157,12 @@ QString QgsLayoutTable::wrappedText( const QString &value, double columnWidth, c
int lastPos = remainingText.lastIndexOf( ' ' );
while ( lastPos > -1 )
{
//check if remaining text is short enough to go in one line
if ( !textRequiresWrapping( remainingText, columnWidth, font ) )
{
break;
}

if ( !textRequiresWrapping( remainingText.left( lastPos ), columnWidth, font ) )
{
outLines << remainingText.left( lastPos );
Expand Down
15 changes: 15 additions & 0 deletions tests/src/core/testqgslayouttable.cpp
Expand Up @@ -71,6 +71,7 @@ class TestQgsLayoutTable : public QObject
void cellStyles(); //test cell styles
void cellStylesRender(); //test rendering cell styles
void dataDefinedSource();
void wrappedText();

private:
QgsVectorLayer *mVectorLayer = nullptr;
Expand Down Expand Up @@ -1412,5 +1413,19 @@ void TestQgsLayoutTable::dataDefinedSource()
QCOMPARE( table->contents().at( 0 ), QVector< QVariant >() << 1 << 2 << 3 );
}

void TestQgsLayoutTable::wrappedText()
{
QgsProject p;
QgsLayout l( &p );
QgsLayoutItemAttributeTable *t = new QgsLayoutItemAttributeTable( &l );
t->setWrapBehavior( QgsLayoutTable::WrapText );

QFont f;
QString sourceText( "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua" );
QString wrapText = t->wrappedText( sourceText, 100 /*columnWidth*/, f );
//there should be no line break before the last word (bug #20546)
QVERIFY( !wrapText.endsWith( "\naliqua" ) );
}

QGSTEST_MAIN( TestQgsLayoutTable )
#include "testqgslayouttable.moc"

0 comments on commit a774499

Please sign in to comment.