Skip to content

Commit ec2d7fe

Browse files
committedOct 14, 2016
[FEATURE] control over drawing of composer table grid horizontal & vertical lines
1 parent ea2fbd1 commit ec2d7fe

File tree

9 files changed

+292
-27
lines changed

9 files changed

+292
-27
lines changed
 

‎python/core/composer/qgscomposertablev2.sip

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,46 @@ class QgsComposerTableV2: QgsComposerMultiFrame
310310
*/
311311
QColor gridColor() const;
312312

313+
/** Sets whether the grid's horizontal lines should be drawn in the table
314+
* @param horizontalGird set to true to draw grid's horizontal lines
315+
* @see setShowGrid
316+
* @see setGridStrokeWidth
317+
* @see setGridColor
318+
* @see setVerticalGrid
319+
* @note added in QGIS 3.0
320+
*/
321+
void setHorizontalGrid( const bool horizontalGrid );
322+
323+
/** Returns whether the grid's horizontal lines are drawn in the table
324+
* @returns true if grid's horizontal lines are drawn
325+
* @see setShowGrid
326+
* @see setGridStrokeWidth
327+
* @see setGridColor
328+
* @see setVerticalGrid
329+
* @note added in QGIS 3.0
330+
*/
331+
bool horizontalGrid() const;
332+
333+
/** Sets whether the grid's vertical lines should be drawn in the table
334+
* @param verticalGird set to true to draw grid's vertical lines
335+
* @see setShowGrid
336+
* @see setGridStrokeWidth
337+
* @see setGridColor
338+
* @see setHorizontalGrid
339+
* @note added in QGIS 3.0
340+
*/
341+
void setVerticalGrid( const bool verticalGrid );
342+
343+
/** Returns whether the grid's vertical lines are drawn in the table
344+
* @returns true if grid's vertical lines are drawn
345+
* @see setShowGrid
346+
* @see setGridStrokeWidth
347+
* @see setGridColor
348+
* @see setHorizontalGrid
349+
* @note added in QGIS 3.0
350+
*/
351+
bool verticalGrid() const;
352+
313353
/** Sets color used for background of table.
314354
* @param color table background color
315355
* @see backgroundColor

‎src/app/composer/qgscomposerattributetablewidget.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,44 @@ void QgsComposerAttributeTableWidget::on_mGridColorButton_colorChanged( const QC
357357
}
358358
}
359359

360+
void QgsComposerAttributeTableWidget::on_mDrawHorizontalGrid_toggled( bool state )
361+
{
362+
if ( !mComposerTable )
363+
{
364+
return;
365+
}
366+
367+
QgsComposition* composition = mComposerTable->composition();
368+
if ( composition )
369+
{
370+
composition->beginMultiFrameCommand( mComposerTable, tr( "Table horizontal grid toggled" ) );
371+
}
372+
mComposerTable->setHorizontalGrid( state );
373+
if ( composition )
374+
{
375+
composition->endMultiFrameCommand();
376+
}
377+
}
378+
379+
void QgsComposerAttributeTableWidget::on_mDrawVerticalGrid_toggled( bool state )
380+
{
381+
if ( !mComposerTable )
382+
{
383+
return;
384+
}
385+
386+
QgsComposition* composition = mComposerTable->composition();
387+
if ( composition )
388+
{
389+
composition->beginMultiFrameCommand( mComposerTable, tr( "Table vertical grid toggled" ) );
390+
}
391+
mComposerTable->setVerticalGrid( state );
392+
if ( composition )
393+
{
394+
composition->endMultiFrameCommand();
395+
}
396+
}
397+
360398
void QgsComposerAttributeTableWidget::on_mShowGridGroupCheckBox_toggled( bool state )
361399
{
362400
if ( !mComposerTable )
@@ -428,6 +466,8 @@ void QgsComposerAttributeTableWidget::updateGuiElements()
428466
mMarginSpinBox->setValue( mComposerTable->cellMargin() );
429467
mGridStrokeWidthSpinBox->setValue( mComposerTable->gridStrokeWidth() );
430468
mGridColorButton->setColor( mComposerTable->gridColor() );
469+
mDrawHorizontalGrid->setChecked( mComposerTable->horizontalGrid() );
470+
mDrawVerticalGrid->setChecked( mComposerTable->verticalGrid() );
431471
if ( mComposerTable->showGrid() )
432472
{
433473
mShowGridGroupCheckBox->setChecked( true );
@@ -568,6 +608,8 @@ void QgsComposerAttributeTableWidget::blockAllSignals( bool b )
568608
mGridColorButton->blockSignals( b );
569609
mGridStrokeWidthSpinBox->blockSignals( b );
570610
mBackgroundColorButton->blockSignals( b );
611+
mDrawHorizontalGrid->blockSignals( b );
612+
mDrawVerticalGrid->blockSignals( b );
571613
mShowGridGroupCheckBox->blockSignals( b );
572614
mShowOnlyVisibleFeaturesCheckBox->blockSignals( b );
573615
mUniqueOnlyCheckBox->blockSignals( b );

‎src/app/composer/qgscomposerattributetablewidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
5555
void on_mHeaderFontColorButton_colorChanged( const QColor& newColor );
5656
void on_mContentFontPushButton_clicked();
5757
void on_mContentFontColorButton_colorChanged( const QColor& newColor );
58+
void on_mDrawHorizontalGrid_toggled( bool state );
59+
void on_mDrawVerticalGrid_toggled( bool state );
5860
void on_mShowGridGroupCheckBox_toggled( bool state );
5961
void on_mShowOnlyVisibleFeaturesCheckBox_stateChanged( int state );
6062
void on_mFeatureFilterCheckBox_stateChanged( int state );

‎src/core/composer/qgscomposertablev2.cpp

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ QgsComposerTableV2::QgsComposerTableV2( QgsComposition *composition, bool create
5858
, mShowGrid( true )
5959
, mGridStrokeWidth( 0.5 )
6060
, mGridColor( Qt::black )
61+
, mHorizontalGrid( true )
62+
, mVerticalGrid( true )
6163
, mBackgroundColor( Qt::white )
6264
, mWrapBehaviour( TruncateText )
6365
{
@@ -120,6 +122,8 @@ bool QgsComposerTableV2::writeXml( QDomElement& elem, QDomDocument & doc, bool i
120122
elem.setAttribute( "contentFontColor", QgsSymbolLayerUtils::encodeColor( mContentFontColor ) );
121123
elem.setAttribute( "gridStrokeWidth", QString::number( mGridStrokeWidth ) );
122124
elem.setAttribute( "gridColor", QgsSymbolLayerUtils::encodeColor( mGridColor ) );
125+
elem.setAttribute( "horizontalGrid", mHorizontalGrid );
126+
elem.setAttribute( "verticalGrid", mVerticalGrid );
123127
elem.setAttribute( "showGrid", mShowGrid );
124128
elem.setAttribute( "backgroundColor", QgsSymbolLayerUtils::encodeColor( mBackgroundColor ) );
125129
elem.setAttribute( "wrapBehaviour", QString::number( static_cast< int >( mWrapBehaviour ) ) );
@@ -187,6 +191,8 @@ bool QgsComposerTableV2::readXml( const QDomElement &itemElem, const QDomDocumen
187191
mContentFontColor = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( "contentFontColor", "0,0,0,255" ) );
188192
mCellMargin = itemElem.attribute( "cellMargin", "1.0" ).toDouble();
189193
mGridStrokeWidth = itemElem.attribute( "gridStrokeWidth", "0.5" ).toDouble();
194+
mHorizontalGrid = itemElem.attribute( "horizontalGrid", "1" ).toInt();
195+
mVerticalGrid = itemElem.attribute( "verticalGrid", "1" ).toInt();
190196
mShowGrid = itemElem.attribute( "showGrid", "1" ).toInt();
191197
mGridColor = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( "gridColor", "0,0,0,255" ) );
192198
mBackgroundColor = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( "backgroundColor", "255,255,255,0" ) );
@@ -243,18 +249,18 @@ int QgsComposerTableV2::rowsVisible( double frameHeight, int firstRow, bool incl
243249
if ( includeHeader )
244250
{
245251
//frame has a header
246-
headerHeight = 2 * ( mShowGrid ? mGridStrokeWidth : 0 ) + 2 * mCellMargin + QgsComposerUtils::fontAscentMM( mHeaderFont );
252+
headerHeight = 2 * ( mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 ) + 2 * mCellMargin + QgsComposerUtils::fontAscentMM( mHeaderFont );
247253
}
248254
else
249255
{
250256
//frame has no header text, just the stroke
251-
headerHeight = ( mShowGrid ? mGridStrokeWidth : 0 );
257+
headerHeight = ( mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 );
252258
}
253259

254260
//remaining height available for content rows
255261
double contentHeight = frameHeight - headerHeight;
256262

257-
double gridHeight = ( mShowGrid ? mGridStrokeWidth : 0 );
263+
double gridHeight = ( mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 );
258264

259265
int currentRow = firstRow;
260266
while ( contentHeight > 0 && currentRow <= mTableContents.count() )
@@ -266,7 +272,7 @@ int QgsComposerTableV2::rowsVisible( double frameHeight, int firstRow, bool incl
266272

267273
if ( includeEmptyRows && contentHeight > 0 )
268274
{
269-
double rowHeight = ( mShowGrid ? mGridStrokeWidth : 0 ) + 2 * mCellMargin + QgsComposerUtils::fontAscentMM( mContentFont );
275+
double rowHeight = ( mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 ) + 2 * mCellMargin + QgsComposerUtils::fontAscentMM( mContentFont );
270276
currentRow += qMax( floor( contentHeight / rowHeight ), 0.0 );
271277
}
272278

@@ -341,7 +347,8 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
341347
//calculate which rows to show in this frame
342348
QPair< int, int > rowsToShow = rowRange( frameIndex );
343349

344-
double gridSize = mShowGrid ? mGridStrokeWidth : 0;
350+
double gridSizeX = mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0;
351+
double gridSizeY = mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0;
345352
double cellHeaderHeight = QgsComposerUtils::fontAscentMM( mHeaderFont ) + 2 * mCellMargin;
346353
double cellBodyHeight = QgsComposerUtils::fontAscentMM( mContentFont ) + 2 * mCellMargin;
347354
QRectF cell;
@@ -375,8 +382,8 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
375382
//draw the text
376383
p->setPen( Qt::SolidLine );
377384

378-
double currentX = gridSize;
379-
double currentY = gridSize;
385+
double currentX = gridSizeX;
386+
double currentY = gridSizeY;
380387
if ( drawHeader )
381388
{
382389
//draw the headers
@@ -425,12 +432,12 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
425432

426433
currentX += mMaxColumnWidthMap[ col ];
427434
currentX += mCellMargin;
428-
currentX += gridSize;
435+
currentX += gridSizeX;
429436
col++;
430437
}
431438

432439
currentY += cellHeaderHeight;
433-
currentY += gridSize;
440+
currentY += gridSizeY;
434441
}
435442

436443
//now draw the body cells
@@ -441,7 +448,7 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
441448
for ( int row = rowsToShow.first; row < rowsToShow.second; ++row )
442449
{
443450
rowsDrawn++;
444-
currentX = gridSize;
451+
currentX = gridSizeX;
445452
int col = 0;
446453

447454
//calculate row height
@@ -481,11 +488,11 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
481488

482489
currentX += mMaxColumnWidthMap[ col ];
483490
currentX += mCellMargin;
484-
currentX += gridSize;
491+
currentX += gridSizeX;
485492
col++;
486493
}
487494
currentY += rowHeight;
488-
currentY += gridSize;
495+
currentY += gridSizeY;
489496
}
490497
}
491498

@@ -497,13 +504,13 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
497504
//draw background of empty rows
498505
for ( int row = rowsDrawn; row < numberRowsToDraw; ++row )
499506
{
500-
currentX = gridSize;
507+
currentX = gridSizeX;
501508
int col = 0;
502509

503510
if ( mergeCells )
504511
{
505512
p->setBrush( backgroundColor( row + 10000, 0 ) );
506-
p->drawRect( QRectF( gridSize, currentY, mTableSize.width() - 2 * gridSize, cellBodyHeight ) );
513+
p->drawRect( QRectF( gridSizeX, currentY, mTableSize.width() - 2 * gridSizeX, cellBodyHeight ) );
507514
}
508515
else
509516
{
@@ -517,11 +524,11 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
517524

518525
// currentY = gridSize;
519526
currentX += mMaxColumnWidthMap[ col ] + 2 * mCellMargin;
520-
currentX += gridSize;
527+
currentX += gridSizeX;
521528
col++;
522529
}
523530
}
524-
currentY += cellBodyHeight + gridSize;
531+
currentY += cellBodyHeight + gridSizeY;
525532
}
526533
p->restore();
527534
}
@@ -534,15 +541,21 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
534541
gridPen.setColor( mGridColor );
535542
gridPen.setJoinStyle( Qt::MiterJoin );
536543
p->setPen( gridPen );
537-
drawHorizontalGridLines( p, rowsToShow.first, rowsToShow.second + numberEmptyRows, drawHeader );
538-
drawVerticalGridLines( p, mMaxColumnWidthMap, rowsToShow.first, rowsToShow.second + numberEmptyRows, drawHeader, mergeCells );
544+
if ( mHorizontalGrid )
545+
{
546+
drawHorizontalGridLines( p, rowsToShow.first, rowsToShow.second + numberEmptyRows, drawHeader );
547+
}
548+
if ( mVerticalGrid )
549+
{
550+
drawVerticalGridLines( p, mMaxColumnWidthMap, rowsToShow.first, rowsToShow.second + numberEmptyRows, drawHeader, mergeCells );
551+
}
539552
}
540553

541554
//special case - no records and table is set to ShowMessage mode
542555
if ( emptyTable && mEmptyTableMode == QgsComposerTableV2::ShowMessage )
543556
{
544-
double messageX = gridSize + mCellMargin;
545-
double messageY = gridSize + ( drawHeader ? cellHeaderHeight + gridSize : 0 );
557+
double messageX = gridSizeX + mCellMargin;
558+
double messageY = gridSizeY + ( drawHeader ? cellHeaderHeight + gridSizeY : 0 );
546559
cell = QRectF( messageX, messageY, mTableSize.width() - messageX, cellBodyHeight );
547560
QgsComposerUtils::drawText( p, cell, mEmptyTableMessage, mContentFont, mContentFontColor, Qt::AlignHCenter, Qt::AlignVCenter, static_cast< Qt::TextFlag >( 0 ) );
548561
}
@@ -729,6 +742,34 @@ void QgsComposerTableV2::setGridColor( const QColor &color )
729742
emit changed();
730743
}
731744

745+
void QgsComposerTableV2::setHorizontalGrid( const bool horizontalGrid )
746+
{
747+
if ( horizontalGrid == mHorizontalGrid )
748+
{
749+
return;
750+
}
751+
752+
mHorizontalGrid = horizontalGrid;
753+
//since grid spacing has changed, we need to recalculate the table size
754+
recalculateTableSize();
755+
756+
emit changed();
757+
}
758+
759+
void QgsComposerTableV2::setVerticalGrid( const bool verticalGrid )
760+
{
761+
if ( verticalGrid == mVerticalGrid )
762+
{
763+
return;
764+
}
765+
766+
mVerticalGrid = verticalGrid;
767+
//since grid spacing has changed, we need to recalculate the table size
768+
recalculateTableSize();
769+
770+
emit changed();
771+
}
772+
732773
void QgsComposerTableV2::setBackgroundColor( const QColor &color )
733774
{
734775
if ( color == mBackgroundColor )
@@ -1002,7 +1043,7 @@ double QgsComposerTableV2::totalWidth()
10021043
totalWidth += maxColWidthIt.value();
10031044
}
10041045
totalWidth += ( 2 * mMaxColumnWidthMap.size() * mCellMargin );
1005-
totalWidth += ( mMaxColumnWidthMap.size() + 1 ) * ( mShowGrid ? mGridStrokeWidth : 0 );
1046+
totalWidth += ( mMaxColumnWidthMap.size() + 1 ) * ( mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0 );
10061047

10071048
return totalWidth;
10081049
}
@@ -1216,22 +1257,22 @@ void QgsComposerTableV2::drawVerticalGridLines( QPainter *painter, const QMap<in
12161257
double tableHeight = 0;
12171258
if ( hasHeader )
12181259
{
1219-
tableHeight += ( mShowGrid ? mGridStrokeWidth : 0 ) + mCellMargin * 2 + QgsComposerUtils::fontAscentMM( mHeaderFont );
1260+
tableHeight += ( mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 ) + mCellMargin * 2 + QgsComposerUtils::fontAscentMM( mHeaderFont );
12201261
}
1221-
tableHeight += ( mShowGrid ? mGridStrokeWidth : 0 );
1262+
tableHeight += ( mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 );
12221263
double headerHeight = tableHeight;
12231264

12241265
double cellBodyHeight = QgsComposerUtils::fontAscentMM( mContentFont );
12251266
for ( int row = firstRow; row < lastRow; ++row )
12261267
{
12271268
double rowHeight = row < mTableContents.count() ? mMaxRowHeightMap[row + 1] : cellBodyHeight;
1228-
tableHeight += rowHeight + ( mShowGrid ? mGridStrokeWidth : 0 ) + mCellMargin * 2;
1269+
tableHeight += rowHeight + ( mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 ) + mCellMargin * 2;
12291270
}
12301271

1231-
double halfGridStrokeWidth = ( mShowGrid ? mGridStrokeWidth : 0 ) / 2.0;
1272+
double halfGridStrokeWidth = ( mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0 ) / 2.0;
12321273
double currentX = halfGridStrokeWidth;
12331274
painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, tableHeight - halfGridStrokeWidth ) );
1234-
currentX += ( mShowGrid ? mGridStrokeWidth : 0 );
1275+
currentX += ( mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0 );
12351276
QMap<int, double>::const_iterator maxColWidthIt = maxWidthMap.constBegin();
12361277
int col = 1;
12371278
for ( ; maxColWidthIt != maxWidthMap.constEnd(); ++maxColWidthIt )
@@ -1246,7 +1287,7 @@ void QgsComposerTableV2::drawVerticalGridLines( QPainter *painter, const QMap<in
12461287
painter->drawLine( QPointF( currentX, halfGridStrokeWidth ), QPointF( currentX, headerHeight - halfGridStrokeWidth ) );
12471288
}
12481289

1249-
currentX += ( mShowGrid ? mGridStrokeWidth : 0 );
1290+
currentX += ( mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0 );
12501291
col++;
12511292
}
12521293
}

‎src/core/composer/qgscomposertablev2.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,46 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
338338
*/
339339
QColor gridColor() const { return mGridColor; }
340340

