Skip to content

Commit fac7887

Browse files
committedJan 30, 2017
[FEATURE] Annotations can be styled using fill symbol styles (fix #10552)
This changes the rendering of annotation frames to use QGIS' symbology engine, which means that all the existing fill styles can now be used to style annotation frames. Also paint effects & data defined symbol parameters. Whee!
1 parent a94ca70 commit fac7887

File tree

18 files changed

+182
-235
lines changed

18 files changed

+182
-235
lines changed
 

‎python/core/annotations/qgsannotation.sip

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,8 @@ class QgsAnnotation : QObject
3131
void setContentsMargin( const QgsMargins& margins );
3232
QgsMargins contentsMargin() const;
3333

34-
void setFrameBorderWidth( double width );
35-
double frameBorderWidth() const;
36-
37-
void setFrameColor( const QColor& color );
38-
QColor frameColor() const;
39-
40-
void setFrameBackgroundColor( const QColor& color );
41-
QColor frameBackgroundColor() const;
34+
void setFillSymbol( QgsFillSymbol* symbol /Transfer/ );
35+
QgsFillSymbol* fillSymbol() const;
4236

4337
void render( QgsRenderContext& context ) const;
4438

‎src/app/qgsannotationwidget.cpp

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,6 @@ QgsAnnotationWidget::QgsAnnotationWidget( QgsMapCanvasAnnotationItem* item, QWid
4646
{
4747
mMapPositionFixedCheckBox->setCheckState( Qt::Unchecked );
4848
}
49-
mFrameWidthSpinBox->setValue( annotation->frameBorderWidth() );
50-
mFrameColorButton->setColor( annotation->frameColor() );
51-
mFrameColorButton->setColorDialogTitle( tr( "Select frame color" ) );
52-
mFrameColorButton->setAllowAlpha( true );
53-
mFrameColorButton->setContext( QStringLiteral( "symbology" ) );
54-
mFrameColorButton->setNoColorString( tr( "Transparent frame" ) );
55-
mFrameColorButton->setShowNoColor( true );
56-
mBackgroundColorButton->setColor( annotation->frameBackgroundColor() );
57-
mBackgroundColorButton->setColorDialogTitle( tr( "Select background color" ) );
58-
mBackgroundColorButton->setAllowAlpha( true );
59-
mBackgroundColorButton->setContext( QStringLiteral( "symbology" ) );
60-
mBackgroundColorButton->setNoColorString( tr( "Transparent" ) );
61-
mBackgroundColorButton->setShowNoColor( true );
6249

6350
whileBlocking( mSpinTopMargin )->setValue( annotation->contentsMargin().top() );
6451
whileBlocking( mSpinLeftMargin )->setValue( annotation->contentsMargin().left() );
@@ -67,14 +54,18 @@ QgsAnnotationWidget::QgsAnnotationWidget( QgsMapCanvasAnnotationItem* item, QWid
6754

6855
mLayerComboBox->setLayer( annotation->mapLayer() );
6956

70-
connect( mBackgroundColorButton, &QgsColorButton::colorChanged, this, &QgsAnnotationWidget::backgroundColorChanged );
71-
7257
const QgsMarkerSymbol* symbol = annotation->markerSymbol();
7358
if ( symbol )
7459
{
7560
mMarkerSymbol.reset( symbol->clone() );
7661
updateCenterIcon();
7762
}
63+
const QgsFillSymbol* fill = annotation->fillSymbol();
64+
if ( fill )
65+
{
66+
mFillSymbol.reset( fill->clone() );
67+
updateFillIcon();
68+
}
7869

7970
blockAllSignals( false );
8071
}
@@ -92,9 +83,7 @@ void QgsAnnotationWidget::apply()
9283
if ( annotation )
9384
{
9485
annotation->setHasFixedMapPosition( mMapPositionFixedCheckBox->checkState() == Qt::Checked );
95-
annotation->setFrameBorderWidth( mFrameWidthSpinBox->value() );
96-
annotation->setFrameColor( mFrameColorButton->color() );
97-
annotation->setFrameBackgroundColor( mBackgroundColorButton->color() );
86+
annotation->setFillSymbol( mFillSymbol->clone() );
9887
annotation->setMarkerSymbol( mMarkerSymbol->clone() );
9988
annotation->setMapLayer( mLayerComboBox->currentLayer() );
10089
annotation->setContentsMargin( QgsMargins( mSpinLeftMargin->value(),
@@ -110,8 +99,6 @@ void QgsAnnotationWidget::blockAllSignals( bool block )
11099
{
111100
mMapPositionFixedCheckBox->blockSignals( block );
112101
mMapMarkerButton->blockSignals( block );
113-
mFrameWidthSpinBox->blockSignals( block );
114-
mFrameColorButton->blockSignals( block );
115102
mLayerComboBox->blockSignals( block );
116103
}
117104

@@ -134,6 +121,26 @@ void QgsAnnotationWidget::on_mMapMarkerButton_clicked()
134121
}
135122
}
136123

124+
void QgsAnnotationWidget::on_mFrameStyleButton_clicked()
125+
{
126+
if ( !mFillSymbol )
127+
{
128+
return;
129+
}
130+
QgsFillSymbol* fillSymbol = mFillSymbol->clone();
131+
QgsSymbolSelectorDialog dlg( fillSymbol, QgsStyle::defaultStyle(), nullptr, this );
132+
if ( dlg.exec() == QDialog::Rejected )
133+
{
134+
delete fillSymbol;
135+
}
136+
else
137+
{
138+
mFillSymbol.reset( fillSymbol );
139+
updateFillIcon();
140+
backgroundColorChanged( fillSymbol->color() );
141+
}
142+
}
143+
137144
void QgsAnnotationWidget::updateCenterIcon()
138145
{
139146
if ( !mMarkerSymbol )
@@ -144,3 +151,13 @@ void QgsAnnotationWidget::updateCenterIcon()
144151
mMapMarkerButton->setIcon( icon );
145152
}
146153

154+
void QgsAnnotationWidget::updateFillIcon()
155+
{
156+
if ( !mFillSymbol )
157+
{
158+
return;
159+
}
160+
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mFillSymbol.data(), mFrameStyleButton->iconSize() );
161+
mFrameStyleButton->setIcon( icon );
162+
}
163+

‎src/app/qgsannotationwidget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
class QgsMapCanvasAnnotationItem;
2525
class QgsMarkerSymbol;
26+
class QgsFillSymbol;
2627

2728
/** A configuration widget to configure the annotation item properties. Usually embedded by QgsAnnotation
2829
subclass configuration dialogs*/
@@ -42,13 +43,16 @@ class APP_EXPORT QgsAnnotationWidget: public QWidget, private Ui::QgsAnnotationW
4243

4344
private slots:
4445
void on_mMapMarkerButton_clicked();
46+
void on_mFrameStyleButton_clicked();
4547

4648
private:
4749
QgsMapCanvasAnnotationItem* mItem = nullptr;
4850
QScopedPointer< QgsMarkerSymbol > mMarkerSymbol;
51+
QScopedPointer< QgsFillSymbol > mFillSymbol;
4952

5053
void blockAllSignals( bool block );
5154
void updateCenterIcon();
55+
void updateFillIcon();
5256
};
5357

5458
#endif // QGSANNOTATIONWIDGET_H

‎src/app/qgstextannotationdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ QgsTextAnnotationDialog::QgsTextAnnotationDialog( QgsMapCanvasAnnotationItem* it
6060

6161
void QgsTextAnnotationDialog::showEvent( QShowEvent* )
6262
{
63-
backgroundColorChanged( mItem && mItem->annotation() ? mItem->annotation()->frameBackgroundColor() : Qt::white );
63+
backgroundColorChanged( mItem && mItem->annotation() && mItem->annotation()->fillSymbol() ? mItem->annotation()->fillSymbol()->color() : Qt::white );
6464
}
6565

6666
void QgsTextAnnotationDialog::on_mButtonBox_clicked( QAbstractButton *button )

‎src/core/annotations/qgsannotation.cpp

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ QgsAnnotation::QgsAnnotation( QObject* parent )
2626
: QObject( parent )
2727
, mMarkerSymbol( new QgsMarkerSymbol() )
2828
{
29-
29+
QgsStringMap props;
30+
props.insert( QStringLiteral( "color" ), QStringLiteral( "white" ) );
31+
props.insert( QStringLiteral( "style" ), QStringLiteral( "solid" ) );
32+
props.insert( QStringLiteral( "style_border" ), QStringLiteral( "solid" ) );
33+
props.insert( QStringLiteral( "color_border" ), QStringLiteral( "black" ) );
34+
props.insert( QStringLiteral( "width_border" ), QStringLiteral( "0.3" ) );
35+
props.insert( QStringLiteral( "joinstyle" ), QStringLiteral( "miter" ) );
36+
mFillSymbol.reset( QgsFillSymbol::createSimple( props ) );
3037
}
3138

3239
void QgsAnnotation::setVisible( bool visible )
@@ -89,21 +96,9 @@ void QgsAnnotation::setContentsMargin( const QgsMargins& margins )
8996
emit appearanceChanged();
9097
}
9198

92-
void QgsAnnotation::setFrameBorderWidth( double width )
99+
void QgsAnnotation::setFillSymbol( QgsFillSymbol* symbol )
93100
{
94-
mFrameBorderWidth = width;
95-
emit appearanceChanged();
96-
}
97-
98-
void QgsAnnotation::setFrameColor( const QColor& c )
99-
{
100-
mFrameColor = c;
101-
emit appearanceChanged();
102-
}
103-
104-
void QgsAnnotation::setFrameBackgroundColor( const QColor& c )
105-
{
106-
mFrameBackgroundColor = c;
101+
mFillSymbol.reset( symbol );
107102
emit appearanceChanged();
108103
}
109104

@@ -263,17 +258,13 @@ QPointF QgsAnnotation::pointOnLineWithDistance( QPointF startPoint, QPointF dire
263258

264259
void QgsAnnotation::drawFrame( QgsRenderContext& context ) const
265260
{
266-
QPen framePen( mFrameColor );
267-
framePen.setWidthF( context.convertToPainterUnits( mFrameBorderWidth, QgsUnitTypes::RenderPixels ) );
268-
269-
QPainter* p = context.painter();
261+
if ( !mFillSymbol )
262+
return;
270263

271-
p->setPen( framePen );
272-
QBrush frameBrush( mFrameBackgroundColor );
273-
p->setBrush( frameBrush );
274-
p->setRenderHint( QPainter::Antialiasing, context.flags() & QgsRenderContext::Antialiasing );
264+
context.painter()->setRenderHint( QPainter::Antialiasing, context.flags() & QgsRenderContext::Antialiasing );
275265

276266
QPolygonF poly;
267+
QList<QPolygonF> rings; //empty list
277268
for ( int i = 0; i < 4; ++i )
278269
{
279270
QLineF currentSegment = segment( i );
@@ -286,7 +277,10 @@ void QgsAnnotation::drawFrame( QgsRenderContext& context ) const
286277
}
287278
poly << currentSegment.p2();
288279
}
289-
p->drawPolygon( poly );
280+
281+
mFillSymbol->startRender( context );
282+
mFillSymbol->renderPolygon( poly, &rings, nullptr, context );
283+
mFillSymbol->stopRender( context );
290284
}
291285

292286
void QgsAnnotation::drawMarkerSymbol( QgsRenderContext& context ) const
@@ -322,12 +316,7 @@ void QgsAnnotation::_writeXml( QDomElement& itemElem, QDomDocument& doc ) const
322316
annotationElem.setAttribute( QStringLiteral( "frameHeight" ), qgsDoubleToString( mFrameSize.height() ) );
323317
annotationElem.setAttribute( QStringLiteral( "canvasPosX" ), qgsDoubleToString( mRelativePosition.x() ) );
324318
annotationElem.setAttribute( QStringLiteral( "canvasPosY" ), qgsDoubleToString( mRelativePosition.y() ) );
325-
annotationElem.setAttribute( QStringLiteral( "frameBorderWidth" ), qgsDoubleToString( mFrameBorderWidth ) );
326319
annotationElem.setAttribute( QStringLiteral( "contentsMargin" ), mContentsMargins.toString() );
327-
annotationElem.setAttribute( QStringLiteral( "frameColor" ), mFrameColor.name() );
328-
annotationElem.setAttribute( QStringLiteral( "frameColorAlpha" ), mFrameColor.alpha() );
329-
annotationElem.setAttribute( QStringLiteral( "frameBackgroundColor" ), mFrameBackgroundColor.name() );
330-
annotationElem.setAttribute( QStringLiteral( "frameBackgroundColorAlpha" ), mFrameBackgroundColor.alpha() );
331320
annotationElem.setAttribute( QStringLiteral( "visible" ), isVisible() );
332321
if ( mMapLayer )
333322
{
@@ -341,6 +330,16 @@ void QgsAnnotation::_writeXml( QDomElement& itemElem, QDomDocument& doc ) const
341330
annotationElem.appendChild( symbolElem );
342331
}
343332
}
333+
if ( mFillSymbol )
334+
{
335+
QDomElement fillElem = doc.createElement( QStringLiteral( "fillSymbol" ) );
336+
QDomElement symbolElem = QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "fill symbol" ), mFillSymbol.data(), doc );
337+
if ( !symbolElem.isNull() )
338+
{
339+
fillElem.appendChild( symbolElem );
340+
annotationElem.appendChild( fillElem );
341+
}
342+
}
344343
itemElem.appendChild( annotationElem );
345344
}
346345

