Skip to content

Commit 166e5bf

Browse files
committed
[composer] Make some set symbol methods clone symbol, nicer API
for PyQGIS (fix #13304)
1 parent 7ac8f41 commit 166e5bf

File tree

8 files changed

+39
-51
lines changed

8 files changed

+39
-51
lines changed

python/core/composer/qgscomposershape.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class QgsComposerShape: QgsComposerItem
4747
/** Sets the QgsFillSymbolV2 used to draw the shape. Must also call setUseSymbolV2( true ) to
4848
* enable drawing with a symbol.
4949
* Note: added in version 2.1*/
50-
void setShapeStyleSymbol( QgsFillSymbolV2* symbol /Transfer/ );
50+
void setShapeStyleSymbol( QgsFillSymbolV2* symbol );
5151
/** Returns the QgsFillSymbolV2 used to draw the shape.
5252
* Note: added in version 2.1*/
5353
QgsFillSymbolV2* shapeStyleSymbol();

python/core/composer/qgscomposition.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class QgsComposition : QGraphicsScene
115115
bool shouldExportPage( const int page ) const;
116116

117117
/** Note: added in version 2.1*/
118-
void setPageStyleSymbol( QgsFillSymbolV2* symbol /Transfer/ );
118+
void setPageStyleSymbol( QgsFillSymbolV2* symbol );
119119
/** Note: added in version 2.1*/
120120
QgsFillSymbolV2* pageStyleSymbol();
121121

src/app/composer/qgscomposershapewidget.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ void QgsComposerShapeWidget::on_mShapeStyleButton_clicked()
117117
updateShapeStyle();
118118
mComposerShape->endCommand();
119119
}
120-
else
121-
{
122-
delete newSymbol;
123-
}
120+
delete newSymbol;
124121
}
125122

126123
void QgsComposerShapeWidget::updateShapeStyle()

src/app/composer/qgscompositionwidget.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,7 @@ void QgsCompositionWidget::on_mPageStyleButton_clicked()
563563
mComposition->setPageStyleSymbol( newSymbol );
564564
updatePageStyle();
565565
}
566-
else
567-
{
568-
delete newSymbol;
569-
}
566+
delete newSymbol;
570567
}
571568

572569
void QgsCompositionWidget::updatePageStyle()

src/core/composer/qgscomposershape.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void QgsComposerShape::setUseSymbolV2( bool useSymbolV2 )
7474
void QgsComposerShape::setShapeStyleSymbol( QgsFillSymbolV2* symbol )
7575
{
7676
delete mShapeStyleSymbol;
77-
mShapeStyleSymbol = symbol;
77+
mShapeStyleSymbol = static_cast<QgsFillSymbolV2*>( symbol->clone() );
7878
refreshSymbol();
7979
}
8080

src/core/composer/qgscomposition.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ bool QgsComposition::shouldExportPage( const int page ) const
492492
void QgsComposition::setPageStyleSymbol( QgsFillSymbolV2* symbol )
493493
{
494494
delete mPageStyleSymbol;
495-
mPageStyleSymbol = symbol;
495+
mPageStyleSymbol = static_cast<QgsFillSymbolV2*>( symbol->clone() );
496496
QgsProject::instance()->dirty( true );
497497
}
498498

tests/src/core/testqgscomposerpaper.cpp

+23-25
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ class TestQgsComposerPaper : public QObject
3636
public:
3737
TestQgsComposerPaper()
3838
: mComposition( 0 )
39-
, mSimpleFill( 0 )
40-
, mMarkerLine( 0 )
41-
, mFillSymbol( 0 )
42-
, mMarkerLineSymbol( 0 )
4339
, mMapSettings( 0 )
4440
{}
4541

@@ -56,10 +52,6 @@ class TestQgsComposerPaper : public QObject
5652
private:
5753
QgsComposition* mComposition;
5854
QString mReport;
59-
QgsSimpleFillSymbolLayerV2* mSimpleFill;
60-
QgsMarkerLineSymbolLayerV2* mMarkerLine;
61-
QgsFillSymbolV2* mFillSymbol;
62-
QgsFillSymbolV2* mMarkerLineSymbol;
6355
QgsMapSettings *mMapSettings;
6456
// QgsSingleSymbolRendererV2* mSymbolRenderer;
6557

@@ -75,16 +67,6 @@ void TestQgsComposerPaper::initTestCase()
7567
mComposition = new QgsComposition( *mMapSettings );
7668
mComposition->setPaperSize( 297, 210 ); //A4 landscape
7769

78-
//setup simple fill
79-
mSimpleFill = new QgsSimpleFillSymbolLayerV2();
80-
mFillSymbol = new QgsFillSymbolV2();
81-
mFillSymbol->changeSymbolLayer( 0, mSimpleFill );
82-
83-
//setup marker line fill
84-
mMarkerLine = new QgsMarkerLineSymbolLayerV2();
85-
mMarkerLineSymbol = new QgsFillSymbolV2();
86-
mMarkerLineSymbol->changeSymbolLayer( 0, mMarkerLine );
87-
8870
mReport = "<h1>Composer Paper Tests</h1>\n";
8971
}
9072

@@ -123,27 +105,43 @@ void TestQgsComposerPaper::defaultPaper()
123105

