mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[composer] Make some set symbol methods clone symbol, nicer API
for PyQGIS (fix #13304)
This commit is contained in:
parent
7ac8f41bd2
commit
166e5bf9eb
@ -47,7 +47,7 @@ class QgsComposerShape: QgsComposerItem
|
||||
/** Sets the QgsFillSymbolV2 used to draw the shape. Must also call setUseSymbolV2( true ) to
|
||||
* enable drawing with a symbol.
|
||||
* Note: added in version 2.1*/
|
||||
void setShapeStyleSymbol( QgsFillSymbolV2* symbol /Transfer/ );
|
||||
void setShapeStyleSymbol( QgsFillSymbolV2* symbol );
|
||||
/** Returns the QgsFillSymbolV2 used to draw the shape.
|
||||
* Note: added in version 2.1*/
|
||||
QgsFillSymbolV2* shapeStyleSymbol();
|
||||
|
@ -115,7 +115,7 @@ class QgsComposition : QGraphicsScene
|
||||
bool shouldExportPage( const int page ) const;
|
||||
|
||||
/** Note: added in version 2.1*/
|
||||
void setPageStyleSymbol( QgsFillSymbolV2* symbol /Transfer/ );
|
||||
void setPageStyleSymbol( QgsFillSymbolV2* symbol );
|
||||
/** Note: added in version 2.1*/
|
||||
QgsFillSymbolV2* pageStyleSymbol();
|
||||
|
||||
|
@ -117,10 +117,7 @@ void QgsComposerShapeWidget::on_mShapeStyleButton_clicked()
|
||||
updateShapeStyle();
|
||||
mComposerShape->endCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
delete newSymbol;
|
||||
}
|
||||
delete newSymbol;
|
||||
}
|
||||
|
||||
void QgsComposerShapeWidget::updateShapeStyle()
|
||||
|
@ -563,10 +563,7 @@ void QgsCompositionWidget::on_mPageStyleButton_clicked()
|
||||
mComposition->setPageStyleSymbol( newSymbol );
|
||||
updatePageStyle();
|
||||
}
|
||||
else
|
||||
{
|
||||
delete newSymbol;
|
||||
}
|
||||
delete newSymbol;
|
||||
}
|
||||
|
||||
void QgsCompositionWidget::updatePageStyle()
|
||||
|
@ -74,7 +74,7 @@ void QgsComposerShape::setUseSymbolV2( bool useSymbolV2 )
|
||||
void QgsComposerShape::setShapeStyleSymbol( QgsFillSymbolV2* symbol )
|
||||
{
|
||||
delete mShapeStyleSymbol;
|
||||
mShapeStyleSymbol = symbol;
|
||||
mShapeStyleSymbol = static_cast<QgsFillSymbolV2*>( symbol->clone() );
|
||||
refreshSymbol();
|
||||
}
|
||||
|
||||
|
@ -492,7 +492,7 @@ bool QgsComposition::shouldExportPage( const int page ) const
|
||||
void QgsComposition::setPageStyleSymbol( QgsFillSymbolV2* symbol )
|
||||
{
|
||||
delete mPageStyleSymbol;
|
||||
mPageStyleSymbol = symbol;
|
||||
mPageStyleSymbol = static_cast<QgsFillSymbolV2*>( symbol->clone() );
|
||||
QgsProject::instance()->dirty( true );
|
||||
}
|
||||
|
||||
|
@ -36,10 +36,6 @@ class TestQgsComposerPaper : public QObject
|
||||
public:
|
||||
TestQgsComposerPaper()
|
||||
: mComposition( 0 )
|
||||
, mSimpleFill( 0 )
|
||||
, mMarkerLine( 0 )
|
||||
, mFillSymbol( 0 )
|
||||
, mMarkerLineSymbol( 0 )
|
||||
, mMapSettings( 0 )
|
||||
{}
|
||||
|
||||
@ -56,10 +52,6 @@ class TestQgsComposerPaper : public QObject
|
||||
private:
|
||||
QgsComposition* mComposition;
|
||||
QString mReport;
|
||||
QgsSimpleFillSymbolLayerV2* mSimpleFill;
|
||||
QgsMarkerLineSymbolLayerV2* mMarkerLine;
|
||||
QgsFillSymbolV2* mFillSymbol;
|
||||
QgsFillSymbolV2* mMarkerLineSymbol;
|
||||
QgsMapSettings *mMapSettings;
|
||||
// QgsSingleSymbolRendererV2* mSymbolRenderer;
|
||||
|
||||
@ -75,16 +67,6 @@ void TestQgsComposerPaper::initTestCase()
|
||||
mComposition = new QgsComposition( *mMapSettings );
|
||||
mComposition->setPaperSize( 297, 210 ); //A4 landscape
|
||||
|
||||
//setup simple fill
|
||||
mSimpleFill = new QgsSimpleFillSymbolLayerV2();
|
||||
mFillSymbol = new QgsFillSymbolV2();
|
||||
mFillSymbol->changeSymbolLayer( 0, mSimpleFill );
|
||||
|
||||
//setup marker line fill
|
||||
mMarkerLine = new QgsMarkerLineSymbolLayerV2();
|
||||
mMarkerLineSymbol = new QgsFillSymbolV2();
|
||||
mMarkerLineSymbol->changeSymbolLayer( 0, mMarkerLine );
|
||||
|
||||
mReport = "<h1>Composer Paper Tests</h1>\n";
|
||||
}
|
||||
|
||||
@ -123,9 +105,14 @@ void TestQgsComposerPaper::defaultPaper()
|
||||
|
||||
void TestQgsComposerPaper::transparentPaper()
|
||||
{
|
||||
mSimpleFill->setColor( Qt::transparent );
|
||||
mSimpleFill->setBorderColor( Qt::transparent );
|
||||
mComposition->setPageStyleSymbol( mFillSymbol );
|
||||
QgsSimpleFillSymbolLayerV2* simpleFill = new QgsSimpleFillSymbolLayerV2();
|
||||
QgsFillSymbolV2* fillSymbol = new QgsFillSymbolV2();
|
||||
fillSymbol->changeSymbolLayer( 0, simpleFill );
|
||||
simpleFill->setColor( Qt::transparent );
|
||||
simpleFill->setBorderColor( Qt::transparent );
|
||||
mComposition->setPageStyleSymbol( fillSymbol );
|
||||
delete fillSymbol;
|
||||
|
||||
QgsCompositionChecker checker( "composerpaper_transparent", mComposition );
|
||||
checker.setControlPathPrefix( "composer_paper" );
|
||||
QVERIFY( checker.testComposition( mReport ) );
|
||||
@ -133,9 +120,15 @@ void TestQgsComposerPaper::transparentPaper()
|
||||
|
||||
void TestQgsComposerPaper::borderedPaper()
|
||||
{
|
||||
mSimpleFill->setColor( Qt::white );
|
||||
mSimpleFill->setBorderColor( Qt::black );
|
||||
mSimpleFill->setBorderWidth( 6 );
|
||||
QgsSimpleFillSymbolLayerV2* simpleFill = new QgsSimpleFillSymbolLayerV2();
|
||||
QgsFillSymbolV2* fillSymbol = new QgsFillSymbolV2();
|
||||
fillSymbol->changeSymbolLayer( 0, simpleFill );
|
||||
simpleFill->setColor( Qt::white );
|
||||
simpleFill->setBorderColor( Qt::black );
|
||||
simpleFill->setBorderWidth( 6 );
|
||||
mComposition->setPageStyleSymbol( fillSymbol );
|
||||
delete fillSymbol;
|
||||
|
||||
QgsCompositionChecker checker( "composerpaper_bordered", mComposition );
|
||||
checker.setControlPathPrefix( "composer_paper" );
|
||||
QVERIFY( checker.testComposition( mReport ) );
|
||||
@ -143,7 +136,12 @@ void TestQgsComposerPaper::borderedPaper()
|
||||
|
||||
void TestQgsComposerPaper::markerLinePaper()
|
||||
{
|
||||
mComposition->setPageStyleSymbol( mMarkerLineSymbol );
|
||||
QgsMarkerLineSymbolLayerV2* markerLine = new QgsMarkerLineSymbolLayerV2();
|
||||
QgsFillSymbolV2* markerLineSymbol = new QgsFillSymbolV2();
|
||||
markerLineSymbol->changeSymbolLayer( 0, markerLine );
|
||||
mComposition->setPageStyleSymbol( markerLineSymbol );
|
||||
delete markerLineSymbol;
|
||||
|
||||
QgsCompositionChecker checker( "composerpaper_markerborder", mComposition );
|
||||
checker.setControlPathPrefix( "composer_paper" );
|
||||
QVERIFY( checker.testComposition( mReport, 0, 0 ) );
|
||||
|
@ -37,8 +37,6 @@ class TestQgsComposerShapes : public QObject
|
||||
: mComposition( 0 )
|
||||
, mComposerShape( 0 )
|
||||
, mMapSettings( 0 )
|
||||
, mSimpleFill( 0 )
|
||||
, mFillSymbol( 0 )
|
||||
{}
|
||||
|
||||
private slots:
|
||||
@ -56,8 +54,6 @@ class TestQgsComposerShapes : public QObject
|
||||
QgsComposition* mComposition;
|
||||
QgsComposerShape* mComposerShape;
|
||||
QgsMapSettings *mMapSettings;
|
||||
QgsSimpleFillSymbolLayerV2* mSimpleFill;
|
||||
QgsFillSymbolV2* mFillSymbol;
|
||||
QString mReport;
|
||||
};
|
||||
|
||||
@ -75,11 +71,6 @@ void TestQgsComposerShapes::initTestCase()
|
||||
mComposerShape->setBackgroundColor( QColor::fromRgb( 255, 150, 0 ) );
|
||||
mComposition->addComposerShape( mComposerShape );
|
||||
|
||||
//setup simple fill
|
||||
mSimpleFill = new QgsSimpleFillSymbolLayerV2();
|
||||
mFillSymbol = new QgsFillSymbolV2();
|
||||
mFillSymbol->changeSymbolLayer( 0, mSimpleFill );
|
||||
|
||||
mReport = "<h1>Composer Shape Tests</h1>\n";
|
||||
}
|
||||
|
||||
@ -151,12 +142,17 @@ void TestQgsComposerShapes::symbolV2()
|
||||
{
|
||||
mComposerShape->setShapeType( QgsComposerShape::Rectangle );
|
||||
|
||||
mSimpleFill->setColor( Qt::green );
|
||||
mSimpleFill->setBorderColor( Qt::yellow );
|
||||
mSimpleFill->setBorderWidth( 6 );
|
||||
//setup simple fill
|
||||
QgsSimpleFillSymbolLayerV2* simpleFill = new QgsSimpleFillSymbolLayerV2();
|
||||
QgsFillSymbolV2* fillSymbol = new QgsFillSymbolV2();
|
||||
fillSymbol->changeSymbolLayer( 0, simpleFill );
|
||||
simpleFill->setColor( Qt::green );
|
||||
simpleFill->setBorderColor( Qt::yellow );
|
||||
simpleFill->setBorderWidth( 6 );
|
||||
|
||||
mComposerShape->setShapeStyleSymbol( mFillSymbol );
|
||||
mComposerShape->setShapeStyleSymbol( fillSymbol );
|
||||
mComposerShape->setUseSymbolV2( true );
|
||||
delete fillSymbol;
|
||||
|
||||
QgsCompositionChecker checker( "composershapes_symbolv2", mComposition );
|
||||
checker.setControlPathPrefix( "composer_shapes" );
|
||||
|
Loading…
x
Reference in New Issue
Block a user