@@ -365,12 +364,7 @@ void QgsAnnotation::_readXml( const QDomElement& annotationElem, const QDomDocum
365364
mMapPositionCrs = QgsCoordinateReferenceSystem();
366365
}
367366

368-
mFrameBorderWidth = annotationElem.attribute( QStringLiteral( "frameBorderWidth" ), QStringLiteral( "0.5" ) ).toDouble();
369367
mContentsMargins = QgsMargins::fromString( annotationElem.attribute( QStringLiteral( "contentsMargin" ) ) );
370-
mFrameColor.setNamedColor( annotationElem.attribute( QStringLiteral( "frameColor" ), QStringLiteral( "#000000" ) ) );
371-
mFrameColor.setAlpha( annotationElem.attribute( QStringLiteral( "frameColorAlpha" ), QStringLiteral( "255" ) ).toInt() );
372-
mFrameBackgroundColor.setNamedColor( annotationElem.attribute( QStringLiteral( "frameBackgroundColor" ) ) );
373-
mFrameBackgroundColor.setAlpha( annotationElem.attribute( QStringLiteral( "frameBackgroundColorAlpha" ), QStringLiteral( "255" ) ).toInt() );
374368
mFrameSize.setWidth( annotationElem.attribute( QStringLiteral( "frameWidth" ), QStringLiteral( "50" ) ).toDouble() );
375369
mFrameSize.setHeight( annotationElem.attribute( QStringLiteral( "frameHeight" ), QStringLiteral( "50" ) ).toDouble() );
376370
mOffsetFromReferencePoint.setX( annotationElem.attribute( QStringLiteral( "offsetX" ), QStringLiteral( "0" ) ).toDouble() );
@@ -393,6 +387,41 @@ void QgsAnnotation::_readXml( const QDomElement& annotationElem, const QDomDocum
393387
}
394388
}
395389

