[composer] Add a checkbox to prevent drawing border and background for empty frame items

This commit is contained in:
Nyall Dawson 2014-09-26 17:45:07 +10:00
parent ce2142585a
commit a9c97ae153
9 changed files with 125 additions and 29 deletions

View File

@ -56,6 +56,20 @@ class QgsComposerFrame: QgsComposerItem
*/ */
void setHidePageIfEmpty( const bool hidePageIfEmpty ); void setHidePageIfEmpty( const bool hidePageIfEmpty );
/**Returns whether the background and frame border should be hidden if this frame is empty
* @returns true if background and border should be hidden if frame is empty
* @note added in QGIS 2.5
* @see setHideBackgroundIfEmpty
*/
bool hideBackgroundIfEmpty() const;
/**Sets whether the background and frame border should be hidden if this frame is empty
* @param hideBackgroundIfEmpty set to true if background and border should be hidden if frame is empty
* @note added in QGIS 2.5
* @see hideBackgroundIfEmpty
*/
void setHideBackgroundIfEmpty( const bool hideBackgroundIfEmpty );
/**Returns whether the frame is empty /**Returns whether the frame is empty
* @returns true if frame is empty * @returns true if frame is empty
* @note added in QGIS 2.5 * @note added in QGIS 2.5

View File

@ -515,6 +515,7 @@ void QgsComposerAttributeTableWidget::updateGuiElements()
mAddFramePushButton->setEnabled( mComposerTable->resizeMode() == QgsComposerMultiFrame::UseExistingFrames ); mAddFramePushButton->setEnabled( mComposerTable->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );
mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() ); mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
toggleSourceControls(); toggleSourceControls();
@ -616,6 +617,7 @@ void QgsComposerAttributeTableWidget::blockAllSignals( bool b )
mEmptyModeComboBox->blockSignals( b ); mEmptyModeComboBox->blockSignals( b );
mEmptyMessageLineEdit->blockSignals( b ); mEmptyMessageLineEdit->blockSignals( b );
mEmptyFrameCheckBox->blockSignals( b ); mEmptyFrameCheckBox->blockSignals( b );
mHideEmptyBgCheckBox->blockSignals( b );
} }
void QgsComposerAttributeTableWidget::setMaximumNumberOfFeatures( int n ) void QgsComposerAttributeTableWidget::setMaximumNumberOfFeatures( int n )
@ -670,7 +672,6 @@ void QgsComposerAttributeTableWidget::on_mUniqueOnlyCheckBox_stateChanged( int s
} }
} }
void QgsComposerAttributeTableWidget::on_mEmptyFrameCheckBox_toggled( bool checked ) void QgsComposerAttributeTableWidget::on_mEmptyFrameCheckBox_toggled( bool checked )
{ {
if ( !mFrame ) if ( !mFrame )
@ -683,6 +684,18 @@ void QgsComposerAttributeTableWidget::on_mEmptyFrameCheckBox_toggled( bool check
mFrame->endCommand(); mFrame->endCommand();
} }
void QgsComposerAttributeTableWidget::on_mHideEmptyBgCheckBox_toggled( bool checked )
{
if ( !mFrame )
{
return;
}
mFrame->beginCommand( tr( "Hide background if empty toggled" ) );
mFrame->setHideBackgroundIfEmpty( checked );
mFrame->endCommand();
}
void QgsComposerAttributeTableWidget::on_mIntersectAtlasCheckBox_stateChanged( int state ) void QgsComposerAttributeTableWidget::on_mIntersectAtlasCheckBox_stateChanged( int state )
{ {
if ( !mComposerTable ) if ( !mComposerTable )

View File

@ -75,6 +75,7 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
void on_mIntersectAtlasCheckBox_stateChanged( int state ); void on_mIntersectAtlasCheckBox_stateChanged( int state );
void on_mUniqueOnlyCheckBox_stateChanged( int state ); void on_mUniqueOnlyCheckBox_stateChanged( int state );
void on_mEmptyFrameCheckBox_toggled( bool checked ); void on_mEmptyFrameCheckBox_toggled( bool checked );
void on_mHideEmptyBgCheckBox_toggled( bool checked );
/**Inserts a new maximum number of features into the spin box (without the spinbox emitting a signal)*/ /**Inserts a new maximum number of features into the spin box (without the spinbox emitting a signal)*/
void setMaximumNumberOfFeatures( int n ); void setMaximumNumberOfFeatures( int n );
@ -85,7 +86,6 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
void atlasToggled(); void atlasToggled();
void updateRelationsCombo(); void updateRelationsCombo();
}; };
#endif // QGSCOMPOSERATTRIBUTETABLEWIDGET_H #endif // QGSCOMPOSERATTRIBUTETABLEWIDGET_H

