Skip to content

Commit

Permalink
Add test for table layout NULL->0
Browse files Browse the repository at this point in the history
See: #46331
  • Loading branch information
elpaso authored and nyalldawson committed Dec 3, 2021
1 parent 00d9304 commit dd0cd13
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/src/core/testqgslayouttable.cpp
Expand Up @@ -88,6 +88,7 @@ class TestQgsLayoutTable : public QObject
void testExpressionSort();
void testScopeForCell();
void testDataDefinedTextFormatForCell();
void testIntegerNullCell();

private:
QgsVectorLayer *mVectorLayer = nullptr;
Expand Down Expand Up @@ -1119,6 +1120,40 @@ void TestQgsLayoutTable::testDataDefinedTextFormatForCell()
QVERIFY( result );
}

void TestQgsLayoutTable::testIntegerNullCell()
{
QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
QgsLayoutItemAttributeTable *table = new QgsLayoutItemAttributeTable( &l );

l.addMultiFrame( table );
QgsLayoutFrame *frame = new QgsLayoutFrame( &l, table );
frame->attemptSetSceneRect( QRectF( 5, 5, 150, 30 ) );
frame->setFrameEnabled( true );
l.addLayoutItem( frame );
table->addFrame( frame );

std::unique_ptr<QgsVectorLayer> layer = std::make_unique< QgsVectorLayer> ( QStringLiteral( "Point?field=intf:integer" ), QStringLiteral( "point" ), QStringLiteral( "memory" ) );
QVERIFY( layer->isValid() );
QgsFeature f1( layer->dataProvider()->fields(), 1 );
f1.setAttribute( QStringLiteral( "intf" ), 1 );
QgsFeature f2( layer->dataProvider()->fields(), 2 );
f2.setAttribute( QStringLiteral( "intf" ), 2 );
QgsFeature f3( layer->dataProvider()->fields(), 3 );
f3.setAttribute( QStringLiteral( "intf" ), QVariant( QVariant::Int ) );
layer->dataProvider()->addFeatures( QgsFeatureList() << f1 << f2 << f3 );

table->setVectorLayer( layer.get() );
table->setContentTextFormat( QgsTextFormat::fromQFont( QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) ) ) );
table->setHeaderTextFormat( QgsTextFormat::fromQFont( QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) ) ) );

QgsLayoutChecker checker( QStringLiteral( "composerattributetable_integernullcell" ), &l );
checker.setControlPathPrefix( QStringLiteral( "composer_table" ) );
const bool result = checker.testLayout( mReport );
QVERIFY( result );

}

void TestQgsLayoutTable::align()
{
QgsLayout l( QgsProject::instance() );
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dd0cd13

Please sign in to comment.