Skip to content
Permalink
Browse files

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 a774499b95177d7645bc84e4c5243fa7f2f0e530
Showing with 21 additions and 0 deletions.
  1. +6 −0 src/core/layout/qgslayouttable.cpp
  2. +15 −0 tests/src/core/testqgslayouttable.cpp
@@ -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 );
@@ -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;
@@ -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.
You can’t perform that action at this time.