Skip to content

Commit a9c97ae

Browse files
committedSep 26, 2014
[composer] Add a checkbox to prevent drawing border and background for empty frame items
1 parent ce21425 commit a9c97ae

9 files changed

+125
-29
lines changed
 

‎python/core/composer/qgscomposerframe.sip

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ class QgsComposerFrame: QgsComposerItem
5555
* @see hidePageIfEmpty
5656
*/
5757
void setHidePageIfEmpty( const bool hidePageIfEmpty );
58+
59+
/**Returns whether the background and frame border should be hidden if this frame is empty
60+
* @returns true if background and border should be hidden if frame is empty
61+
* @note added in QGIS 2.5
62+
* @see setHideBackgroundIfEmpty
63+
*/
64+
bool hideBackgroundIfEmpty() const;
65+
66+
/**Sets whether the background and frame border should be hidden if this frame is empty
67+
* @param hideBackgroundIfEmpty set to true if background and border should be hidden if frame is empty
68+
* @note added in QGIS 2.5
69+
* @see hideBackgroundIfEmpty
70+
*/
71+
void setHideBackgroundIfEmpty( const bool hideBackgroundIfEmpty );
5872

5973
/**Returns whether the frame is empty
6074
* @returns true if frame is empty

‎src/app/composer/qgscomposerattributetablewidget.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ void QgsComposerAttributeTableWidget::updateGuiElements()
515515
mAddFramePushButton->setEnabled( mComposerTable->resizeMode() == QgsComposerMultiFrame::UseExistingFrames );
516516

517517
mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
518+
mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
518519

519520
toggleSourceControls();
520521

@@ -616,6 +617,7 @@ void QgsComposerAttributeTableWidget::blockAllSignals( bool b )
616617
mEmptyModeComboBox->blockSignals( b );
617618
mEmptyMessageLineEdit->blockSignals( b );
618619
mEmptyFrameCheckBox->blockSignals( b );
620+
mHideEmptyBgCheckBox->blockSignals( b );
619621
}
620622

621623
void QgsComposerAttributeTableWidget::setMaximumNumberOfFeatures( int n )
@@ -670,7 +672,6 @@ void QgsComposerAttributeTableWidget::on_mUniqueOnlyCheckBox_stateChanged( int s
670672
}
671673
}
672674

673-
674675
void QgsComposerAttributeTableWidget::on_mEmptyFrameCheckBox_toggled( bool checked )
675676
{
676677
if ( !mFrame )
@@ -683,6 +684,18 @@ void QgsComposerAttributeTableWidget::on_mEmptyFrameCheckBox_toggled( bool check
683684
mFrame->endCommand();
684685
}
685686

687+
void QgsComposerAttributeTableWidget::on_mHideEmptyBgCheckBox_toggled( bool checked )
688+
{
689+
if ( !mFrame )
690+
{
691+
return;
692+
}
693+
694+
mFrame->beginCommand( tr( "Hide background if empty toggled" ) );
695+
mFrame->setHideBackgroundIfEmpty( checked );
696+
mFrame->endCommand();
697+
}
698+
686699
void QgsComposerAttributeTableWidget::on_mIntersectAtlasCheckBox_stateChanged( int state )
687700
{
688701
if ( !mComposerTable )

‎src/app/composer/qgscomposerattributetablewidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
7575
void on_mIntersectAtlasCheckBox_stateChanged( int state );
7676
void on_mUniqueOnlyCheckBox_stateChanged( int state );
7777
void on_mEmptyFrameCheckBox_toggled( bool checked );
78+
void on_mHideEmptyBgCheckBox_toggled( bool checked );
7879

7980
/**Inserts a new maximum number of features into the spin box (without the spinbox emitting a signal)*/
8081
void setMaximumNumberOfFeatures( int n );
@@ -85,7 +86,6 @@ class QgsComposerAttributeTableWidget: public QgsComposerItemBaseWidget, private
8586
void atlasToggled();
8687