View File

@ -101,6 +101,7 @@ void QgsComposerHtmlWidget::blockSignals( bool block )
mRadioUrlSource->blockSignals( block ); mRadioUrlSource->blockSignals( block );
mEvaluateExpressionsCheckbox->blockSignals( block ); mEvaluateExpressionsCheckbox->blockSignals( block );
mEmptyFrameCheckBox->blockSignals( block ); mEmptyFrameCheckBox->blockSignals( block );
mHideEmptyBgCheckBox->blockSignals( block );
} }
void QgsComposerHtmlWidget::on_mUrlLineEdit_editingFinished() void QgsComposerHtmlWidget::on_mUrlLineEdit_editingFinished()
@ -278,6 +279,18 @@ void QgsComposerHtmlWidget::on_mEmptyFrameCheckBox_toggled( bool checked )
mFrame->endCommand(); mFrame->endCommand();
} }
void QgsComposerHtmlWidget::on_mHideEmptyBgCheckBox_toggled( bool checked )
{
if ( !mFrame )
{
return;
}
mFrame->beginCommand( tr( "Hide background if empty toggled" ) );
mFrame->setHideBackgroundIfEmpty( checked );
mFrame->endCommand();
}
void QgsComposerHtmlWidget::on_mRadioManualSource_clicked( bool checked ) void QgsComposerHtmlWidget::on_mRadioManualSource_clicked( bool checked )
{ {
if ( !mHtml ) if ( !mHtml )
@ -447,6 +460,7 @@ void QgsComposerHtmlWidget::setGuiElementValues()
mStylesheetEditor->setText( mHtml->userStylesheet() ); mStylesheetEditor->setText( mHtml->userStylesheet() );
mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() ); mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
populateDataDefinedButtons(); populateDataDefinedButtons();

View File

@ -48,11 +48,13 @@ class QgsComposerHtmlWidget: public QgsComposerItemBaseWidget, private Ui::QgsCo
void on_mReloadPushButton2_clicked(); void on_mReloadPushButton2_clicked();
void on_mAddFramePushButton_clicked(); void on_mAddFramePushButton_clicked();
void on_mEmptyFrameCheckBox_toggled( bool checked ); void on_mEmptyFrameCheckBox_toggled( bool checked );
void on_mHideEmptyBgCheckBox_toggled( bool checked );
/**Sets the GUI elements to the values of mHtmlItem*/ /**Sets the GUI elements to the values of mHtmlItem*/
void setGuiElementValues(); void setGuiElementValues();
protected: protected:
QgsComposerItem::DataDefinedProperty ddPropertyForWidget( QgsDataDefinedButton *widget ); QgsComposerItem::DataDefinedProperty ddPropertyForWidget( QgsDataDefinedButton *widget );
protected slots: protected slots:

View File

@ -21,6 +21,7 @@ QgsComposerFrame::QgsComposerFrame( QgsComposition* c, QgsComposerMultiFrame* mf
: QgsComposerItem( x, y, width, height, c ) : QgsComposerItem( x, y, width, height, c )
, mMultiFrame( mf ) , mMultiFrame( mf )
, mHidePageIfEmpty( false ) , mHidePageIfEmpty( false )
, mHideBackgroundIfEmpty( false )
{ {
//repaint frame when multiframe content changes //repaint frame when multiframe content changes
connect( mf, SIGNAL( contentsChanged() ), this, SLOT( repaint() ) ); connect( mf, SIGNAL( contentsChanged() ), this, SLOT( repaint() ) );
@ -35,6 +36,7 @@ QgsComposerFrame::QgsComposerFrame()
: QgsComposerItem( 0, 0, 0, 0, 0 ) : QgsComposerItem( 0, 0, 0, 0, 0 )
, mMultiFrame( 0 ) , mMultiFrame( 0 )
, mHidePageIfEmpty( false ) , mHidePageIfEmpty( false )
, mHideBackgroundIfEmpty( false )
{ {
} }
@ -50,7 +52,7 @@ bool QgsComposerFrame::writeXML( QDomElement& elem, QDomDocument & doc ) const
frameElem.setAttribute( "sectionWidth", QString::number( mSection.width() ) ); frameElem.setAttribute( "sectionWidth", QString::number( mSection.width() ) );
frameElem.setAttribute( "sectionHeight", QString::number( mSection.height() ) ); frameElem.setAttribute( "sectionHeight", QString::number( mSection.height() ) );
frameElem.setAttribute( "hidePageIfEmpty", mHidePageIfEmpty ); frameElem.setAttribute( "hidePageIfEmpty", mHidePageIfEmpty );
frameElem.setAttribute( "hideBackgroundIfEmpty", mHideBackgroundIfEmpty );
elem.appendChild( frameElem ); elem.appendChild( frameElem );
return _writeXML( frameElem, doc ); return _writeXML( frameElem, doc );
@ -64,6 +66,7 @@ bool QgsComposerFrame::readXML( const QDomElement& itemElem, const QDomDocument&
double height = itemElem.attribute( "sectionHeight" ).toDouble(); double height = itemElem.attribute( "sectionHeight" ).toDouble();
mSection = QRectF( x, y, width, height ); mSection = QRectF( x, y, width, height );
mHidePageIfEmpty = itemElem.attribute( "hidePageIfEmpty", "0" ).toInt(); mHidePageIfEmpty = itemElem.attribute( "hidePageIfEmpty", "0" ).toInt();
mHideBackgroundIfEmpty = itemElem.attribute( "hideBackgroundIfEmpty", "0" ).toInt();
QDomElement composerItem = itemElem.firstChildElement( "ComposerItem" ); QDomElement composerItem = itemElem.firstChildElement( "ComposerItem" );
if ( composerItem.isNull() ) if ( composerItem.isNull() )
{ {
@ -77,6 +80,17 @@ void QgsComposerFrame::setHidePageIfEmpty( const bool hidePageIfEmpty )
mHidePageIfEmpty = hidePageIfEmpty; mHidePageIfEmpty = hidePageIfEmpty;
} }
void QgsComposerFrame::setHideBackgroundIfEmpty( const bool hideBackgroundIfEmpty )
{
if ( hideBackgroundIfEmpty == mHideBackgroundIfEmpty )
{
return;
}
mHideBackgroundIfEmpty = hideBackgroundIfEmpty;
update();
}
bool QgsComposerFrame::isEmpty() const bool QgsComposerFrame::isEmpty() const
{ {
if ( !mMultiFrame ) if ( !mMultiFrame )
@ -152,7 +166,12 @@ void QgsComposerFrame::paint( QPainter* painter, const QStyleOptionGraphicsItem*
return; return;
} }
drawBackground( painter ); bool empty = isEmpty();
if ( !empty || !mHideBackgroundIfEmpty )
{
drawBackground( painter );
}
if ( mMultiFrame ) if ( mMultiFrame )
{ {
//calculate index of frame //calculate index of frame
@ -160,7 +179,10 @@ void QgsComposerFrame::paint( QPainter* painter, const QStyleOptionGraphicsItem*
mMultiFrame->render( painter, mSection, frameIndex ); mMultiFrame->render( painter, mSection, frameIndex );
} }
drawFrame( painter ); if ( !empty || !mHideBackgroundIfEmpty )
{
drawFrame( painter );
}
if ( isSelected() ) if ( isSelected() )
{ {
drawSelectionBoxes( painter ); drawSelectionBoxes( painter );

View File

@ -78,6 +78,20 @@ class CORE_EXPORT QgsComposerFrame: public QgsComposerItem
*/ */
void setHidePageIfEmpty( const bool hidePageIfEmpty ); void setHidePageIfEmpty( const bool hidePageIfEmpty );
/**Returns whether the background and frame border should be hidden if this frame is empty
* @returns true if background and border should be hidden if frame is empty
* @note added in QGIS 2.5
* @see setHideBackgroundIfEmpty
*/
bool hideBackgroundIfEmpty() const { return mHideBackgroundIfEmpty; }
/**Sets whether the background and frame border should be hidden if this frame is empty
* @param hideBackgroundIfEmpty set to true if background and border should be hidden if frame is empty
* @note added in QGIS 2.5
* @see hideBackgroundIfEmpty
*/
void setHideBackgroundIfEmpty( const bool hideBackgroundIfEmpty );
/**Returns whether the frame is empty /**Returns whether the frame is empty
* @returns true if frame is empty * @returns true if frame is empty
* @note added in QGIS 2.5 * @note added in QGIS 2.5
@ -92,6 +106,9 @@ class CORE_EXPORT QgsComposerFrame: public QgsComposerItem
/**if true, composition will not export page if this frame is empty*/ /**if true, composition will not export page if this frame is empty*/
bool mHidePageIfEmpty; bool mHidePageIfEmpty;
/**if true, background and outside frame will not be drawn if frame is empty*/
bool mHideBackgroundIfEmpty;
}; };
#endif // QGSCOMPOSERFRAME_H #endif // QGSCOMPOSERFRAME_H

View File

@ -45,9 +45,9 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>-312</y> <y>-340</y>
<width>392</width> <width>392</width>
<height>1104</height> <height>1132</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="mainLayout"> <layout class="QVBoxLayout" name="mainLayout">
@ -541,13 +541,6 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0" colspan="2">
<widget class="QPushButton" name="mAddFramePushButton">
<property name="text">
<string>Add Frame</string>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="mResizeModeLabel"> <widget class="QLabel" name="mResizeModeLabel">
<property name="text"> <property name="text">
@ -568,6 +561,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2">
<widget class="QPushButton" name="mAddFramePushButton">
<property name="text">
<string>Add Frame</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="mEmptyFrameCheckBox"> <widget class="QCheckBox" name="mEmptyFrameCheckBox">
<property name="text"> <property name="text">
@ -575,6 +575,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mHideEmptyBgCheckBox">
<property name="text">
<string>Don't draw background if frame is empty</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -45,9 +45,9 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>-10</y> <y>-40</y>
<width>391</width> <width>391</width>
<height>489</height> <height>517</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="mainLayout"> <layout class="QVBoxLayout" name="mainLayout">
@ -146,16 +146,6 @@
<string notr="true">composeritem</string> <string notr="true">composeritem</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="mResizeModeLabel">
<property name="text">
<string>Resize mode</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="mResizeModeComboBox"> <widget class="QComboBox" name="mResizeModeComboBox">
<property name="sizePolicy"> <property name="sizePolicy">
@ -166,6 +156,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="mEmptyFrameCheckBox">
<property name="text">
<string>Don't export page if frame is empty</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="2">
<widget class="QPushButton" name="mAddFramePushButton"> <widget class="QPushButton" name="mAddFramePushButton">
<property name="text"> <property name="text">
@ -173,10 +170,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="2"> <item row="0" column="0">
<widget class="QCheckBox" name="mEmptyFrameCheckBox"> <widget class="QLabel" name="mResizeModeLabel">
<property name="text"> <property name="text">
<string>Don't export page if frame is empty</string> <string>Resize mode</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mHideEmptyBgCheckBox">
<property name="text">
<string>Don't draw background if frame is empty</string>
</property> </property>
</widget> </widget>
</item> </item>