341+
/** Sets whether the grid's horizontal lines should be drawn in the table
342+
* @param horizontalGrid set to true to draw grid's horizontal lines
343+
* @see setShowGrid
344+
* @see setGridStrokeWidth
345+
* @see setGridColor
346+
* @see setVerticalGrid
347+
* @note added in QGIS 3.0
348+
*/
349+
void setHorizontalGrid( const bool horizontalGrid );
350+
351+
/** Returns whether the grid's horizontal lines are drawn in the table
352+
* @returns true if grid's horizontal lines are drawn
353+
* @see setShowGrid
354+
* @see setGridStrokeWidth
355+
* @see setGridColor
356+
* @see setVerticalGrid
357+
* @note added in QGIS 3.0
358+
*/
359+
bool horizontalGrid() const { return mHorizontalGrid; }
360+
361+
/** Sets whether the grid's vertical lines should be drawn in the table
362+
* @param verticalGrid set to true to draw grid's vertical lines
363+
* @see setShowGrid
364+
* @see setGridStrokeWidth
365+
* @see setGridColor
366+
* @see setHorizontalGrid
367+
* @note added in QGIS 3.0
368+
*/
369+
void setVerticalGrid( const bool verticalGrid );
370+
371+
/** Returns whether the grid's vertical lines are drawn in the table
372+
* @returns true if grid's vertical lines are drawn
373+
* @see setShowGrid
374+
* @see setGridStrokeWidth
375+
* @see setGridColor
376+
* @see setHorizontalGrid
377+
* @note added in QGIS 3.0
378+
*/
379+
bool verticalGrid() const { return mVerticalGrid; }
380+
341381
/** Sets color used for background of table.
342382
* @param color table background color
343383
* @see backgroundColor
@@ -477,6 +517,12 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
477517
/** Color for grid lines*/
478518
QColor mGridColor;
479519

