@@ -58,6 +58,8 @@ QgsComposerTableV2::QgsComposerTableV2( QgsComposition *composition, bool create
58
58
, mShowGrid( true )
59
59
, mGridStrokeWidth( 0.5 )
60
60
, mGridColor( Qt::black )
61
+ , mHorizontalGrid( true )
62
+ , mVerticalGrid( true )
61
63
, mBackgroundColor( Qt::white )
62
64
, mWrapBehaviour( TruncateText )
63
65
{
@@ -120,6 +122,8 @@ bool QgsComposerTableV2::writeXml( QDomElement& elem, QDomDocument & doc, bool i
120
122
elem.setAttribute ( " contentFontColor" , QgsSymbolLayerUtils::encodeColor ( mContentFontColor ) );
121
123
elem.setAttribute ( " gridStrokeWidth" , QString::number ( mGridStrokeWidth ) );
122
124
elem.setAttribute ( " gridColor" , QgsSymbolLayerUtils::encodeColor ( mGridColor ) );
125
+ elem.setAttribute ( " horizontalGrid" , mHorizontalGrid );
126
+ elem.setAttribute ( " verticalGrid" , mVerticalGrid );
123
127
elem.setAttribute ( " showGrid" , mShowGrid );
124
128
elem.setAttribute ( " backgroundColor" , QgsSymbolLayerUtils::encodeColor ( mBackgroundColor ) );
125
129
elem.setAttribute ( " wrapBehaviour" , QString::number ( static_cast < int >( mWrapBehaviour ) ) );
@@ -187,6 +191,8 @@ bool QgsComposerTableV2::readXml( const QDomElement &itemElem, const QDomDocumen
187
191
mContentFontColor = QgsSymbolLayerUtils::decodeColor ( itemElem.attribute ( " contentFontColor" , " 0,0,0,255" ) );
188
192
mCellMargin = itemElem.attribute ( " cellMargin" , " 1.0" ).toDouble ();
189
193
mGridStrokeWidth = itemElem.attribute ( " gridStrokeWidth" , " 0.5" ).toDouble ();
194
+ mHorizontalGrid = itemElem.attribute ( " horizontalGrid" , " 1" ).toInt ();
195
+ mVerticalGrid = itemElem.attribute ( " verticalGrid" , " 1" ).toInt ();
190
196
mShowGrid = itemElem.attribute ( " showGrid" , " 1" ).toInt ();
191
197
mGridColor = QgsSymbolLayerUtils::decodeColor ( itemElem.attribute ( " gridColor" , " 0,0,0,255" ) );
192
198
mBackgroundColor = QgsSymbolLayerUtils::decodeColor ( itemElem.attribute ( " backgroundColor" , " 255,255,255,0" ) );
@@ -243,18 +249,18 @@ int QgsComposerTableV2::rowsVisible( double frameHeight, int firstRow, bool incl
243
249
if ( includeHeader )
244
250
{
245
251
// 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 );
247
253
}
248
254
else
249
255
{
250
256
// frame has no header text, just the stroke
251
- headerHeight = ( mShowGrid ? mGridStrokeWidth : 0 );
257
+ headerHeight = ( mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 );
252
258
}
253
259
254
260
// remaining height available for content rows
255
261
double contentHeight = frameHeight - headerHeight;
256
262
257
- double gridHeight = ( mShowGrid ? mGridStrokeWidth : 0 );
263
+ double gridHeight = ( mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 );
258
264
259
265
int currentRow = firstRow;
260
266
while ( contentHeight > 0 && currentRow <= mTableContents .count () )
@@ -266,7 +272,7 @@ int QgsComposerTableV2::rowsVisible( double frameHeight, int firstRow, bool incl
266
272
267
273
if ( includeEmptyRows && contentHeight > 0 )
268
274
{
269
- double rowHeight = ( mShowGrid ? mGridStrokeWidth : 0 ) + 2 * mCellMargin + QgsComposerUtils::fontAscentMM ( mContentFont );
275
+ double rowHeight = ( mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 ) + 2 * mCellMargin + QgsComposerUtils::fontAscentMM ( mContentFont );
270
276
currentRow += qMax ( floor ( contentHeight / rowHeight ), 0.0 );
271
277
}
272
278
@@ -341,7 +347,8 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
341
347
// calculate which rows to show in this frame
342
348
QPair< int , int > rowsToShow = rowRange ( frameIndex );
343
349
344
- double gridSize = mShowGrid ? mGridStrokeWidth : 0 ;
350
+ double gridSizeX = mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0 ;
351
+ double gridSizeY = mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 ;
345
352
double cellHeaderHeight = QgsComposerUtils::fontAscentMM ( mHeaderFont ) + 2 * mCellMargin ;
346
353
double cellBodyHeight = QgsComposerUtils::fontAscentMM ( mContentFont ) + 2 * mCellMargin ;
347
354
QRectF cell;
@@ -375,8 +382,8 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
375
382
// draw the text
376
383
p->setPen ( Qt::SolidLine );
377
384
378
- double currentX = gridSize ;
379
- double currentY = gridSize ;
385
+ double currentX = gridSizeX ;
386
+ double currentY = gridSizeY ;
380
387
if ( drawHeader )
381
388
{
382
389
// draw the headers
@@ -425,12 +432,12 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
425
432
426
433
currentX += mMaxColumnWidthMap [ col ];
427
434
currentX += mCellMargin ;
428
- currentX += gridSize ;
435
+ currentX += gridSizeX ;
429
436
col++;
430
437
}
431
438
432
439
currentY += cellHeaderHeight;
433
- currentY += gridSize ;
440
+ currentY += gridSizeY ;
434
441
}
435
442
436
443
// now draw the body cells
@@ -441,7 +448,7 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
441
448
for ( int row = rowsToShow.first ; row < rowsToShow.second ; ++row )
442
449
{
443
450
rowsDrawn++;
444
- currentX = gridSize ;
451
+ currentX = gridSizeX ;
445
452
int col = 0 ;
446
453
447
454
// calculate row height
@@ -481,11 +488,11 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
481
488
482
489
currentX += mMaxColumnWidthMap [ col ];
483
490
currentX += mCellMargin ;
484
- currentX += gridSize ;
491
+ currentX += gridSizeX ;
485
492
col++;
486
493
}
487
494
currentY += rowHeight;
488
- currentY += gridSize ;
495
+ currentY += gridSizeY ;
489
496
}
490
497
}
491
498
@@ -497,13 +504,13 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
497
504
// draw background of empty rows
498
505
for ( int row = rowsDrawn; row < numberRowsToDraw; ++row )
499
506
{
500
- currentX = gridSize ;
507
+ currentX = gridSizeX ;
501
508
int col = 0 ;
502
509
503
510
if ( mergeCells )
504
511
{
505
512
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 ) );
507
514
}
508
515
else
509
516
{
@@ -517,11 +524,11 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
517
524
518
525
// currentY = gridSize;
519
526
currentX += mMaxColumnWidthMap [ col ] + 2 * mCellMargin ;
520
- currentX += gridSize ;
527
+ currentX += gridSizeX ;
521
528
col++;
522
529
}
523
530
}
524
- currentY += cellBodyHeight + gridSize ;
531
+ currentY += cellBodyHeight + gridSizeY ;
525
532
}
526
533
p->restore ();
527
534
}
@@ -534,15 +541,21 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameInd
534
541
gridPen.setColor ( mGridColor );
535
542
gridPen.setJoinStyle ( Qt::MiterJoin );
536
543
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
+ }
539
552
}
540
553
541
554
// special case - no records and table is set to ShowMessage mode
542
555
if ( emptyTable && mEmptyTableMode == QgsComposerTableV2::ShowMessage )
543
556
{
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 );
546
559
cell = QRectF ( messageX, messageY, mTableSize .width () - messageX, cellBodyHeight );
547
560
QgsComposerUtils::drawText ( p, cell, mEmptyTableMessage , mContentFont , mContentFontColor , Qt::AlignHCenter, Qt::AlignVCenter, static_cast < Qt::TextFlag >( 0 ) );
548
561
}
@@ -729,6 +742,34 @@ void QgsComposerTableV2::setGridColor( const QColor &color )
729
742
emit changed ();
730
743
}
731
744
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
+
732
773
void QgsComposerTableV2::setBackgroundColor ( const QColor &color )
733
774
{
734
775
if ( color == mBackgroundColor )
@@ -1002,7 +1043,7 @@ double QgsComposerTableV2::totalWidth()
1002
1043
totalWidth += maxColWidthIt.value ();
1003
1044
}
1004
1045
totalWidth += ( 2 * mMaxColumnWidthMap .size () * mCellMargin );
1005
- totalWidth += ( mMaxColumnWidthMap .size () + 1 ) * ( mShowGrid ? mGridStrokeWidth : 0 );
1046
+ totalWidth += ( mMaxColumnWidthMap .size () + 1 ) * ( mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0 );
1006
1047
1007
1048
return totalWidth;
1008
1049
}
@@ -1216,22 +1257,22 @@ void QgsComposerTableV2::drawVerticalGridLines( QPainter *painter, const QMap<in
1216
1257
double tableHeight = 0 ;
1217
1258
if ( hasHeader )
1218
1259
{
1219
- tableHeight += ( mShowGrid ? mGridStrokeWidth : 0 ) + mCellMargin * 2 + QgsComposerUtils::fontAscentMM ( mHeaderFont );
1260
+ tableHeight += ( mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 ) + mCellMargin * 2 + QgsComposerUtils::fontAscentMM ( mHeaderFont );
1220
1261
}
1221
- tableHeight += ( mShowGrid ? mGridStrokeWidth : 0 );
1262
+ tableHeight += ( mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0 );
1222
1263
double headerHeight = tableHeight;
1223
1264
1224
1265
double cellBodyHeight = QgsComposerUtils::fontAscentMM ( mContentFont );
1225
1266
for ( int row = firstRow; row < lastRow; ++row )
1226
1267
{
1227
1268
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 ;
1229
1270
}
1230
1271
1231
- double halfGridStrokeWidth = ( mShowGrid ? mGridStrokeWidth : 0 ) / 2.0 ;
1272
+ double halfGridStrokeWidth = ( mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0 ) / 2.0 ;
1232
1273
double currentX = halfGridStrokeWidth;
1233
1274
painter->drawLine ( QPointF ( currentX, halfGridStrokeWidth ), QPointF ( currentX, tableHeight - halfGridStrokeWidth ) );
1234
- currentX += ( mShowGrid ? mGridStrokeWidth : 0 );
1275
+ currentX += ( mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0 );
1235
1276
QMap<int , double >::const_iterator maxColWidthIt = maxWidthMap.constBegin ();
1236
1277
int col = 1 ;
1237
1278
for ( ; maxColWidthIt != maxWidthMap.constEnd (); ++maxColWidthIt )
@@ -1246,7 +1287,7 @@ void QgsComposerTableV2::drawVerticalGridLines( QPainter *painter, const QMap<in
1246
1287
painter->drawLine ( QPointF ( currentX, halfGridStrokeWidth ), QPointF ( currentX, headerHeight - halfGridStrokeWidth ) );
1247
1288
}
1248
1289
1249
- currentX += ( mShowGrid ? mGridStrokeWidth : 0 );
1290
+ currentX += ( mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0 );
1250
1291
col++;
1251
1292
}
1252
1293
}
0 commit comments