Skip to content

Commit

Permalink
Add unit tests for manual table row heights and column widths
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 14, 2020
1 parent 0aef9a1 commit faf4949
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/src/core/testqgslayoutmanualtable.cpp
Expand Up @@ -24,6 +24,8 @@
#include "qgsreadwritecontext.h"
#include "qgsprintlayout.h"
#include "qgscurrencynumericformat.h"
#include "qgsmultirenderchecker.h"
#include "qgsfontutils.h"

#include <QObject>
#include "qgstest.h"
Expand All @@ -44,6 +46,8 @@ class TestQgsLayoutManualTable : public QObject
void setContents();
void cellStyles();
void cellFormat();
void rowHeight();
void columnWidth();

private:
QString mReport;
Expand Down Expand Up @@ -229,6 +233,9 @@ void TestQgsLayoutManualTable::setContents()
QCOMPARE( table->tableContents().at( 1 ).at( 1 ).content().toString(), QStringLiteral( "B" ) );
QCOMPARE( table->tableContents().at( 1 ).at( 2 ).content().toString(), QStringLiteral( "C" ) );

table->setRowHeights( QList< double >() << 5.5 << 4.0 );
table->setColumnWidths( QList< double >() << 15.5 << 14.0 << 13.4 );

// save and restore

//write to XML
Expand All @@ -253,6 +260,9 @@ void TestQgsLayoutManualTable::setContents()
QCOMPARE( tableFromXml->tableContents().at( 1 ).at( 0 ).content().toString(), QStringLiteral( "A" ) );
QCOMPARE( tableFromXml->tableContents().at( 1 ).at( 1 ).content().toString(), QStringLiteral( "B" ) );
QCOMPARE( tableFromXml->tableContents().at( 1 ).at( 2 ).content().toString(), QStringLiteral( "C" ) );

QCOMPARE( tableFromXml->rowHeights(), QList< double >() << 5.5 << 4.0 );
QCOMPARE( tableFromXml->columnWidths(), QList< double >() << 15.5 << 14.0 << 13.4 );
}

void TestQgsLayoutManualTable::cellStyles()
Expand Down Expand Up @@ -314,5 +324,61 @@ void TestQgsLayoutManualTable::cellFormat()
compareTable( table, expectedRows );
}

void TestQgsLayoutManualTable::rowHeight()
{
QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
QgsLayoutItemManualTable *table = new QgsLayoutItemManualTable( &l );
QgsLayoutFrame *frame1 = new QgsLayoutFrame( &l, table );
frame1->attemptSetSceneRect( QRectF( 5, 5, 100, 60 ) );
frame1->setFrameEnabled( true );
table->addFrame( frame1 );
table->setBackgroundColor( Qt::yellow );

table->setContentFont( QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) ) );

frame1->setFrameEnabled( false );
table->setShowGrid( true );
table->setHorizontalGrid( true );
table->setVerticalGrid( true );

table->setTableContents( QgsTableContents() << ( QgsTableRow() << QgsTableCell( QStringLiteral( "Jet" ) ) << QgsTableCell( QStringLiteral( "Helicopter" ) ) << QgsTableCell( QStringLiteral( "Plane" ) ) )
<< ( QgsTableRow() << QgsTableCell( QStringLiteral( "A" ) ) << QgsTableCell( QStringLiteral( "B" ) ) << QgsTableCell( QStringLiteral( "C" ) ) ) );

table->setRowHeights( QList< double >() << 0 << 40.0 );
QgsLayoutChecker checker( QStringLiteral( "manualtable_rowheight" ), &l );
checker.setControlPathPrefix( QStringLiteral( "layout_manual_table" ) );
bool result = checker.testLayout( mReport );
QVERIFY( result );
}

void TestQgsLayoutManualTable::columnWidth()
{
QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
QgsLayoutItemManualTable *table = new QgsLayoutItemManualTable( &l );
QgsLayoutFrame *frame1 = new QgsLayoutFrame( &l, table );
frame1->attemptSetSceneRect( QRectF( 5, 5, 100, 60 ) );
frame1->setFrameEnabled( true );
table->addFrame( frame1 );
table->setBackgroundColor( Qt::yellow );

table->setContentFont( QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) ) );

frame1->setFrameEnabled( false );
table->setShowGrid( true );
table->setHorizontalGrid( true );
table->setVerticalGrid( true );

table->setTableContents( QgsTableContents() << ( QgsTableRow() << QgsTableCell( QStringLiteral( "Jet" ) ) << QgsTableCell( QStringLiteral( "Helicopter" ) ) << QgsTableCell( QStringLiteral( "Plane" ) ) )
<< ( QgsTableRow() << QgsTableCell( QStringLiteral( "A" ) ) << QgsTableCell( QStringLiteral( "B" ) ) << QgsTableCell( QStringLiteral( "C" ) ) ) );

table->setColumnWidths( QList< double >() << 0 << 10.0 << 30.0 );
QgsLayoutChecker checker( QStringLiteral( "manualtable_columnwidth" ), &l );
checker.setControlPathPrefix( QStringLiteral( "layout_manual_table" ) );
bool result = checker.testLayout( mReport );
QVERIFY( result );
}

QGSTEST_MAIN( TestQgsLayoutManualTable )
#include "testqgslayoutmanualtable.moc"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 faf4949

Please sign in to comment.