520+
/** True if grid should be shown*/
521+
bool mHorizontalGrid;
522+
523+
/** True if grid should be shown*/
524+
bool mVerticalGrid;
525+
480526
/** Color for table background*/
481527
QColor mBackgroundColor;
482528

‎src/ui/composer/qgscomposerattributetablewidgetbase.ui

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,20 @@
504504
</item>
505505
</layout>
506506
</item>
507+
<item row="2" column="0" colspan="2">
508+
<widget class="QCheckBox" name="mDrawHorizontalGrid">
509+
<property name="text">
510+
<string>Draw horizontal lines</string>
511+
</property>
512+
</widget>
513+
</item>
514+
<item row="3" column="0" colspan="2">
515+
<widget class="QCheckBox" name="mDrawVerticalGrid">
516+
<property name="text">
517+
<string>Draw vertical lines</string>
518+
</property>
519+
</widget>
520+
</item>
507521
</layout>
508522
</widget>
509523
</item>

‎tests/src/core/testqgscomposertablev2.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class TestQgsComposerTableV2 : public QObject
7070
void contentsContainsRow(); //test the contentsContainsRow function
7171
void removeDuplicates(); //test removing duplicate rows
7272
void multiLineText(); //test rendering a table with multiline text
73+
void horizontalGrid(); //test rendering a table with horizontal-only grid
74+
void verticalGrid(); //test rendering a table with vertical-only grid
7375
void align(); //test alignment of table cells
7476
void wrapChar(); //test setting wrap character
7577
void autoWrap(); //test auto word wrap
@@ -675,6 +677,84 @@ void TestQgsComposerTableV2::multiLineText()
675677
delete multiLineLayer;
676678
}
677679

