Skip to content

Commit cfc8303

Browse files
committed
[composer] Allow setting the join style for composer item frames
1 parent 040c551 commit cfc8303

File tree

6 files changed

+102
-12
lines changed

6 files changed

+102
-12
lines changed

python/core/composer/qgscomposeritem.sip

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,23 @@ class QgsComposerItem : QObject, QGraphicsRectItem
237237
*/
238238
virtual void setFrameOutlineWidth( double outlineWidth );
239239

240+
/** Returns the join style used for drawing the item's frame
241+
* @returns Join style for outline frame
242+
* @note introduced in 2.3
243+
* @see hasFrame
244+
* @see setFrameJoinStyle
245+
*/
246+
Qt::PenJoinStyle frameJoinStyle() const;
247+
248+
/** Sets join style used when drawing the item's frame
249+
* @param style Join style for outline frame
250+
* @returns nothing
251+
* @note introduced in 2.3
252+
* @see setFrameEnabled
253+
* @see frameJoinStyle
254+
*/
255+
void setFrameJoinStyle( Qt::PenJoinStyle style );
256+
240257
/** Returns the estimated amount the item's frame bleeds outside the item's
241258
* actual rectangle. For instance, if the item has a 2mm frame outline, then
242259
* 1mm of this frame is drawn outside the item's rect. In this case the

src/app/composer/qgscomposeritemwidget.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,19 @@ void QgsComposerItemWidget::on_mOutlineWidthSpinBox_valueChanged( double d )
200200
mItem->endCommand();
201201
}
202202

203+
void QgsComposerItemWidget::on_mFrameJoinStyleCombo_currentIndexChanged( int index )
204+
{
205+
Q_UNUSED( index );
206+
if ( !mItem )
207+
{
208+
return;
209+
}
210+
211+
mItem->beginCommand( tr( "Item frame join style" ) );
212+
mItem->setFrameJoinStyle( mFrameJoinStyleCombo->penJoinStyle() );
213+
mItem->endCommand();
214+
}
215+
203216
void QgsComposerItemWidget::on_mFrameGroupBox_toggled( bool state )
204217
{
205218
if ( !mItem )
@@ -339,6 +352,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
339352
mTransparencySlider->blockSignals( true );
340353
mTransparencySpnBx->blockSignals( true );
341354
mFrameColorButton->blockSignals( true );
355+
mFrameJoinStyleCombo->blockSignals( true );
342356
mBackgroundColorButton->blockSignals( true );
343357
mItemRotationSpinBox->blockSignals( true );
344358

@@ -349,6 +363,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
349363
mFrameColorButton->setColorDialogTitle( tr( "Select frame color" ) );
350364
mFrameColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
351365
mOutlineWidthSpinBox->setValue( mItem->pen().widthF() );
366+
mFrameJoinStyleCombo->setPenJoinStyle( mItem->frameJoinStyle() );
352367
mItemIdLineEdit->setText( mItem->id() );
353368
mFrameGroupBox->setChecked( mItem->hasFrame() );
354369
mBackgroundGroupBox->setChecked( mItem->hasBackground() );
@@ -359,6 +374,7 @@ void QgsComposerItemWidget::setValuesForGuiElements()
359374

360375
mBackgroundColorButton->blockSignals( false );
361376
mFrameColorButton->blockSignals( false );
377+
mFrameJoinStyleCombo->blockSignals( false );
362378
mOutlineWidthSpinBox->blockSignals( false );
363379
mFrameGroupBox->blockSignals( false );
364380
mBackgroundGroupBox->blockSignals( false );

src/app/composer/qgscomposeritemwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa
5555
// void on_mTransparencySpinBox_valueChanged( int value );
5656
void on_mOutlineWidthSpinBox_valueChanged( double d );
5757
void on_mFrameGroupBox_toggled( bool state );
58+
void on_mFrameJoinStyleCombo_currentIndexChanged( int index );
5859
void on_mBackgroundGroupBox_toggled( bool state );
5960
void on_mItemIdLineEdit_editingFinished();
6061

src/core/composer/qgscomposeritem.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue
5656
, mFrame( false )
5757
, mBackground( true )
5858
, mBackgroundColor( QColor( 255, 255, 255, 255 ) )
59+
, mFrameJoinStyle( Qt::MiterJoin )
5960
, mItemPositionLocked( false )
6061
, mLastValidViewScaleFactor( -1 )
6162
, mItemRotation( 0 )
@@ -79,6 +80,7 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
7980
, mFrame( false )
8081
, mBackground( true )
8182
, mBackgroundColor( QColor( 255, 255, 255, 255 ) )
83+
, mFrameJoinStyle( Qt::MiterJoin )
8284
, mItemPositionLocked( false )
8385
, mLastValidViewScaleFactor( -1 )
8486
, mItemRotation( 0 )
@@ -100,7 +102,7 @@ void QgsComposerItem::init( bool manageZValue )
100102
setBrush( QBrush( QColor( 255, 255, 255, 255 ) ) );
101103
QPen defaultPen( QColor( 0, 0, 0 ) );
102104
defaultPen.setWidthF( 0.3 );
103-
defaultPen.setJoinStyle( Qt::MiterJoin );
105+
defaultPen.setJoinStyle( mFrameJoinStyle );
104106
setPen( defaultPen );
105107
//let z-Value be managed by composition
106108
if ( mComposition && manageZValue )
@@ -175,6 +177,7 @@ bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) cons
175177
composerItemElem.setAttribute( "positionMode", QString::number(( int ) mLastUsedPositionMode ) );
176178
composerItemElem.setAttribute( "zValue", QString::number( zValue() ) );
177179
composerItemElem.setAttribute( "outlineWidth", QString::number( pen().widthF() ) );
180+
composerItemElem.setAttribute( "frameJoinStyle", QgsSymbolLayerV2Utils::encodePenJoinStyle( mFrameJoinStyle ) );
178181
composerItemElem.setAttribute( "itemRotation", QString::number( mItemRotation ) );
179182
composerItemElem.setAttribute( "uuid", mUuid );
180183
composerItemElem.setAttribute( "id", mId );
@@ -315,11 +318,13 @@ bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument&
315318
penGreen = frameColorElem.attribute( "green" ).toDouble( &greenOk );
316319
penBlue = frameColorElem.attribute( "blue" ).toDouble( &blueOk );
317320
penAlpha = frameColorElem.attribute( "alpha" ).toDouble( &alphaOk );
321+
mFrameJoinStyle = QgsSymbolLayerV2Utils::decodePenJoinStyle( itemElem.attribute( "frameJoinStyle", "miter" ) );
322+
318323
if ( redOk && greenOk && blueOk && alphaOk && widthOk )
319324
{
320325
QPen framePen( QColor( penRed, penGreen, penBlue, penAlpha ) );
321326
framePen.setWidthF( penWidth );
322-
framePen.setJoinStyle( Qt::MiterJoin );
327+
framePen.setJoinStyle( mFrameJoinStyle );
323328
setPen( framePen );
324329
}
325330
}
@@ -370,6 +375,21 @@ void QgsComposerItem::setFrameOutlineWidth( double outlineWidth )
370375
emit frameChanged();
371376
}
372377

378+
void QgsComposerItem::setFrameJoinStyle( Qt::PenJoinStyle style )
379+
{
380+
if ( mFrameJoinStyle == style )
381+
{
382+
//no change
383+
return;
384+
}
385+
mFrameJoinStyle = style;
386+
387+
QPen itemPen = pen();
388+
itemPen.setJoinStyle( mFrameJoinStyle );
389+
setPen( itemPen );
390+
emit frameChanged();
391+
}
392+
373393
double QgsComposerItem::estimatedFrameBleed() const
374394
{
375395
if ( !hasFrame() )

src/core/composer/qgscomposeritem.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,22 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
197197
*/
198198
virtual void setFrameOutlineWidth( double outlineWidth );
199199