124106
void TestQgsComposerPaper::transparentPaper()
125107
{
126-
mSimpleFill->setColor( Qt::transparent );
127-
mSimpleFill->setBorderColor( Qt::transparent );
128-
mComposition->setPageStyleSymbol( mFillSymbol );
108+
QgsSimpleFillSymbolLayerV2* simpleFill = new QgsSimpleFillSymbolLayerV2();
109+
QgsFillSymbolV2* fillSymbol = new QgsFillSymbolV2();
110+
fillSymbol->changeSymbolLayer( 0, simpleFill );
111+
simpleFill->setColor( Qt::transparent );
112+
simpleFill->setBorderColor( Qt::transparent );
113+
mComposition->setPageStyleSymbol( fillSymbol );
114+
delete fillSymbol;
115+
129116
QgsCompositionChecker checker( "composerpaper_transparent", mComposition );
130117
checker.setControlPathPrefix( "composer_paper" );
131118
QVERIFY( checker.testComposition( mReport ) );
132119
}
133120

134121
void TestQgsComposerPaper::borderedPaper()
135122
{
136-
mSimpleFill->setColor( Qt::white );
137-
mSimpleFill->setBorderColor( Qt::black );
138-
mSimpleFill->setBorderWidth( 6 );
123+
QgsSimpleFillSymbolLayerV2* simpleFill = new QgsSimpleFillSymbolLayerV2();
124+
QgsFillSymbolV2* fillSymbol = new QgsFillSymbolV2();
125+
fillSymbol->changeSymbolLayer( 0, simpleFill );
126+
simpleFill->setColor( Qt::white );
127+
simpleFill->setBorderColor( Qt::black );
128+
simpleFill->setBorderWidth( 6 );
129+
mComposition->setPageStyleSymbol( fillSymbol );
130+
delete fillSymbol;
131+
139132
QgsCompositionChecker checker( "composerpaper_bordered", mComposition );
140133
checker.setControlPathPrefix( "composer_paper" );
141134
QVERIFY( checker.testComposition( mReport ) );
142135
}
143136

144137
void TestQgsComposerPaper::markerLinePaper()
145138
{
146-
mComposition->setPageStyleSymbol( mMarkerLineSymbol );
139+
QgsMarkerLineSymbolLayerV2* markerLine = new QgsMarkerLineSymbolLayerV2();
140+
QgsFillSymbolV2* markerLineSymbol = new QgsFillSymbolV2();
141+
markerLineSymbol->changeSymbolLayer( 0, markerLine );
142+
mComposition->setPageStyleSymbol( markerLineSymbol );
143+
delete markerLineSymbol;
144+
147145
QgsCompositionChecker checker( "composerpaper_markerborder", mComposition );
148146
checker.setControlPathPrefix( "composer_paper" );
149147
QVERIFY( checker.testComposition( mReport, 0, 0 ) );

tests/src/core/testqgscomposershapes.cpp

+10-14
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class TestQgsComposerShapes : public QObject
3737
: mComposition( 0 )
3838
, mComposerShape( 0 )
3939
, mMapSettings( 0 )
40-
, mSimpleFill( 0 )
41-
, mFillSymbol( 0 )
4240
{}
4341

4442
private slots:
@@ -56,8 +54,6 @@ class TestQgsComposerShapes : public QObject
5654
QgsComposition* mComposition;
5755
QgsComposerShape* mComposerShape;
5856
QgsMapSettings *mMapSettings;
59-
QgsSimpleFillSymbolLayerV2* mSimpleFill;
60-
QgsFillSymbolV2* mFillSymbol;
6157
QString mReport;
6258
};
6359

@@ -75,11 +71,6 @@ void TestQgsComposerShapes::initTestCase()
7571
mComposerShape->setBackgroundColor( QColor::fromRgb( 255, 150, 0 ) );
7672
mComposition->addComposerShape( mComposerShape );
7773

78-
//setup simple fill
79-
mSimpleFill = new QgsSimpleFillSymbolLayerV2();
80-
mFillSymbol = new QgsFillSymbolV2();
81-
mFillSymbol->changeSymbolLayer( 0, mSimpleFill );
82-
8374
mReport = "<h1>Composer Shape Tests</h1>\n";
8475
}
8576

@@ -151,12 +142,17 @@ void TestQgsComposerShapes::symbolV2()
151142
{
152143
mComposerShape->setShapeType( QgsComposerShape::Rectangle );
153144

154-
mSimpleFill->setColor( Qt::green );
155-
mSimpleFill->setBorderColor( Qt::yellow );
156-
mSimpleFill->setBorderWidth( 6 );
157-
158-
mComposerShape->setShapeStyleSymbol( mFillSymbol );
145+
//setup simple fill
146+
QgsSimpleFillSymbolLayerV2* simpleFill = new QgsSimpleFillSymbolLayerV2();
147+
QgsFillSymbolV2* fillSymbol = new QgsFillSymbolV2();
148+
fillSymbol->changeSymbolLayer( 0, simpleFill );
149+
simpleFill->setColor( Qt::green );
150+
simpleFill->setBorderColor( Qt::yellow );
151+
simpleFill->setBorderWidth( 6 );
152+
153+
mComposerShape->setShapeStyleSymbol( fillSymbol );
159154
mComposerShape->setUseSymbolV2( true );
155+
delete fillSymbol;
160156

161157
QgsCompositionChecker checker( "composershapes_symbolv2", mComposition );
162158
checker.setControlPathPrefix( "composer_shapes" );

0 commit comments

Comments
 (0)