680+
void TestQgsComposerTableV2::horizontalGrid()
681+
{
682+
QgsVectorLayer* multiLineLayer = new QgsVectorLayer( "Point?field=col1:string&field=col2:string&field=col3:string", "multiline", "memory" );
683+
QVERIFY( multiLineLayer->isValid() );
684+
QgsFeature f1( multiLineLayer->dataProvider()->fields(), 1 );
685+
f1.setAttribute( "col1", "multiline\nstring" );
686+
f1.setAttribute( "col2", "singleline string" );
687+
f1.setAttribute( "col3", "singleline" );
688+
QgsFeature f2( multiLineLayer->dataProvider()->fields(), 2 );
689+
f2.setAttribute( "col1", "singleline string" );
690+
f2.setAttribute( "col2", "multiline\nstring" );
691+
f2.setAttribute( "col3", "singleline" );
692+
QgsFeature f3( multiLineLayer->dataProvider()->fields(), 3 );
693+
f3.setAttribute( "col1", "singleline" );
694+
f3.setAttribute( "col2", "singleline" );
695+
f3.setAttribute( "col3", "multiline\nstring" );
696+
QgsFeature f4( multiLineLayer->dataProvider()->fields(), 4 );
697+
f4.setAttribute( "col1", "long triple\nline\nstring" );
698+
f4.setAttribute( "col2", "double\nlinestring" );
699+
f4.setAttribute( "col3", "singleline" );
700+
multiLineLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 << f2 << f3 << f4 );
701+
702+
mFrame1->setFrameEnabled( false );
703+
mFrame2->setFrameEnabled( false );
704+
mFrame2->setSceneRect( QRectF( 5, 40, 100, 90 ) );
705+
706+
mComposerAttributeTable->setMaximumNumberOfFeatures( 20 );
707+
mComposerAttributeTable->setShowGrid( true );
708+
mComposerAttributeTable->setHorizontalGrid( true );
709+
mComposerAttributeTable->setVerticalGrid( false );
710+
mComposerAttributeTable->setVectorLayer( multiLineLayer );
711+
QgsCompositionChecker checker( "composerattributetable_horizontalgrid", mComposition );
712+
checker.setControlPathPrefix( "composer_table" );
713+
bool result = checker.testComposition( mReport );
714+
QVERIFY( result );
715+
716+
delete multiLineLayer;
717+
}
718+
719+
void TestQgsComposerTableV2::verticalGrid()
720+
{
721+
QgsVectorLayer* multiLineLayer = new QgsVectorLayer( "Point?field=col1:string&field=col2:string&field=col3:string", "multiline", "memory" );
722+
QVERIFY( multiLineLayer->isValid() );
723+
QgsFeature f1( multiLineLayer->dataProvider()->fields(), 1 );
724+
f1.setAttribute( "col1", "multiline\nstring" );
725+
f1.setAttribute( "col2", "singleline string" );
726+
f1.setAttribute( "col3", "singleline" );
727+
QgsFeature f2( multiLineLayer->dataProvider()->fields(), 2 );
728+
f2.setAttribute( "col1", "singleline string" );
729+
f2.setAttribute( "col2", "multiline\nstring" );
730+
f2.setAttribute( "col3", "singleline" );
731+
QgsFeature f3( multiLineLayer->dataProvider()->fields(), 3 );
732+
f3.setAttribute( "col1", "singleline" );
733+
f3.setAttribute( "col2", "singleline" );
734+
f3.setAttribute( "col3", "multiline\nstring" );
735+
QgsFeature f4( multiLineLayer->dataProvider()->fields(), 4 );
736+
f4.setAttribute( "col1", "long triple\nline\nstring" );
737+
f4.setAttribute( "col2", "double\nlinestring" );
738+
f4.setAttribute( "col3", "singleline" );
739+
multiLineLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 << f2 << f3 << f4 );
740+
741+
mFrame1->setFrameEnabled( false );
742+
mFrame2->setFrameEnabled( false );
743+
mFrame2->setSceneRect( QRectF( 5, 40, 100, 90 ) );
744+
745+
mComposerAttributeTable->setMaximumNumberOfFeatures( 20 );
746+
mComposerAttributeTable->setShowGrid( true );
747+
mComposerAttributeTable->setHorizontalGrid( false );
748+
mComposerAttributeTable->setVerticalGrid( true );
749+
mComposerAttributeTable->setVectorLayer( multiLineLayer );
750+
QgsCompositionChecker checker( "composerattributetable_verticalgrid", mComposition );
751+
checker.setControlPathPrefix( "composer_table" );
752+
bool result = checker.testComposition( mReport );
753+
QVERIFY( result );
754+
755+
delete multiLineLayer;
756+
}
757+
678758
void TestQgsComposerTableV2::align()
679759
{
680760
QgsVectorLayer* multiLineLayer = new QgsVectorLayer( "Point?field=col1:string&field=col2:string&field=col3:string", "multiline", "memory" );

0 commit comments

Comments
 (0)
Please sign in to comment.