Skip to content

Commit

Permalink
[composer] Seperate draw empty rows option from empty table behaviour
Browse files Browse the repository at this point in the history
Now "draw empty rows" is a seperate checkbox (fix #11392)
  • Loading branch information
nyalldawson committed Oct 14, 2014
1 parent 5ec1b75 commit 1cb22c0
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 36 deletions.
13 changes: 12 additions & 1 deletion python/core/composer/qgscomposertablev2.sip
Expand Up @@ -52,7 +52,6 @@ class QgsComposerTableV2: QgsComposerMultiFrame
{
HeadersOnly, /*!< show header rows only */
HideTable, /*!< hides entire table if empty */
DrawEmptyCells, /*!< draws empty cells */
ShowMessage /*!< shows preset message instead of table contents*/
};

Expand Down Expand Up @@ -103,6 +102,18 @@ class QgsComposerTableV2: QgsComposerMultiFrame
* @see emptyTableBehaviour
*/
QString emptyTableMessage() const;

/**Sets whether empty rows should be drawn. Tables default to hiding empty
* @param showEmpty set to true to show empty rows in the table
* @see showEmptyRows
*/
void setShowEmptyRows( const bool showEmpty );

/**Returns whether empty rows are drawn in the table
* @returns true if empty rows are drawn
* @see setShowEmptyRows
*/
bool showEmptyRows() const;

/**Sets the font used to draw header text in the table.
* @param font font for header cells
Expand Down
32 changes: 22 additions & 10 deletions src/app/composer/qgscomposerattributetablewidget.cpp
Expand Up @@ -46,7 +46,6 @@ QgsComposerAttributeTableWidget::QgsComposerAttributeTableWidget( QgsComposerAtt

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

bool atlasEnabled = atlasComposition() && atlasComposition()->enabled();
Expand Down Expand Up @@ -269,7 +268,6 @@ void QgsComposerAttributeTableWidget::on_mMarginSpinBox_valueChanged( double d )
composition->beginMultiFrameCommand( mComposerTable, tr( "Table margin changed" ), QgsComposerMultiFrameMergeCommand::TableMargin );
}
mComposerTable->setCellMargin( d );
mComposerTable->update();
if ( composition )
{
composition->endMultiFrameCommand();
Expand Down Expand Up @@ -318,7 +316,6 @@ void QgsComposerAttributeTableWidget::on_mHeaderFontColorButton_colorChanged( co
composition->beginMultiFrameCommand( mComposerTable, tr( "Table header font color" ) );
}
mComposerTable->setHeaderFontColor( newColor );
mComposerTable->update();
if ( composition )
{
composition->endMultiFrameCommand();
Expand Down Expand Up @@ -367,7 +364,6 @@ void QgsComposerAttributeTableWidget::on_mContentFontColorButton_colorChanged( c
composition->beginMultiFrameCommand( mComposerTable, tr( "Table content font color" ) );
}
mComposerTable->setContentFontColor( newColor );
mComposerTable->update();
if ( composition )
{
composition->endMultiFrameCommand();
Expand All @@ -387,7 +383,6 @@ void QgsComposerAttributeTableWidget::on_mGridStrokeWidthSpinBox_valueChanged( d
composition->beginMultiFrameCommand( mComposerTable, tr( "Table grid stroke" ), QgsComposerMultiFrameMergeCommand::TableGridStrokeWidth );
}
mComposerTable->setGridStrokeWidth( d );
mComposerTable->update();
if ( composition )
{
composition->endMultiFrameCommand();
Expand All @@ -407,7 +402,6 @@ void QgsComposerAttributeTableWidget::on_mGridColorButton_colorChanged( const QC
composition->beginMultiFrameCommand( mComposerTable, tr( "Table grid color" ) );
}
mComposerTable->setGridColor( newColor );
mComposerTable->update();
if ( composition )
{
composition->endMultiFrameCommand();
Expand All @@ -427,7 +421,6 @@ void QgsComposerAttributeTableWidget::on_mShowGridGroupCheckBox_toggled( bool st
composition->beginMultiFrameCommand( mComposerTable, tr( "Table grid toggled" ) );
}
mComposerTable->setShowGrid( state );
mComposerTable->update();
if ( composition )
{
composition->endMultiFrameCommand();
Expand All @@ -447,7 +440,6 @@ void QgsComposerAttributeTableWidget::on_mBackgroundColorButton_colorChanged( co
composition->beginMultiFrameCommand( mComposerTable, tr( "Table background color" ) );
}
mComposerTable->setBackgroundColor( newColor );
mComposerTable->update();
if ( composition )
{
composition->endMultiFrameCommand();
Expand Down Expand Up @@ -536,6 +528,7 @@ void QgsComposerAttributeTableWidget::updateGuiElements()
mEmptyMessageLineEdit->setText( mComposerTable->emptyTableMessage() );
mEmptyMessageLineEdit->setEnabled( mComposerTable->emptyTableBehaviour() == QgsComposerTableV2::ShowMessage );
mEmptyMessageLabel->setEnabled( mComposerTable->emptyTableBehaviour() == QgsComposerTableV2::ShowMessage );
mDrawEmptyCheckBox->setChecked( mComposerTable->showEmptyRows() );

mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mComposerTable->resizeMode() ) );
mAddFramePushButton->setEnabled( mComposerTable->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );
Expand Down Expand Up @@ -573,7 +566,7 @@ void QgsComposerAttributeTableWidget::updateRelationsCombo()
if ( atlasLayer )
{
QList<QgsRelation> relations = QgsProject::instance()->relationManager()->referencedRelations( mComposerTable->composition()->atlasComposition().coverageLayer() );
Q_FOREACH( const QgsRelation& relation, relations )
Q_FOREACH ( const QgsRelation& relation, relations )
{
mRelationsComboBox->addItem( relation.name(), relation.id() );
}
Expand Down Expand Up @@ -645,6 +638,7 @@ void QgsComposerAttributeTableWidget::blockAllSignals( bool b )
mEmptyMessageLineEdit->blockSignals( b );
mEmptyFrameCheckBox->blockSignals( b );
mHideEmptyBgCheckBox->blockSignals( b );
mDrawEmptyCheckBox->blockSignals( b );
}

void QgsComposerAttributeTableWidget::setMaximumNumberOfFeatures( int n )
Expand Down Expand Up @@ -993,6 +987,25 @@ void QgsComposerAttributeTableWidget::on_mEmptyModeComboBox_currentIndexChanged(
}
}

void QgsComposerAttributeTableWidget::on_mDrawEmptyCheckBox_toggled( bool checked )
{
if ( !mComposerTable )
{
return;
}

QgsComposition* composition = mComposerTable->composition();
if ( composition )
{
composition->beginMultiFrameCommand( mComposerTable, tr( "Show empty rows changed" ) );
}
mComposerTable->setShowEmptyRows( checked );
if ( composition )
{
composition->endMultiFrameCommand();
}
}

void QgsComposerAttributeTableWidget::on_mEmptyMessageLineEdit_editingFinished()
{
if ( !mComposerTable )
Expand All @@ -1006,7 +1019,6 @@ void QgsComposerAttributeTableWidget::on_mEmptyMessageLineEdit_editingFinished()
composition->beginMultiFrameCommand( mComposerTable, tr( "Empty table message changed" ) );
}
mComposerTable->setEmptyTableMessage( mEmptyMessageLineEdit->text() );
mComposerTable->update();
if ( composition )
{
composition->endMultiFrameCommand();
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgscomposerattributetablewidget.h
Expand Up @@ -72,6 +72,7 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
void on_mSourceComboBox_currentIndexChanged( int index );
void on_mRelationsComboBox_currentIndexChanged( int index );
void on_mEmptyModeComboBox_currentIndexChanged( int index );
void on_mDrawEmptyCheckBox_toggled( bool checked );
void on_mEmptyMessageLineEdit_editingFinished();
void on_mIntersectAtlasCheckBox_stateChanged( int state );
void on_mUniqueOnlyCheckBox_stateChanged( int state );
Expand Down
27 changes: 21 additions & 6 deletions src/core/composer/qgscomposertablev2.cpp
Expand Up @@ -25,6 +25,7 @@ QgsComposerTableV2::QgsComposerTableV2( QgsComposition *composition, bool create
: QgsComposerMultiFrame( composition, createUndoCommands )
, mCellMargin( 1.0 )
, mEmptyTableMode( HeadersOnly )
, mShowEmptyRows( false )
, mHeaderFontColor( Qt::black )
, mHeaderHAlignment( FollowColumn )
, mHeaderMode( FirstFrame )
Expand Down Expand Up @@ -67,6 +68,7 @@ bool QgsComposerTableV2::writeXML( QDomElement& elem, QDomDocument & doc, bool i
elem.setAttribute( "cellMargin", QString::number( mCellMargin ) );
elem.setAttribute( "emptyTableMode", QString::number(( int )mEmptyTableMode ) );
elem.setAttribute( "emptyTableMessage", mEmptyTableMessage );
elem.setAttribute( "showEmptyRows", mShowEmptyRows );
elem.setAttribute( "headerFont", mHeaderFont.toString() );
elem.setAttribute( "headerFontColor", QgsSymbolLayerV2Utils::encodeColor( mHeaderFontColor ) );
elem.setAttribute( "headerHAlignment", QString::number(( int )mHeaderHAlignment ) );
Expand Down Expand Up @@ -110,6 +112,7 @@ bool QgsComposerTableV2::readXML( const QDomElement &itemElem, const QDomDocumen

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

int numberRowsToDraw = rowsToShow.second - rowsToShow.first;
if ( mEmptyTableMode == QgsComposerTableV2::DrawEmptyCells )
if ( drawContents && mShowEmptyRows )
{
numberRowsToDraw = rowsVisible( frameIndex );
}
Expand Down Expand Up @@ -444,6 +447,18 @@ void QgsComposerTableV2::setEmptyTableMessage( const QString message )
emit changed();
}

void QgsComposerTableV2::setShowEmptyRows( const bool showEmpty )
{
if ( showEmpty == mShowEmptyRows )
{
return;
}

mShowEmptyRows = showEmpty;
update();
emit changed();
}

void QgsComposerTableV2::setHeaderFont( const QFont &font )
{
if ( font == mHeaderFont )
Expand All @@ -466,7 +481,7 @@ void QgsComposerTableV2::setHeaderFontColor( const QColor &color )
}

mHeaderFontColor = color;
repaint();
update();

emit changed();
}
Expand All @@ -479,7 +494,7 @@ void QgsComposerTableV2::setHeaderHAlignment( const QgsComposerTableV2::HeaderHA
}

mHeaderHAlignment = alignment;
repaint();
update();

emit changed();
}
Expand Down Expand Up @@ -519,7 +534,7 @@ void QgsComposerTableV2::setContentFontColor( const QColor &color )
}

mContentFontColor = color;
repaint();
update();

emit changed();
}
Expand Down Expand Up @@ -560,7 +575,7 @@ void QgsComposerTableV2::setGridColor( const QColor &color )
}

mGridColor = color;
repaint();
update();

emit changed();
}
Expand All @@ -573,7 +588,7 @@ void QgsComposerTableV2::setBackgroundColor( const QColor &color )
}

mBackgroundColor = color;
repaint();
update();

emit changed();
}
Expand Down
16 changes: 15 additions & 1 deletion src/core/composer/qgscomposertablev2.h
Expand Up @@ -77,7 +77,6 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
{
HeadersOnly = 0, /*!< show header rows only */
HideTable, /*!< hides entire table if empty */
DrawEmptyCells, /*!< draws empty cells */
ShowMessage /*!< shows preset message instead of table contents*/
};

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

