Skip to content

Commit 1cb22c0

Browse files
committedOct 14, 2014
[composer] Seperate draw empty rows option from empty table behaviour
Now "draw empty rows" is a seperate checkbox (fix #11392)
1 parent 5ec1b75 commit 1cb22c0

File tree

8 files changed

+103
-36
lines changed

8 files changed

+103
-36
lines changed
 

‎python/core/composer/qgscomposertablev2.sip

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class QgsComposerTableV2: QgsComposerMultiFrame
5252
{
5353
HeadersOnly, /*!< show header rows only */
5454
HideTable, /*!< hides entire table if empty */
55-
DrawEmptyCells, /*!< draws empty cells */
5655
ShowMessage /*!< shows preset message instead of table contents*/
5756
};
5857

@@ -103,6 +102,18 @@ class QgsComposerTableV2: QgsComposerMultiFrame
103102
* @see emptyTableBehaviour
104103
*/
105104
QString emptyTableMessage() const;
105+
106+
/**Sets whether empty rows should be drawn. Tables default to hiding empty
107+
* @param showEmpty set to true to show empty rows in the table
108+
* @see showEmptyRows
109+
*/
110+
void setShowEmptyRows( const bool showEmpty );
111+
112+
/**Returns whether empty rows are drawn in the table
113+
* @returns true if empty rows are drawn
114+
* @see setShowEmptyRows
115+
*/
116+
bool showEmptyRows() const;
106117

107118
/**Sets the font used to draw header text in the table.
108119
* @param font font for header cells

‎src/app/composer/qgscomposerattributetablewidget.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ QgsComposerAttributeTableWidget::QgsComposerAttributeTableWidget( QgsComposerAtt
4646

4747
mEmptyModeComboBox->addItem( tr( "Draw headers only" ), QgsComposerTableV2::HeadersOnly );
4848
mEmptyModeComboBox->addItem( tr( "Hide entire table" ), QgsComposerTableV2::HideTable );
49-
mEmptyModeComboBox->addItem( tr( "Draw empty cells" ), QgsComposerTableV2::DrawEmptyCells );
5049
mEmptyModeComboBox->addItem( tr( "Show set message" ), QgsComposerTableV2::ShowMessage );
5150

5251
bool atlasEnabled = atlasComposition() && atlasComposition()->enabled();
@@ -269,7 +268,6 @@ void QgsComposerAttributeTableWidget::on_mMarginSpinBox_valueChanged( double d )
269268
composition->beginMultiFrameCommand( mComposerTable, tr( "Table margin changed" ), QgsComposerMultiFrameMergeCommand::TableMargin );
270269
}
271270
mComposerTable->setCellMargin( d );
272-
mComposerTable->update();
273271
if ( composition )
274272
{
275273
composition->endMultiFrameCommand();
@@ -318,7 +316,6 @@ void QgsComposerAttributeTableWidget::on_mHeaderFontColorButton_colorChanged( co
318316
composition->beginMultiFrameCommand( mComposerTable, tr( "Table header font color" ) );
319317
}
320318
mComposerTable->setHeaderFontColor( newColor );
321-
mComposerTable->update();
322319
if ( composition )
323320
{
324321
composition->endMultiFrameCommand();
@@ -367,7 +364,6 @@ void QgsComposerAttributeTableWidget::on_mContentFontColorButton_colorChanged( c
367364
composition->beginMultiFrameCommand( mComposerTable, tr( "Table content font color" ) );
368365
}
369366
mComposerTable->setContentFontColor( newColor );
370-
mComposerTable->update();
371367
if ( composition )
372368
{
373369
composition->endMultiFrameCommand();
@@ -387,7 +383,6 @@ void QgsComposerAttributeTableWidget::on_mGridStrokeWidthSpinBox_valueChanged( d
387383
composition->beginMultiFrameCommand( mComposerTable, tr( "Table grid stroke" ), QgsComposerMultiFrameMergeCommand::TableGridStrokeWidth );
388384
}
389385
mComposerTable->setGridStrokeWidth( d );
390-
mComposerTable->update();
391386
if ( composition )
392387
{
393388
composition->endMultiFrameCommand();
@@ -407,7 +402,6 @@ void QgsComposerAttributeTableWidget::on_mGridColorButton_colorChanged( const QC
407402
composition->beginMultiFrameCommand( mComposerTable, tr( "Table grid color" ) );
408403
}
409404
mComposerTable->setGridColor( newColor );
410-
mComposerTable->update();
411405
if ( composition )
412406
{
413407
composition->endMultiFrameCommand();
@@ -427,7 +421,6 @@ void QgsComposerAttributeTableWidget::on_mShowGridGroupCheckBox_toggled( bool st
427421
composition->beginMultiFrameCommand( mComposerTable, tr( "Table grid toggled" ) );
428422
}
429423
mComposerTable->setShowGrid( state );
430-
mComposerTable->update();
431424
if ( composition )
432425
{
433426
composition->endMultiFrameCommand();
@@ -447,7 +440,6 @@ void QgsComposerAttributeTableWidget::on_mBackgroundColorButton_colorChanged( co
447440
composition->beginMultiFrameCommand( mComposerTable, tr( "Table background color" ) );
448441
}
449442
mComposerTable->setBackgroundColor( newColor );
450-
mComposerTable->update();
451443
if ( composition )
452444
{
453445
composition->endMultiFrameCommand();
@@ -536,6 +528,7 @@ void QgsComposerAttributeTableWidget::updateGuiElements()
536528
mEmptyMessageLineEdit->setText( mComposerTable->emptyTableMessage() );
537529
mEmptyMessageLineEdit->setEnabled( mComposerTable->emptyTableBehaviour() == QgsComposerTableV2::ShowMessage );
538530
mEmptyMessageLabel->setEnabled( mComposerTable->emptyTableBehaviour() == QgsComposerTableV2::ShowMessage );
531+
mDrawEmptyCheckBox->setChecked( mComposerTable->showEmptyRows() );
539532

540533
mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mComposerTable->resizeMode() ) );
541534
mAddFramePushButton->setEnabled( mComposerTable->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );
@@ -573,7 +566,7 @@ void QgsComposerAttributeTableWidget::updateRelationsCombo()
573566
if ( atlasLayer )
574567
{
575568
QList<QgsRelation> relations = QgsProject::instance()->relationManager()->referencedRelations( mComposerTable->composition()->atlasComposition().coverageLayer() );
576-
Q_FOREACH( const QgsRelation& relation, relations )
569+
Q_FOREACH ( const QgsRelation& relation, relations )
577570
{
578571
mRelationsComboBox->addItem( relation.name(), relation.id() );
579572
}
@@ -645,6 +638,7 @@ void QgsComposerAttributeTableWidget::blockAllSignals( bool b )
645638
mEmptyMessageLineEdit->blockSignals( b );
646639
mEmptyFrameCheckBox->blockSignals( b );
647640
mHideEmptyBgCheckBox->blockSignals( b );
641+
mDrawEmptyCheckBox->blockSignals( b );
648642
}
649643

650644
void QgsComposerAttributeTableWidget::setMaximumNumberOfFeatures( int n )
@@ -993,6 +987,25 @@ void QgsComposerAttributeTableWidget::on_mEmptyModeComboBox_currentIndexChanged(
993987
}
994988
}
995989

990+
void QgsComposerAttributeTableWidget::on_mDrawEmptyCheckBox_toggled( bool checked )
991+
{
992+
if ( !mComposerTable )
993+
{
994+
return;
995+
}
996+
997+
QgsComposition* composition = mComposerTable->composition();
998+
if ( composition )
999+
{
1000+
composition->beginMultiFrameCommand( mComposerTable, tr( "Show empty rows changed" ) );
1001+
}
1002+
mComposerTable->setShowEmptyRows( checked );
1003+
if ( composition )
1004+
{
1005+
composition->endMultiFrameCommand();
1006+
}
1007+
}
1008+
9961009
void QgsComposerAttributeTableWidget::on_mEmptyMessageLineEdit_editingFinished()
9971010
{
9981011
if ( !mComposerTable )
@@ -1006,7 +1019,6 @@ void QgsComposerAttributeTableWidget::on_mEmptyMessageLineEdit_editingFinished()
10061019
composition->beginMultiFrameCommand( mComposerTable, tr( "Empty table message changed" ) );
10071020
}
10081021
mComposerTable->setEmptyTableMessage( mEmptyMessageLineEdit->text() );
1009-
mComposerTable->update();
10101022
if ( composition )
10111023
{
10121024
composition->endMultiFrameCommand();

‎src/app/composer/qgscomposerattributetablewidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
7272
void on_mSourceComboBox_currentIndexChanged( int index );
7373
void on_mRelationsComboBox_currentIndexChanged( int index );
7474
void on_mEmptyModeComboBox_currentIndexChanged( int index );
75+
void on_mDrawEmptyCheckBox_toggled( bool checked );
7576
void on_mEmptyMessageLineEdit_editingFinished();
7677
void on_mIntersectAtlasCheckBox_stateChanged( int state );
7778
void on_mUniqueOnlyCheckBox_stateChanged( int state );

‎src/core/composer/qgscomposertablev2.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ QgsComposerTableV2::QgsComposerTableV2( QgsComposition *composition, bool create
2525
: QgsComposerMultiFrame( composition, createUndoCommands )
2626
, mCellMargin( 1.0 )
2727
, mEmptyTableMode( HeadersOnly )
28+
, mShowEmptyRows( false )
2829
, mHeaderFontColor( Qt::black )
2930
, mHeaderHAlignment( FollowColumn )
3031
, mHeaderMode( FirstFrame )
@@ -67,6 +68,7 @@ bool QgsComposerTableV2::writeXML( QDomElement& elem, QDomDocument & doc, bool i
6768
elem.setAttribute( "cellMargin", QString::number( mCellMargin ) );
6869
elem.setAttribute( "emptyTableMode", QString::number(( int )mEmptyTableMode ) );
6970
elem.setAttribute( "emptyTableMessage", mEmptyTableMessage );
71+
elem.setAttribute( "showEmptyRows", mShowEmptyRows );
7072
elem.setAttribute( "headerFont", mHeaderFont.toString() );
7173
elem.setAttribute( "headerFontColor", QgsSymbolLayerV2Utils::encodeColor( mHeaderFontColor ) );
7274
elem.setAttribute( "headerHAlignment", QString::number(( int )mHeaderHAlignment ) );
@@ -110,6 +112,7 @@ bool QgsComposerTableV2::readXML( const QDomElement &itemElem, const QDomDocumen
110112

111113
mEmptyTableMode = QgsComposerTableV2::EmptyTableMode( itemElem.attribute( "emptyTableMode", "0" ).toInt() );
112114
mEmptyTableMessage = itemElem.attribute( "emptyTableMessage", tr( "No matching records" ) );
115+
mShowEmptyRows = itemElem.attribute( "showEmptyRows", "0" ).toInt();
113116
mHeaderFont.fromString( itemElem.attribute( "headerFont", "" ) );
114117
mHeaderFontColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "headerFontColor", "0,0,0,255" ) );
115118
mHeaderHAlignment = QgsComposerTableV2::HeaderHAlignment( itemElem.attribute( "headerHAlignment", "0" ).toInt() );
@@ -270,7 +273,7 @@ void QgsComposerTableV2::render( QPainter *p, const QRectF &renderExtent, const
270273
bool drawContents = !( emptyTable && mEmptyTableMode == QgsComposerTableV2::ShowMessage );
271274

272275
int numberRowsToDraw = rowsToShow.second - rowsToShow.first;
273-
if ( mEmptyTableMode == QgsComposerTableV2::DrawEmptyCells )
276+
if ( drawContents && mShowEmptyRows )
274277
{
275278
numberRowsToDraw = rowsVisible( frameIndex );
276279
}
@@ -444,6 +447,18 @@ void QgsComposerTableV2::setEmptyTableMessage( const QString message )
444447
emit changed();
445448
}
446449

450+
void QgsComposerTableV2::setShowEmptyRows( const bool showEmpty )
451+
{
452+
if ( showEmpty == mShowEmptyRows )
453+
{
454+
return;
455+
}
456+
457+
mShowEmptyRows = showEmpty;
458+
update();
459+
emit changed();
460+
}
461+
447462
void QgsComposerTableV2::setHeaderFont( const QFont &font )
448463
{
449464
if ( font == mHeaderFont )
@@ -466,7 +481,7 @@ void QgsComposerTableV2::setHeaderFontColor( const QColor &color )
466481
}
467482

468483
mHeaderFontColor = color;
469-
repaint();
484+
update();
470485

471486
emit changed();
472487
}
@@ -479,7 +494,7 @@ void QgsComposerTableV2::setHeaderHAlignment( const QgsComposerTableV2::HeaderHA
479494
}
480495

481496
mHeaderHAlignment = alignment;
482-
repaint();
497+
update();
483498

484499
emit changed();
485500
}
@@ -519,7 +534,7 @@ void QgsComposerTableV2::setContentFontColor( const QColor &color )
519534
}
520535

521536
mContentFontColor = color;
522-
repaint();
537+
update();
523538

524539
emit changed();
525540
}
@@ -560,7 +575,7 @@ void QgsComposerTableV2::setGridColor( const QColor &color )
560575
}
561576

562577
mGridColor = color;
563-
repaint();
578+
update();
564579

565580
emit changed();
566581
}
@@ -573,7 +588,7 @@ void QgsComposerTableV2::setBackgroundColor( const QColor &color )
573588
}
574589

575590
mBackgroundColor = color;
576-
repaint();
591+
update();
577592

578593
emit changed();
579594
}

‎src/core/composer/qgscomposertablev2.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
7777
{
7878
HeadersOnly = 0, /*!< show header rows only */
7979
HideTable, /*!< hides entire table if empty */
80-
DrawEmptyCells, /*!< draws empty cells */
8180
ShowMessage /*!< shows preset message instead of table contents*/
8281
};
8382

