Skip to content

Commit ec0d944

Browse files
committedJan 29, 2013
[feature] added draw background checkbox in composer items
(this allow to workaround the non-opaque background bug with atlas and is more consistent with the frame settings) )
1 parent 94491b8 commit ec0d944

File tree

5 files changed

+159
-69
lines changed

5 files changed

+159
-69
lines changed
 

‎src/app/composer/qgscomposeritemwidget.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,40 @@ void QgsComposerItemWidget::on_mFrameCheckBox_stateChanged( int state )
150150
mItem->beginCommand( tr( "Item frame toggled" ) );
151151
if ( state == Qt::Checked )
152152
{
153+
mFrameBox->setEnabled( true );
153154
mItem->setFrameEnabled( true );
154155
}
155156
else
156157
{
158+
mFrameBox->setEnabled( false );
157159
mItem->setFrameEnabled( false );
158160
}
159161
mItem->update();
160162
mItem->endCommand();
161163
}
162164

165+
void QgsComposerItemWidget::on_mBackgroundCheckBox_stateChanged( int state )
166+
{
167+
if ( !mItem )
168+
{
169+
return;
170+
}
171+
172+
mItem->beginCommand( tr( "Item background toggled" ) );
173+
if ( state == Qt::Checked )
174+
{
175+
mBackgroundBox->setEnabled( true );
176+
mItem->setBackgroundEnabled( true );
177+
}
178+
else
179+
{
180+
mBackgroundBox->setEnabled( false );
181+
mItem->setBackgroundEnabled( false );
182+
}
183+
mItem->update();
184+
mItem->endCommand();
185+
}
186+
163187
void QgsComposerItemWidget::setValuesForGuiElements()
164188
{
165189
if ( !mItem )

‎src/app/composer/qgscomposeritemwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa
3838
void on_mOpacitySpinBox_valueChanged( int value );
3939
void on_mOutlineWidthSpinBox_valueChanged( double d );
4040
void on_mFrameCheckBox_stateChanged( int state );
41+
void on_mBackgroundCheckBox_stateChanged( int state );
4142
void on_mPositionButton_clicked();
4243
void on_mItemIdLineEdit_textChanged( const QString& text );
4344

‎src/core/composer/qgscomposeritem.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue
4646
, mHAlignSnapItem( 0 )
4747
, mVAlignSnapItem( 0 )
4848
, mFrame( false )
49+
, mBackground( true )
4950
, mItemPositionLocked( false )
5051
, mLastValidViewScaleFactor( -1 )
5152
, mRotation( 0 )
@@ -61,6 +62,7 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
6162
, mHAlignSnapItem( 0 )
6263
, mVAlignSnapItem( 0 )
6364
, mFrame( false )
65+
, mBackground( true )
6466
, mItemPositionLocked( false )
6567
, mLastValidViewScaleFactor( -1 )
6668
, mRotation( 0 )
@@ -130,6 +132,16 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
130132
composerItemElem.setAttribute( "frame", "false" );
131133
}
132134

135+
//frame
136+
if ( mBackground )
137+
{
138+
composerItemElem.setAttribute( "background", "true" );
139+
}
140+
else
141+
{
142+
composerItemElem.setAttribute( "background", "false" );
143+
}
144+
133145
//scene rect
134146
composerItemElem.setAttribute( "x", QString::number( transform().dx() ) );
135147
composerItemElem.setAttribute( "y", QString::number( transform().dy() ) );
@@ -200,6 +212,17 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
200212
mFrame = false;
201213
}
202214

215+
//frame
216+
QString background = itemElem.attribute( "background" );
217+
if ( background.compare( "true", Qt::CaseInsensitive ) == 0 )
218+
{
219+
mBackground = true;
220+
}
221+
else
222+
{
223+
mBackground = false;
224+
}
225+
203226
//position lock for mouse moves/resizes
204227
QString positionLock = itemElem.attribute( "positionLock" );
205228
if ( positionLock.compare( "true", Qt::CaseInsensitive ) == 0 )
@@ -799,9 +822,9 @@ void QgsComposerItem::setSceneRect( const QRectF& rectangle )
799822