8788
void updateRelationsCombo();
88-
8989
};
9090

9191
#endif // QGSCOMPOSERATTRIBUTETABLEWIDGET_H

‎src/app/composer/qgscomposerhtmlwidget.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ void QgsComposerHtmlWidget::blockSignals( bool block )
101101
mRadioUrlSource->blockSignals( block );
102102
mEvaluateExpressionsCheckbox->blockSignals( block );
103103
mEmptyFrameCheckBox->blockSignals( block );
104+
mHideEmptyBgCheckBox->blockSignals( block );
104105
}
105106

106107
void QgsComposerHtmlWidget::on_mUrlLineEdit_editingFinished()
@@ -278,6 +279,18 @@ void QgsComposerHtmlWidget::on_mEmptyFrameCheckBox_toggled( bool checked )
278279
mFrame->endCommand();
279280
}
280281

282+
void QgsComposerHtmlWidget::on_mHideEmptyBgCheckBox_toggled( bool checked )
283+
{
284+
if ( !mFrame )
285+
{
286+
return;
287+
}
288+
289+
mFrame->beginCommand( tr( "Hide background if empty toggled" ) );
290+
mFrame->setHideBackgroundIfEmpty( checked );
291+
mFrame->endCommand();
292+
}
293+
281294
void QgsComposerHtmlWidget::on_mRadioManualSource_clicked( bool checked )
282295
{
283296
if ( !mHtml )
@@ -447,6 +460,7 @@ void QgsComposerHtmlWidget::setGuiElementValues()
447460
mStylesheetEditor->setText( mHtml->userStylesheet() );
448461

449462
mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
463+
mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
450464

451465
populateDataDefinedButtons();
452466

‎src/app/composer/qgscomposerhtmlwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ class QgsComposerHtmlWidget: public QgsComposerItemBaseWidget, private Ui::QgsCo
4848
void on_mReloadPushButton2_clicked();
4949
void on_mAddFramePushButton_clicked();
5050
void on_mEmptyFrameCheckBox_toggled( bool checked );
51+
void on_mHideEmptyBgCheckBox_toggled( bool checked );
5152

5253
/**Sets the GUI elements to the values of mHtmlItem*/
5354
void setGuiElementValues();
5455

5556
protected:
57+
5658
QgsComposerItem::DataDefinedProperty ddPropertyForWidget( QgsDataDefinedButton *widget );
5759

5860
protected slots:

‎src/core/composer/qgscomposerframe.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ QgsComposerFrame::QgsComposerFrame( QgsComposition* c, QgsComposerMultiFrame* mf
2121
: QgsComposerItem( x, y, width, height, c )
2222
, mMultiFrame( mf )
2323
, mHidePageIfEmpty( false )
24+
, mHideBackgroundIfEmpty( false )
2425
{
2526
//repaint frame when multiframe content changes
2627
connect( mf, SIGNAL( contentsChanged() ), this, SLOT( repaint() ) );
@@ -35,6 +36,7 @@ QgsComposerFrame::QgsComposerFrame()
3536
: QgsComposerItem( 0, 0, 0, 0, 0 )
3637
, mMultiFrame( 0 )
3738
, mHidePageIfEmpty( false )
39+
, mHideBackgroundIfEmpty( false )
3840
{
3941
}
4042

@@ -50,7 +52,7 @@ bool QgsComposerFrame::writeXML( QDomElement& elem, QDomDocument & doc ) const
5052
frameElem.setAttribute( "sectionWidth", QString::number( mSection.width() ) );
5153
frameElem.setAttribute( "sectionHeight", QString::number( mSection.height() ) );
5254
frameElem.setAttribute( "hidePageIfEmpty", mHidePageIfEmpty );
53-
55+
frameElem.setAttribute( "hideBackgroundIfEmpty", mHideBackgroundIfEmpty );
5456
elem.appendChild( frameElem );
5557

5658
return _writeXML( frameElem, doc );
@@ -64,6 +66,7 @@ bool QgsComposerFrame::readXML( const QDomElement& itemElem, const QDomDocument&
6466
double height = itemElem.attribute( "sectionHeight" ).toDouble();
6567
mSection = QRectF( x, y, width, height );
6668
mHidePageIfEmpty = itemElem.attribute( "hidePageIfEmpty", "0" ).toInt();
69+
mHideBackgroundIfEmpty = itemElem.attribute( "hideBackgroundIfEmpty", "0" ).toInt();
6770
QDomElement composerItem = itemElem.firstChildElement( "ComposerItem" );
6871
if ( composerItem.isNull() )
6972
{
@@ -77,6 +80,17 @@ void QgsComposerFrame::setHidePageIfEmpty( const bool hidePageIfEmpty )
7780
mHidePageIfEmpty = hidePageIfEmpty;
7881
}
7982

83+
void QgsComposerFrame::setHideBackgroundIfEmpty( const bool hideBackgroundIfEmpty )
84+
{
85+
if ( hideBackgroundIfEmpty == mHideBackgroundIfEmpty )
86+
{
87+
return;
88+
}
89+
90+
mHideBackgroundIfEmpty = hideBackgroundIfEmpty;
91+
update();
92+
}
93+
8094
bool QgsComposerFrame::isEmpty() const
8195
{
8296
if ( !mMultiFrame )
@@ -152,15 +166,23 @@ void QgsComposerFrame::paint( QPainter* painter, const QStyleOptionGraphicsItem*
152166
return;
153167
}
154168

155-
drawBackground( painter );
169+
bool empty = isEmpty();
170+
171+
if ( !empty || !mHideBackgroundIfEmpty )
172+
{
173+
drawBackground( painter );
174+
}
156175
if ( mMultiFrame )
157176
{
158177
//calculate index of frame
159178
int frameIndex = mMultiFrame->frameIndex( this );
160179
mMultiFrame->render( painter, mSection, frameIndex );
161180
}
162181

163-
drawFrame( painter );
182+
if ( !empty || !mHideBackgroundIfEmpty )
183+
{
184+
drawFrame( painter );
185+
}
164186
if ( isSelected() )
165187
{
166188
drawSelectionBoxes( painter );

‎src/core/composer/qgscomposerframe.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ class CORE_EXPORT QgsComposerFrame: public QgsComposerItem
7878
*/
7979
void setHidePageIfEmpty( const bool hidePageIfEmpty );
8080

81+
/**Returns whether the background and frame border should be hidden if this frame is empty
82+
* @returns true if background and border should be hidden if frame is empty
83+
* @note added in QGIS 2.5
84+
* @see setHideBackgroundIfEmpty
85+
*/
86+
bool hideBackgroundIfEmpty() const { return mHideBackgroundIfEmpty; }
87+
88+
/**Sets whether the background and frame border should be hidden if this frame is empty
89+
* @param hideBackgroundIfEmpty set to true if background and border should be hidden if frame is empty
90+
* @note added in QGIS 2.5
91+
* @see hideBackgroundIfEmpty
92+
*/
93+
void setHideBackgroundIfEmpty( const bool hideBackgroundIfEmpty );
94+
8195
/**Returns whether the frame is empty
8296
* @returns true if frame is empty
8397
* @note added in QGIS 2.5
@@ -92,6 +106,9 @@ class CORE_EXPORT QgsComposerFrame: public QgsComposerItem
92106

93107
/**if true, composition will not export page if this frame is empty*/
94108
bool mHidePageIfEmpty;
109+
/**if true, background and outside frame will not be drawn if frame is empty*/
110+
bool mHideBackgroundIfEmpty;
111+
95112
};
96113

97114
#endif // QGSCOMPOSERFRAME_H

‎src/ui/qgscomposerattributetablewidgetbase.ui

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
<property name="geometry">
4646
<rect>
4747
<x>0</x>
48-
<y>-312</y>
48+
<y>-340</y>
4949
<width>392</width>
50-
<height>1104</height>
50+
<height>1132</height>
5151
</rect>
5252
</property>
5353
<layout class="QVBoxLayout" name="mainLayout">
@@ -541,13 +541,6 @@
541541
<bool>false</bool>
542542
</property>
543543
<layout class="QGridLayout" name="gridLayout_3">
544-
<item row="1" column="0" colspan="2">
545-
<widget class="QPushButton" name="mAddFramePushButton">
546-
<property name="text">
547-
<string>Add Frame</string>
548-
</property>
549-
</widget>
550-
</item>
551544
<item row="0" column="0">
552545
<widget class="QLabel" name="mResizeModeLabel">
553546
<property name="text">
@@ -568,13 +561,27 @@
568561
</property>
569562
</widget>
570563
</item>
564+
<item row="1" column="0" colspan="2">
565+
<widget class="QPushButton" name="mAddFramePushButton">
566+
<property name="text">
567+
<string>Add Frame</string>
568+
</property>
569+
</widget>
570+
</item>
571571
<item row="2" column="0" colspan="2">
572572
<widget class="QCheckBox" name="mEmptyFrameCheckBox">
573573
<property name="text">
574574
<string>Don't export page if frame is empty</string>
575575
</property>
576576
</widget>
577577
</item>
578+
<item row="3" column="0" colspan="2">
579+
<widget class="QCheckBox" name="mHideEmptyBgCheckBox">
580+
<property name="text">
581+
<string>Don't draw background if frame is empty</string>
582+
</property>
583+
</widget>
584+
</item>
578585
</layout>
579586
</widget>
580587
</item>

‎src/ui/qgscomposerhtmlwidgetbase.ui

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
<property name="geometry">
4646
<rect>
4747
<x>0</x>
48-
<y>-10</y>
48+
<y>-40</y>
4949
<width>391</width>
50-
<height>489</height>
50+
<height>517</height>
5151
</rect>
5252
</property>
5353
<layout class="QVBoxLayout" name="mainLayout">
@@ -146,16 +146,6 @@
146146
<string notr="true">composeritem</string>
147147
</property>
148148
<layout class="QGridLayout" name="gridLayout">
149-
<item row="0" column="0">
150-
<widget class="QLabel" name="mResizeModeLabel">
151-
<property name="text">
152-
<string>Resize mode</string>
153-
</property>
154-
<property name="wordWrap">
155-
<bool>true</bool>
156-
</property>
157-
</widget>
158-
</item>
159149
<item row="0" column="1">
160150
<widget class="QComboBox" name="mResizeModeComboBox">
161151
<property name="sizePolicy">
@@ -166,17 +156,34 @@
166156
</property>
167157
</widget>
168158
</item>
159+
<item row="2" column="0" colspan="2">
160+
<widget class="QCheckBox" name="mEmptyFrameCheckBox">
161+
<property name="text">
162+
<string>Don't export page if frame is empty</string>
163+
</property>
164+
</widget>
165+
</item>
169166
<item row="1" column="0" colspan="2">
170167
<widget class="QPushButton" name="mAddFramePushButton">
171168
<property name="text">
172169
<string>Add Frame</string>
173170
</property>
174171
</widget>
175172
</item>
176-
<item row="2" column="0" colspan="2">
177-
<widget class="QCheckBox" name="mEmptyFrameCheckBox">
173+
<item row="0" column="0">
174+
<widget class="QLabel" name="mResizeModeLabel">
178175
<property name="text">
179-
<string>Don't export page if frame is empty</string>
176+
<string>Resize mode</string>
177+
</property>
178+
<property name="wordWrap">
179+
<bool>true</bool>
180+
</property>
181+
</widget>
182+
</item>
183+
<item row="3" column="0" colspan="2">
184+
<widget class="QCheckBox" name="mHideEmptyBgCheckBox">
185+
<property name="text">
186+
<string>Don't draw background if frame is empty</string>
180187
</property>
181188
</widget>
182189
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.