/**Sets whether empty rows should be drawn. Tables default to hiding empty rows.
* @param showEmpty set to true to show empty rows in the table
* @see showEmptyRows
*/
void setShowEmptyRows( const bool showEmpty );

/**Returns whether empty rows are drawn in the table
* @returns true if empty rows are drawn
* @see setShowEmptyRows
*/
bool showEmptyRows() const { return mShowEmptyRows; }

/**Sets the font used to draw header text in the table.
* @param font font for header cells
* @see headerFont
Expand Down Expand Up @@ -340,6 +351,9 @@ class CORE_EXPORT QgsComposerTableV2: public QgsComposerMultiFrame
/**String to show in empty tables*/
QString mEmptyTableMessage;

/**True if empty rows should be shown in the table*/
bool mShowEmptyRows;

/**Header font*/
QFont mHeaderFont;

Expand Down
31 changes: 19 additions & 12 deletions src/ui/qgscomposerattributetablewidgetbase.ui
Expand Up @@ -45,9 +45,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-91</y>
<width>392</width>
<height>1164</height>
<height>1192</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
Expand Down Expand Up @@ -237,7 +237,7 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<item row="2" column="0">
<widget class="QLabel" name="mMarginLabel">
<property name="text">
<string>Cell margins</string>
Expand All @@ -250,21 +250,21 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="mMarginSpinBox">
<property name="suffix">
<string> mm</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Display header</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="3" column="1">
<widget class="QComboBox" name="mHeaderModeComboBox">
<item>
<property name="text">
Expand All @@ -283,34 +283,34 @@
</item>
</widget>
</item>
<item row="2" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Empty tables</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="5" column="1">
<widget class="QComboBox" name="mEmptyModeComboBox"/>
</item>
<item row="3" column="0">
<item row="6" column="0">
<widget class="QLabel" name="mEmptyMessageLabel">
<property name="text">
<string>Message to display</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="6" column="1">
<widget class="QLineEdit" name="mEmptyMessageLineEdit"/>
</item>
<item row="4" column="0">
<item row="7" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Background color</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="7" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QgsColorButtonV2" name="mBackgroundColorButton">
Expand Down Expand Up @@ -346,6 +346,13 @@
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="mDrawEmptyCheckBox">
<property name="text">
<string>Show empty rows</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 1cb22c0

Please sign in to comment.