200+
/** Returns the join style used for drawing the item's frame
201+
* @returns Join style for outline frame
202+
* @note introduced in 2.3
203+
* @see hasFrame
204+
* @see setFrameJoinStyle
205+
*/
206+
Qt::PenJoinStyle frameJoinStyle() const { return mFrameJoinStyle; }
207+
/** Sets join style used when drawing the item's frame
208+
* @param style Join style for outline frame
209+
* @returns nothing
210+
* @note introduced in 2.3
211+
* @see setFrameEnabled
212+
* @see frameJoinStyle
213+
*/
214+
void setFrameJoinStyle( Qt::PenJoinStyle style );
215+
200216
/** Returns the estimated amount the item's frame bleeds outside the item's
201217
* actual rectangle. For instance, if the item has a 2mm frame outline, then
202218
* 1mm of this frame is drawn outside the item's rect. In this case the
@@ -382,6 +398,8 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
382398
bool mBackground;
383399
/**Background color*/
384400
QColor mBackgroundColor;
401+
/**Frame join style*/
402+
Qt::PenJoinStyle mFrameJoinStyle;
385403

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

src/ui/qgscomposeritemwidgetbase.ui

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414
<string>Global Options</string>
1515
</property>
1616
<layout class="QVBoxLayout" name="verticalLayout_2">
17-
<property name="margin">
17+
<property name="leftMargin">
18+
<number>0</number>
19+
</property>
20+
<property name="topMargin">
21+
<number>0</number>
22+
</property>
23+
<property name="rightMargin">
24+
<number>0</number>
25+
</property>
26+
<property name="bottomMargin">
1827
<number>0</number>
1928
</property>
2029
<item>
@@ -264,12 +273,13 @@
264273
<bool>true</bool>
265274
</property>
266275
<layout class="QFormLayout" name="formLayout_4">
267-
<property name="fieldGrowthPolicy">
268-
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
269-
</property>
270-
<property name="labelAlignment">
271-
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
272-
</property>
276+
<item row="0" column="0" colspan="2">
277+
<widget class="QgsColorButton" name="mFrameColorButton">
278+
<property name="text">
279+
<string>Color...</string>
280+
</property>
281+
</widget>
282+
</item>
273283
<item row="1" column="0">
274284
<widget class="QLabel" name="mOutlineWidthLabel">
275285
<property name="text">
@@ -286,13 +296,16 @@
286296
<item row="1" column="1">
287297
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox"/>
288298
</item>
289-
<item row="0" column="0" colspan="2">
290-
<widget class="QgsColorButton" name="mFrameColorButton">
299+
<item row="2" column="0">
300+
<widget class="QLabel" name="label_8">
291301
<property name="text">
292-
<string>Color...</string>
302+
<string>Join style</string>
293303
</property>
294304
</widget>
295305
</item>
306+
<item row="2" column="1">
307+
<widget class="QgsPenJoinStyleComboBox" name="mFrameJoinStyleCombo"/>
308+
</item>
296309
</layout>
297310
</widget>
298311
</item>
@@ -449,6 +462,11 @@
449462
<header location="global">qgscollapsiblegroupbox.h</header>
450463
<container>1</container>
451464
</customwidget>
465+
<customwidget>
466+
<class>QgsPenJoinStyleComboBox</class>
467+
<extends>QComboBox</extends>
468+
<header>qgspenstylecombobox.h</header>
469+
</customwidget>
452470
</customwidgets>
453471
<resources/>
454472
<connections/>

0 commit comments

Comments
 (0)