[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

@ -55,6 +55,20 @@ class QgsComposerFrame: QgsComposerItem
* @see 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 true if frame is empty

View File

@ -515,6 +515,7 @@ void QgsComposerAttributeTableWidget::updateGuiElements()
mAddFramePushButton->setEnabled( mComposerTable->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );
mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
toggleSourceControls();
@ -616,6 +617,7 @@ void QgsComposerAttributeTableWidget::blockAllSignals( bool b )
mEmptyModeComboBox->blockSignals( b );
mEmptyMessageLineEdit->blockSignals( b );
mEmptyFrameCheckBox->blockSignals( b );
mHideEmptyBgCheckBox->blockSignals( b );
}
void QgsComposerAttributeTableWidget::setMaximumNumberOfFeatures( int n )
@ -670,7 +672,6 @@ void QgsComposerAttributeTableWidget::on_mUniqueOnlyCheckBox_stateChanged( int s
}
}
void QgsComposerAttributeTableWidget::on_mEmptyFrameCheckBox_toggled( bool checked )
{
if ( !mFrame )
@ -683,6 +684,18 @@ void QgsComposerAttributeTableWidget::on_mEmptyFrameCheckBox_toggled( bool check
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 )
{
if ( !mComposerTable )

View File

@ -75,6 +75,7 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
void on_mIntersectAtlasCheckBox_stateChanged( int state );
void on_mUniqueOnlyCheckBox_stateChanged( int state );
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)*/
void setMaximumNumberOfFeatures( int n );
@ -85,7 +86,6 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
void atlasToggled();
void updateRelationsCombo();
};
#endif // QGSCOMPOSERATTRIBUTETABLEWIDGET_H

View File

@ -101,6 +101,7 @@ void QgsComposerHtmlWidget::blockSignals( bool block )
mRadioUrlSource->blockSignals( block );
mEvaluateExpressionsCheckbox->blockSignals( block );
mEmptyFrameCheckBox->blockSignals( block );
mHideEmptyBgCheckBox->blockSignals( block );
}
void QgsComposerHtmlWidget::on_mUrlLineEdit_editingFinished()
@ -278,6 +279,18 @@ void QgsComposerHtmlWidget::on_mEmptyFrameCheckBox_toggled( bool checked )
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 )
{
if ( !mHtml )
@ -447,6 +460,7 @@ void QgsComposerHtmlWidget::setGuiElementValues()
mStylesheetEditor->setText( mHtml->userStylesheet() );
mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
populateDataDefinedButtons();

View File

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

View File

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

View File

@ -78,6 +78,20 @@ class CORE_EXPORT QgsComposerFrame: public QgsComposerItem
*/
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 true if frame is empty
* @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*/
bool mHidePageIfEmpty;
/**if true, background and outside frame will not be drawn if frame is empty*/
bool mHideBackgroundIfEmpty;
};
#endif // QGSCOMPOSERFRAME_H

View File

@ -45,9 +45,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-312</y>
<y>-340</y>
<width>392</width>
<height>1104</height>
<height>1132</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
@ -541,13 +541,6 @@
<bool>false</bool>
</property>
<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">
<widget class="QLabel" name="mResizeModeLabel">
<property name="text">
@ -568,6 +561,13 @@
</property>
</widget>
</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">
<widget class="QCheckBox" name="mEmptyFrameCheckBox">
<property name="text">
@ -575,6 +575,13 @@
</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>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -45,9 +45,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-10</y>
<y>-40</y>
<width>391</width>
<height>489</height>
<height>517</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
@ -146,16 +146,6 @@
<string notr="true">composeritem</string>
</property>
<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">
<widget class="QComboBox" name="mResizeModeComboBox">
<property name="sizePolicy">
@ -166,6 +156,13 @@
</property>
</widget>
</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">
<widget class="QPushButton" name="mAddFramePushButton">
<property name="text">
@ -173,10 +170,20 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="mEmptyFrameCheckBox">
<item row="0" column="0">
<widget class="QLabel" name="mResizeModeLabel">
<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>
</widget>
</item>