Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[composer] Add a checkbox to prevent drawing border and background fo…
…r empty frame items
  • Loading branch information
nyalldawson committed Sep 26, 2014
1 parent ce21425 commit a9c97ae
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 29 deletions.
14 changes: 14 additions & 0 deletions python/core/composer/qgscomposerframe.sip
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/app/composer/qgscomposerattributetablewidget.cpp
Expand Up @@ -515,6 +515,7 @@ void QgsComposerAttributeTableWidget::updateGuiElements()
mAddFramePushButton->setEnabled( mComposerTable->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );

mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );

toggleSourceControls();

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -670,7 +672,6 @@ void QgsComposerAttributeTableWidget::on_mUniqueOnlyCheckBox_stateChanged( int s
}
}


void QgsComposerAttributeTableWidget::on_mEmptyFrameCheckBox_toggled( bool checked )
{
if ( !mFrame )
Expand All @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposerattributetablewidget.h
Expand Up @@ -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 );
Expand All @@ -85,7 +86,6 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
void atlasToggled();

void updateRelationsCombo();

};

#endif // QGSCOMPOSERATTRIBUTETABLEWIDGET_H
14 changes: 14 additions & 0 deletions src/app/composer/qgscomposerhtmlwidget.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -447,6 +460,7 @@ void QgsComposerHtmlWidget::setGuiElementValues()
mStylesheetEditor->setText( mHtml->userStylesheet() );

mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );

populateDataDefinedButtons();

Expand Down
2 changes: 2 additions & 0 deletions src/app/composer/qgscomposerhtmlwidget.h
Expand Up @@ -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:
Expand Down
28 changes: 25 additions & 3 deletions src/core/composer/qgscomposerframe.cpp
Expand Up @@ -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() ) );
Expand All @@ -35,6 +36,7 @@ QgsComposerFrame::QgsComposerFrame()
: QgsComposerItem( 0, 0, 0, 0, 0 )
, mMultiFrame( 0 )
, mHidePageIfEmpty( false )
, mHideBackgroundIfEmpty( false )
{
}

Expand All @@ -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 );
Expand All @@ -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() )
{
Expand All @@ -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 )
Expand Down Expand Up @@ -152,15 +166,23 @@ void QgsComposerFrame::paint( QPainter* painter, const QStyleOptionGraphicsItem*
return;
}

drawBackground( painter );
bool empty = isEmpty();

if ( !empty || !mHideBackgroundIfEmpty )
{
drawBackground( painter );
}
if ( mMultiFrame )
{
//calculate index of frame
int frameIndex = mMultiFrame->frameIndex( this );
mMultiFrame->render( painter, mSection, frameIndex );
}

drawFrame( painter );
if ( !empty || !mHideBackgroundIfEmpty )
{
drawFrame( painter );
}
if ( isSelected() )
{
drawSelectionBoxes( painter );
Expand Down
17 changes: 17 additions & 0 deletions src/core/composer/qgscomposerframe.h
Expand Up @@ -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
Expand All @@ -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
25 changes: 16 additions & 9 deletions src/ui/qgscomposerattributetablewidgetbase.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand All @@ -568,13 +561,27 @@
</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">
<string>Don't export page if frame is empty</string>
</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>
Expand Down
37 changes: 22 additions & 15 deletions src/ui/qgscomposerhtmlwidgetbase.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand All @@ -166,17 +156,34 @@
</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">
<string>Add Frame</string>
</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>
Expand Down

0 comments on commit a9c97ae

Please sign in to comment.