390+
mFillSymbol.reset( nullptr );
391+
QDomElement fillElem = annotationElem.firstChildElement( QStringLiteral( "fillSymbol" ) );
392+
if ( !fillElem.isNull() )
393+
{
394+
QDomElement symbolElem = fillElem.firstChildElement( QStringLiteral( "symbol" ) );
395+
if ( !symbolElem.isNull() )
396+
{
397+
QgsFillSymbol* symbol = QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem );
398+
if ( symbol )
399+
{
400+
mFillSymbol.reset( symbol );
401+
}
402+
}
403+
}
404+
if ( !mFillSymbol )
405+
{
406+
QColor frameColor;
407+
frameColor.setNamedColor( annotationElem.attribute( QStringLiteral( "frameColor" ), QStringLiteral( "#000000" ) ) );
408+
frameColor.setAlpha( annotationElem.attribute( QStringLiteral( "frameColorAlpha" ), QStringLiteral( "255" ) ).toInt() );
409+
QColor frameBackgroundColor;
410+
frameBackgroundColor.setNamedColor( annotationElem.attribute( QStringLiteral( "frameBackgroundColor" ) ) );
411+
frameBackgroundColor.setAlpha( annotationElem.attribute( QStringLiteral( "frameBackgroundColorAlpha" ), QStringLiteral( "255" ) ).toInt() );
412+
double frameBorderWidth = annotationElem.attribute( QStringLiteral( "frameBorderWidth" ), QStringLiteral( "0.5" ) ).toDouble();
413+
// need to roughly convert border width from pixels to mm - just assume 96 dpi
414+
frameBorderWidth = frameBorderWidth * 25.4 / 96.0;
415+
QgsStringMap props;
416+
props.insert( QStringLiteral( "color" ), frameBackgroundColor.name() );
417+
props.insert( QStringLiteral( "style" ), QStringLiteral( "solid" ) );
418+
props.insert( QStringLiteral( "style_border" ), QStringLiteral( "solid" ) );
419+
props.insert( QStringLiteral( "color_border" ), frameColor.name() );
420+
props.insert( QStringLiteral( "width_border" ), QString::number( frameBorderWidth ) );
421+
props.insert( QStringLiteral( "joinstyle" ), QStringLiteral( "miter" ) );
422+
mFillSymbol.reset( QgsFillSymbol::createSimple( props ) );
423+
}
424+
396425
updateBalloon();
397426
emit mapLayerChanged();
398427
}

