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