800823
void QgsComposerItem::drawBackground( QPainter* p )
801824
{
802-
if ( p )
825+
if ( mBackground && p )
803826
{
804-
p->setBrush( brush() );
827+
p->setBrush( brush() );//this causes a problem in atlas generation
805828
p->setPen( Qt::NoPen );
806829
p->setRenderHint( QPainter::Antialiasing, true );
807830
p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );

‎src/core/composer/qgscomposeritem.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,22 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
175175
*/
176176
void setFrameEnabled( bool drawFrame ) {mFrame = drawFrame;}
177177

178+
179+
/** Whether this item has a Background or not.
180+
* @returns true if there is a Background around this item, otherwise false.
181+
* @note introduced since 2.0
182+
* @see hasBackground
183+
*/
184+
bool hasBackground() const {return mBackground;}
185+
186+
/** Set whether this item has a Background drawn around it or not.
187+
* @param drawBackground draw Background
188+
* @returns nothing
189+
* @note introduced in 2.0
190+
* @see hasBackground
191+
*/
192+
void setBackgroundEnabled( bool drawBackground ) {mBackground = drawBackground;}
193+
178194
/**Composite operations for item groups do nothing per default*/
179195
virtual void addItem( QgsComposerItem* item ) { Q_UNUSED( item ); }
180196
virtual void removeItems() {}
@@ -271,6 +287,8 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
271287

272288
/**True if item fram needs to be painted*/
273289
bool mFrame;
290+
/**True if item background needs to be painted*/
291+
bool mBackground;
274292

275293
/**True if item position and size cannot be changed with mouse move
276294
@note: this member was added in version 1.2*/

‎src/ui/qgscomposeritemwidgetbase.ui

Lines changed: 91 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,103 +6,120 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>235</width>
10-
<height>277</height>
9+
<width>393</width>
10+
<height>391</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
16-
<layout class="QGridLayout" name="gridLayout">
17-
<item row="0" column="0" colspan="3">
18-
<widget class="QPushButton" name="mFrameColorButton">
16+
<layout class="QFormLayout" name="formLayout_2">
17+
<item row="1" column="0">
18+
<widget class="QCheckBox" name="mFrameCheckBox">
1919
<property name="text">
20-
<string>Frame color...</string>
20+
<string>Show frame</string>
2121
</property>
2222
</widget>
2323
</item>
24-
<item row="1" column="0" colspan="3">
25-
<widget class="QPushButton" name="mBackgroundColorButton">
26-
<property name="text">
27-
<string>Background color...</string>
24+
<item row="2" column="0" colspan="2">
25+
<widget class="QGroupBox" name="mFrameBox">
26+
<property name="title">
27+
<string>Frame settings</string>
2828
</property>
29+
<layout class="QGridLayout" name="gridLayout_2">
30+
<item row="0" column="0" colspan="2">
31+
<widget class="QPushButton" name="mFrameColorButton">
32+
<property name="text">
33+
<string>Frame color...</string>
34+
</property>
35+
</widget>
36+
</item>
37+
<item row="1" column="0">
38+
<widget class="QLabel" name="mOutlineWidthLabel">
39+
<property name="text">
40+
<string>Thickness</string>
41+
</property>
42+
<property name="wordWrap">
43+
<bool>true</bool>
44+
</property>
45+
<property name="buddy">
46+
<cstring>mOutlineWidthSpinBox</cstring>
47+
</property>
48+
</widget>
49+
</item>
50+
<item row="1" column="1">
51+
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox"/>
52+
</item>
53+
</layout>
2954
</widget>
3055
</item>
31-
<item row="2" column="0" colspan="3">
32-
<layout class="QHBoxLayout" name="horizontalLayout">
33-
<item>
34-
<widget class="QLabel" name="mOpacityLabel">
35-
<property name="text">
36-
<string>Opacity</string>
37-
</property>
38-
<property name="wordWrap">
39-
<bool>true</bool>
40-
</property>
41-
<property name="buddy">
42-
<cstring>mOpacitySlider</cstring>
43-
</property>
44-
</widget>
45-
</item>
46-
<item>
47-
<widget class="QSlider" name="mOpacitySlider">
48-
<property name="maximum">
49-
<number>255</number>
50-
</property>
51-
<property name="orientation">
52-
<enum>Qt::Horizontal</enum>
53-
</property>
54-
</widget>
55-
</item>
56-
<item>
57-
<widget class="QSpinBox" name="mOpacitySpinBox">
58-
<property name="maximum">
59-
<number>255</number>
60-
</property>
61-
</widget>
62-
</item>
63-
</layout>
64-
</item>
6556
<item row="3" column="0">
66-
<widget class="QLabel" name="mOutlineWidthLabel">
57+
<widget class="QCheckBox" name="mBackgroundCheckBox">
6758
<property name="text">
68-
<string>Outline width</string>
69-
</property>
70-
<property name="wordWrap">
71-
<bool>true</bool>
72-
</property>
73-
<property name="buddy">
74-
<cstring>mOutlineWidthSpinBox</cstring>
59+
<string>Show background</string>
7560
</property>
7661
</widget>
7762
</item>
78-
<item row="3" column="2">
79-
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox"/>
80-
</item>
81-
<item row="4" column="0" colspan="3">
82-
<widget class="QPushButton" name="mPositionButton">
83-
<property name="text">
84-
<string>Position and size...</string>
63+
<item row="4" column="0" colspan="2">
64+
<widget class="QGroupBox" name="mBackgroundBox">
65+
<property name="title">
66+
<string>Background settings</string>
8567
</property>
68+
<layout class="QGridLayout" name="gridLayout">
69+
<item row="0" column="0" colspan="3">
70+
<widget class="QPushButton" name="mBackgroundColorButton">
71+
<property name="text">
72+
<string>Background color...</string>
73+
</property>
74+
</widget>
75+
</item>
76+
<item row="1" column="0">
77+
<widget class="QLabel" name="mOpacityLabel">
78+
<property name="text">
79+
<string>Opacity</string>
80+
</property>
81+
<property name="wordWrap">
82+
<bool>true</bool>
83+
</property>
84+
<property name="buddy">
85+
<cstring>mOpacitySlider</cstring>
86+
</property>
87+
</widget>
88+
</item>
89+
<item row="1" column="1">
90+
<widget class="QSlider" name="mOpacitySlider">
91+
<property name="maximum">
92+
<number>255</number>
93+
</property>
94+
<property name="orientation">
95+
<enum>Qt::Horizontal</enum>
96+
</property>
97+
</widget>
98+
</item>
99+
<item row="1" column="2">
100+
<widget class="QSpinBox" name="mOpacitySpinBox">
101+
<property name="maximum">
102+
<number>255</number>
103+
</property>
104+
</widget>
105+
</item>
106+
</layout>
86107
</widget>
87108
</item>
88109
<item row="5" column="0" colspan="2">
89-
<widget class="QCheckBox" name="mFrameCheckBox">
90-
<property name="text">
91-
<string>Show frame</string>
92-
</property>
93-
</widget>
110+
<layout class="QHBoxLayout" name="horizontalLayout"/>
94111
</item>
95-
<item row="6" column="0">
112+
<item row="7" column="0">
96113
<widget class="QLabel" name="mIdLabel">
97114
<property name="text">
98115
<string>Item ID</string>
99116
</property>
100117
</widget>
101118
</item>
102-
<item row="6" column="1" colspan="2">
119+
<item row="7" column="1">
103120
<widget class="QLineEdit" name="mItemIdLineEdit"/>
104121
</item>
105-
<item row="7" column="0" colspan="2">
122+
<item row="8" column="0" colspan="2">
106123
<spacer name="verticalSpacer">
107124
<property name="orientation">
108125
<enum>Qt::Vertical</enum>
@@ -115,6 +132,13 @@
115132
</property>
116133
</spacer>
117134
</item>
135+
<item row="0" column="0" colspan="2">
136+
<widget class="QPushButton" name="mPositionButton">
137+
<property name="text">
138+
<string>Position and size...</string>
139+
</property>
140+
</widget>
141+
</item>
118142
</layout>
119143
</widget>
120144
<resources/>

0 commit comments

Comments
 (0)
Please sign in to comment.