‎src/core/annotations/qgsannotation.h

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -172,40 +172,17 @@ class CORE_EXPORT QgsAnnotation : public QObject
172172
QgsMargins contentsMargin() const { return mContentsMargins; }
173173

174174
/**
175-
* Sets the annotation's frame's border width (in pixels).
176-
* @see frameBorderWidth()
177-
*/
178-
void setFrameBorderWidth( double width );
179-
180-
/**
181-
* Returns the annotation's frame's border width (in pixels).
182-
* @see setFrameBorderWidth
183-
*/
184-
double frameBorderWidth() const { return mFrameBorderWidth; }
185-
186-
/**
187-
* Sets the annotation's frame's border color.
188-
* @see frameColor()
189-
*/
190-
void setFrameColor( const QColor& color );
191-
192-
/**
193-
* Returns the annotation's frame's border color.
194-
* @see setFrameColor()
195-
*/
196-
QColor frameColor() const { return mFrameColor; }
197-
198-
/**
199-
* Sets the annotation's frame's background color.
200-
* @see frameBackgroundColor()
175+
* Sets the fill symbol used for rendering the annotation frame. Ownership
176+
* of the symbol is transferred to the annotation.
177+
* @see fillSymbol()
201178
*/
202-
void setFrameBackgroundColor( const QColor& color );
179+
void setFillSymbol( QgsFillSymbol* symbol );
203180