@@ -129,6 +128,18 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
129128
*/
130129
QString emptyTableMessage() const { return mEmptyTableMessage; }
131130

131+
/**Sets whether empty rows should be drawn. Tables default to hiding empty rows.
132+
* @param showEmpty set to true to show empty rows in the table
133+
* @see showEmptyRows
134+
*/
135+
void setShowEmptyRows( const bool showEmpty );
136+
137+
/**Returns whether empty rows are drawn in the table
138+
* @returns true if empty rows are drawn
139+
* @see setShowEmptyRows
140+
*/
141+
bool showEmptyRows() const { return mShowEmptyRows; }
142+
132143
/**Sets the font used to draw header text in the table.
133144
* @param font font for header cells
134145
* @see headerFont
@@ -340,6 +351,9 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
340351
/**String to show in empty tables*/
341352
QString mEmptyTableMessage;
342353

354+
/**True if empty rows should be shown in the table*/
355+
bool mShowEmptyRows;
356+
343357
/**Header font*/
344358
QFont mHeaderFont;
345359

‎src/ui/qgscomposerattributetablewidgetbase.ui

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
<property name="geometry">
4646
<rect>
4747
<x>0</x>
48-
<y>0</y>
48+
<y>-91</y>
4949
<width>392</width>
50-
<height>1164</height>
50+
<height>1192</height>
5151
</rect>
5252
</property>
5353
<layout class="QVBoxLayout" name="mainLayout">
@@ -237,7 +237,7 @@
237237
<bool>false</bool>
238238
</property>
239239
<layout class="QGridLayout" name="gridLayout_6">
240-
<item row="0" column="0">
240+
<item row="2" column="0">
241241
<widget class="QLabel" name="mMarginLabel">
242242
<property name="text">
243243
<string>Cell margins</string>
@@ -250,21 +250,21 @@
250250
</property>
251251
</widget>
252252
</item>
253-
<item row="0" column="1">
253+
<item row="2" column="1">
254254
<widget class="QDoubleSpinBox" name="mMarginSpinBox">
255255
<property name="suffix">
256256
<string> mm</string>
257257
</property>
258258
</widget>
259259
</item>
260-
<item row="1" column="0">
260+
<item row="3" column="0">
261261
<widget class="QLabel" name="label_7">
262262
<property name="text">
263263
<string>Display header</string>
264264
</property>
265265
</widget>
266266
</item>
267-
<item row="1" column="1">
267+
<item row="3" column="1">
268268
<widget class="QComboBox" name="mHeaderModeComboBox">
269269
<item>
270270
<property name="text">
@@ -283,34 +283,34 @@
283283
</item>
284284
</widget>
285285
</item>
286-
<item row="2" column="0">
286+
<item row="5" column="0">
287287
<widget class="QLabel" name="label_9">
288288
<property name="text">
289289
<string>Empty tables</string>
290290
</property>
291291
</widget>
292292
</item>
293-
<item row="2" column="1">
293+
<item row="5" column="1">
294294
<widget class="QComboBox" name="mEmptyModeComboBox"/>
295295
</item>
296-
<item row="3" column="0">
296+
<item row="6" column="0">
297297
<widget class="QLabel" name="mEmptyMessageLabel">
298298
<property name="text">
299299
<string>Message to display</string>
300300
</property>
301301
</widget>
302302
</item>
303-
<item row="3" column="1">
303+
<item row="6" column="1">
304304
<widget class="QLineEdit" name="mEmptyMessageLineEdit"/>
305305
</item>
306-
<item row="4" column="0">
306+
<item row="7" column="0">
307307
<widget class="QLabel" name="label_10">
308308
<property name="text">
309309
<string>Background color</string>
310310
</property>
311311
</widget>
312312
</item>
313-
<item row="4" column="1">
313+
<item row="7" column="1">
314314
<layout class="QHBoxLayout" name="horizontalLayout_5">
315315
<item>
316316
<widget class="QgsColorButtonV2" name="mBackgroundColorButton">
@@ -346,6 +346,13 @@
346346
</item>
347347
</layout>
348348
</item>
349+
<item row="1" column="0" colspan="2">
350+
<widget class="QCheckBox" name="mDrawEmptyCheckBox">
351+
<property name="text">
352+
<string>Show empty rows</string>
353+
</property>
354+
</widget>
355+
</item>
349356
</layout>
350357
</widget>
351358
</item>

