Skip to content
Permalink
Browse files

[composer] Seperate draw empty rows option from empty table behaviour

Now "draw empty rows" is a seperate checkbox (fix #11392)
  • Loading branch information
nyalldawson committed Oct 14, 2014
1 parent 5ec1b75 commit 1cb22c084d27df9a2f867328def61c30211340f4
@@ -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*/
};

@@ -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
@@ -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();
@@ -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();
@@ -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();
@@ -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();
@@ -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();
@@ -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();
@@ -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();
@@ -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();
@@ -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 );
@@ -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() );
}
@@ -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 )
@@ -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 )
@@ -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();
@@ -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 );
@@ -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 )
@@ -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 ) );
@@ -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() );
@@ -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 );
}
@@ -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 )
@@ -466,7 +481,7 @@ void QgsComposerTableV2::setHeaderFontColor( const QColor &color )
}

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

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

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

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

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

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

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

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

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

emit changed();
}
@@ -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*/
};

@@ -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
@@ -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;

@@ -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">
@@ -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>
@@ -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">
@@ -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">
@@ -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>

0 comments on commit 1cb22c0

Please sign in to comment.
You can’t perform that action at this time.