204181
/**
205-
* Returns the annotation's frame's background color.
206-
* @see setFrameBackgroundColor()
182+
* Returns the symbol that is used for rendering the annotation frame.
183+
* @see setFillSymbol()
207184
*/
208-
QColor frameBackgroundColor() const { return mFrameBackgroundColor; }
185+
QgsFillSymbol* fillSymbol() const { return mFillSymbol.data(); }
209186

210187
/**
211188
* Renders the annotation to a target render context.
@@ -354,14 +331,8 @@ class CORE_EXPORT QgsAnnotation : public QObject
354331

355332
QgsMargins mContentsMargins;
356333

357-
//! Width of the frame
358-
double mFrameBorderWidth = 1.0;
359-
360-
//! Frame / balloon color
361-
QColor mFrameColor = QColor( 0, 0, 0 );
362-
363-
//! Frame background color
364-
QColor mFrameBackgroundColor = QColor( 255, 255, 255 );
334+
//! Fill symbol used for drawing annotation
335+
QScopedPointer<QgsFillSymbol> mFillSymbol;
365336

366337
//! Segment number where the connection to the map point is attached. -1 if no balloon needed (e.g. if point is contained in frame)
367338
int mBalloonSegment = -1;

‎src/gui/qgsformannotation.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ void QgsFormAnnotation::setDesignerForm( const QString& uiFile )
4747
if ( mDesignerWidget )
4848
{
4949
mMinimumSize = mDesignerWidget->minimumSize();
50-
setFrameBackgroundColor( mDesignerWidget->palette().color( QPalette::Window ) );
50+
if ( fillSymbol() )
51+
{
52+
QgsFillSymbol* newFill = fillSymbol()->clone();
53+
newFill->setColor( mDesignerWidget->palette().color( QPalette::Window ) );
54+
setFillSymbol( newFill );
55+
}
5156
setFrameSize( preferredFrameSize() );
5257
}
5358
emit appearanceChanged();
@@ -153,9 +158,11 @@ void QgsFormAnnotation::readXml( const QDomElement& itemElem, const QDomDocument
153158
}
154159

155160
mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
156-
if ( mDesignerWidget )
161+
if ( mDesignerWidget && fillSymbol() )
157162
{
158-
setFrameBackgroundColor( mDesignerWidget->palette().color( QPalette::Window ) );
163+
QgsFillSymbol* newFill = fillSymbol()->clone();
164+
newFill->setColor( mDesignerWidget->palette().color( QPalette::Window ) );
165+
setFillSymbol( newFill );
159166
}
160167
}
161168

@@ -165,9 +172,11 @@ void QgsFormAnnotation::setAssociatedFeature( const QgsFeature& feature )
165172

166173
//create new embedded widget
167174
mDesignerWidget.reset( createDesignerWidget( mDesignerForm ) );
168-
if ( mDesignerWidget )
175+
if ( mDesignerWidget && fillSymbol() )
169176
{
170-
setFrameBackgroundColor( mDesignerWidget->palette().color( QPalette::Window ) );
177+
QgsFillSymbol* newFill = fillSymbol()->clone();
178+
newFill->setColor( mDesignerWidget->palette().color( QPalette::Window ) );
179+
setFillSymbol( newFill );
171180
}
172181
emit appearanceChanged();
173182
}

‎src/gui/qgsmapcanvasannotationitem.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ QRectF QgsMapCanvasAnnotationItem::boundingRect() const
7676
void QgsMapCanvasAnnotationItem::updateBoundingRect()
7777
{
7878
prepareGeometryChange();
79-
double frameBorderWidth = mAnnotation ? mAnnotation->frameBorderWidth() : 0.0;
79+
double frameBorderWidth;
80+
81+
82+
// TODO
83+
8084
if ( mAnnotation && !mAnnotation->hasFixedMapPosition() )
8185
{
8286
mBoundingRect = QRectF( - frameBorderWidth / 2.0, -frameBorderWidth / 2.0, mAnnotation->frameSize().width() + frameBorderWidth, mAnnotation->frameSize().height() + frameBorderWidth );

‎src/ui/qgsannotationwidgetbase.ui

Lines changed: 36 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,31 @@
1414
<string>Form</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout">
17-
<item row="5" column="1">
18-
<layout class="QHBoxLayout" name="horizontalLayout_2">
19-
<item>
20-
<widget class="QgsColorButton" name="mBackgroundColorButton">
21-
<property name="minimumSize">
22-
<size>
23-
<width>120</width>
24-
<height>0</height>
25-
</size>
26-
</property>
27-
<property name="maximumSize">
28-
<size>
29-
<width>120</width>
30-
<height>16777215</height>
31-
</size>
32-
</property>
33-
<property name="text">
34-
<string/>
35-
</property>
36-
</widget>
37-
</item>
38-
<item>
39-
<spacer name="horizontalSpacer_2">
40-
<property name="orientation">
41-
<enum>Qt::Horizontal</enum>
42-
</property>
43-
<property name="sizeHint" stdset="0">
44-
<size>
45-
<width>40</width>
46-
<height>20</height>
47-
</size>
48-
</property>
49-
</spacer>
50-
</item>
51-
</layout>
17+
<item row="3" column="1">
18+
<widget class="QPushButton" name="mFrameStyleButton">
19+
<property name="text">
20+
<string/>
21+
</property>
22+
</widget>
5223
</item>
53-
<item row="6" column="0">
54-
<widget class="QLabel" name="mFrameColorLabel">
24+
<item row="3" column="0">
25+
<widget class="QLabel" name="mMapMarkerLabel_3">
5526
<property name="text">
56-
<string>Frame color</string>
27+
<string>Frame style</string>
28+
</property>
29+
<property name="buddy">
30+
<cstring>mMapMarkerButton</cstring>
5731
</property>
5832
</widget>
5933
</item>
60-
<item row="2" column="1">
61-
<widget class="QPushButton" name="mMapMarkerButton">
34+
<item row="0" column="0" colspan="2">
35+
<widget class="QCheckBox" name="mMapPositionFixedCheckBox">
6236
<property name="text">
63-
<string/>
37+
<string>Fixed map position</string>
6438
</property>
6539
</widget>
6640
</item>
67-
<item row="7" column="0" colspan="2">
41+
<item row="5" column="0" colspan="2">
6842
<widget class="QgsCollapsibleGroupBox" name="mMarginsGroupBox">
6943
<property name="title">
7044
<string>Contents margins</string>
@@ -201,37 +175,7 @@
201175
</layout>
202176
</widget>
203177
</item>
204-
<item row="5" column="0">
205-
<widget class="QLabel" name="mBackgroundColorLabel">
206-
<property name="text">
207-
<string>Background color</string>
208-
</property>
209-
</widget>
210-
</item>
211-
<item row="3" column="1">
212-
<widget class="QgsDoubleSpinBox" name="mFrameWidthSpinBox"/>
213-
</item>
214-
<item row="2" column="0">
215-
<widget class="QLabel" name="mMapMarkerLabel">
216-
<property name="text">
217-
<string>Map marker</string>
218-
</property>
219-
<property name="buddy">
220-
<cstring>mMapMarkerButton</cstring>
221-
</property>
222-
</widget>
223-
</item>
224-
<item row="3" column="0">
225-
<widget class="QLabel" name="mFrameWidthLabel">
226-
<property name="text">
227-
<string>Frame width</string>
228-
</property>
229-
<property name="buddy">
230-
<cstring>mFrameWidthSpinBox</cstring>
231-
</property>
232-
</widget>
233-
</item>
234-
<item row="8" column="1">
178+
<item row="6" column="1">
235179
<spacer name="verticalSpacer">
236180
<property name="orientation">
237181
<enum>Qt::Vertical</enum>
@@ -244,75 +188,43 @@
244188
</property>
245189
</spacer>
246190
</item>
247-
<item row="6" column="1">
248-
<layout class="QHBoxLayout" name="horizontalLayout">
249-
<item>
250-
<widget class="QgsColorButton" name="mFrameColorButton">
251-
<property name="minimumSize">
252-
<size>
253-
<width>120</width>
254-
<height>0</height>
255-
</size>
256-
</property>
257-
<property name="maximumSize">
258-
<size>
259-
<width>120</width>
260-
<height>16777215</height>
261-
</size>
262-
</property>
263-
<property name="text">
264-
<string/>
265-
</property>
266-
</widget>
267-
</item>
268-
<item>
269-
<spacer name="horizontalSpacer">
270-
<property name="orientation">
271-
<enum>Qt::Horizontal</enum>
272-
</property>
273-
<property name="sizeHint" stdset="0">
274-
<size>
275-
<width>40</width>
276-
<height>20</height>
277-
</size>
278-
</property>
279-
</spacer>
280-
</item>
281-
</layout>
191+
<item row="1" column="1">
192+
<widget class="QgsMapLayerComboBox" name="mLayerComboBox">
193+
<property name="toolTip">
194+
<string>Allows the annotation to be associated with a map layer. If set, the annotation will only be visible when the layer is visible.</string>
195+
</property>
196+
</widget>
282197
</item>
283-
<item row="1" column="0">
284-
<widget class="QLabel" name="mMapMarkerLabel_2">
198+
<item row="2" column="0">
199+
<widget class="QLabel" name="mMapMarkerLabel">
285200
<property name="text">
286-
<string>Linked layer</string>
201+
<string>Map marker</string>
287202
</property>
288203
<property name="buddy">
289204
<cstring>mMapMarkerButton</cstring>
290205
</property>
291206
</widget>
292207
</item>
293-
<item row="0" column="0" colspan="2">
294-
<widget class="QCheckBox" name="mMapPositionFixedCheckBox">
208+
<item row="2" column="1">
209+
<widget class="QPushButton" name="mMapMarkerButton">
295210
<property name="text">
296-
<string>Fixed map position</string>
211+
<string/>
297212
</property>
298213
</widget>
299214
</item>
300-
<item row="1" column="1">
301-
<widget class="QgsMapLayerComboBox" name="mLayerComboBox">
302-
<property name="toolTip">
303-
<string>Allows the annotation to be associated with a map layer. If set, the annotation will only be visible when the layer is visible.</string>
215+
<item row="1" column="0">
216+
<widget class="QLabel" name="mMapMarkerLabel_2">
217+
<property name="text">
218+
<string>Linked layer</string>
219+
</property>
220+
<property name="buddy">
221+
<cstring>mMapMarkerButton</cstring>
304222
</property>
305223
</widget>
306224
</item>
307225
</layout>
308226
</widget>
309227
<customwidgets>
310-
<customwidget>
311-
<class>QgsColorButton</class>
312-
<extends>QToolButton</extends>
313-
<header>qgscolorbutton.h</header>
314-
<container>1</container>
315-
</customwidget>
316228
<customwidget>
317229
<class>QgsMapLayerComboBox</class>
318230
<extends>QComboBox</extends>
@@ -334,9 +246,6 @@
334246
<tabstop>mMapPositionFixedCheckBox</tabstop>
335247
<tabstop>mLayerComboBox</tabstop>
336248
<tabstop>mMapMarkerButton</tabstop>
337-
<tabstop>mFrameWidthSpinBox</tabstop>
338-
<tabstop>mBackgroundColorButton</tabstop>
339-
<tabstop>mFrameColorButton</tabstop>
340249
</tabstops>
341250
<resources/>
342251
<connections/>

‎tests/src/python/test_qgsannotation.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
QgsPoint,
2626
QgsVectorLayer,
2727
QgsFeature,
28-
QgsMargins)
28+
QgsMargins,
29+
QgsFillSymbol)
2930
from qgis.PyQt.QtCore import (QDir,
3031
QPointF,
3132
QSizeF)
@@ -123,6 +124,15 @@ def testMargins(self):
123124
im = self.renderAnnotation(a, QPointF(20, 30))
124125
self.assertTrue(self.imageCheck('annotation_margins', 'annotation_margins', im))
125126

127+
def testFillSymbol(self):
128+
""" test rendering an annotation with fill symbol"""
129+
a = QgsTextAnnotation()
130+
a.setFrameSize(QSizeF(400, 250))
131+
a.setHasFixedMapPosition(False)
132+
a.setFillSymbol(QgsFillSymbol.createSimple({'color': 'blue', 'width_border': '5'}))
133+
im = self.renderAnnotation(a, QPointF(20, 30))
134+
self.assertTrue(self.imageCheck('annotation_fillstyle', 'annotation_fillstyle', im))
135+
126136
def renderAnnotation(self, annotation, offset):
127137
image = QImage(600, 400, QImage.Format_RGB32)
128138
image.fill(QColor(0, 0, 0, 0))
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.