‎tests/src/core/testqgscomposertablev2.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class TestQgsComposerTableV2: public QObject
5151
void attributeTableRender(); //test rendering attribute table
5252
void manualColumnWidth(); //test setting manual column widths
5353
void attributeTableEmpty(); //test empty modes for attribute table
54+
void showEmptyRows(); //test showing empty rows
5455
void attributeTableExtend();
5556
void attributeTableRepeat();
5657
void attributeTableAtlasSource(); //test attribute table in atlas feature mode
@@ -341,18 +342,24 @@ void TestQgsComposerTableV2::attributeTableEmpty()
341342
QgsCompositionChecker checker2( "composerattributetable_hidetable", mComposition );
342343
QVERIFY( checker2.testComposition( mReport, 0 ) );
343344

344-
mComposerAttributeTable->setEmptyTableBehaviour( QgsComposerTableV2::DrawEmptyCells );
345-
QgsCompositionChecker checker3( "composerattributetable_drawempty", mComposition );
346-
QVERIFY( checker3.testComposition( mReport, 0 ) );
347-
348345
mComposerAttributeTable->setEmptyTableBehaviour( QgsComposerTableV2::ShowMessage );
349346
mComposerAttributeTable->setEmptyTableMessage( "no rows" );
350-
QgsCompositionChecker checker4( "composerattributetable_showmessage", mComposition );
351-
QVERIFY( checker4.testComposition( mReport, 0 ) );
347+
QgsCompositionChecker checker3( "composerattributetable_showmessage", mComposition );
348+
QVERIFY( checker3.testComposition( mReport, 0 ) );
352349

353350
mComposerAttributeTable->setFilterFeatures( false );
354351
}
355352

353+
void TestQgsComposerTableV2::showEmptyRows()
354+
{
355+
mComposerAttributeTable->setMaximumNumberOfFeatures( 3 );
356+
mComposerAttributeTable->setShowEmptyRows( true );
357+
QgsCompositionChecker checker( "composerattributetable_drawempty", mComposition );
358+
QVERIFY( checker.testComposition( mReport, 0 ) );
359+
mComposerAttributeTable->setMaximumNumberOfFeatures( 20 );
360+
mComposerAttributeTable->setShowEmptyRows( false );
361+
}
362+
356363
void TestQgsComposerTableV2::attributeTableExtend()
357364
{
358365
//test that adding and removing frames automatically does not result in a crash
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.