@@ -870,8 +870,12 @@ bool QgsImageFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
870
870
871
871
double QgsImageFillSymbolLayer::estimateMaxBleed () const
872
872
{
873
- double subLayerBleed = mOutline ->symbolLayer ( 0 )->estimateMaxBleed ();
874
- return subLayerBleed;
873
+ if ( mOutline && mOutline ->symbolLayer ( 0 ) )
874
+ {
875
+ double subLayerBleed = mOutline ->symbolLayer ( 0 )->estimateMaxBleed ();
876
+ return subLayerBleed;
877
+ }
878
+ return 0 ;
875
879
}
876
880
877
881
double QgsImageFillSymbolLayer::dxfWidth ( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
@@ -936,7 +940,6 @@ QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QByteArray& svgData, double
936
940
937
941
QgsSVGFillSymbolLayer::~QgsSVGFillSymbolLayer ()
938
942
{
939
- delete mOutline ;
940
943
delete mSvgPattern ;
941
944
}
942
945
@@ -1399,12 +1402,47 @@ void QgsSVGFillSymbolLayer::setDefaultSvgParams()
1399
1402
1400
1403
1401
1404
QgsLinePatternFillSymbolLayer::QgsLinePatternFillSymbolLayer (): QgsImageFillSymbolLayer(), mDistanceUnit( QgsSymbolV2::MM ), mLineWidthUnit( QgsSymbolV2::MM ),
1402
- mOffsetUnit( QgsSymbolV2::MM )
1405
+ mOffsetUnit( QgsSymbolV2::MM ), mFillLineSymbol( 0 )
1403
1406
{
1407
+ setSubSymbol ( new QgsLineSymbolV2 () );
1408
+ QgsImageFillSymbolLayer::setSubSymbol ( 0 ); // no outline
1404
1409
}
1405
1410
1406
1411
QgsLinePatternFillSymbolLayer::~QgsLinePatternFillSymbolLayer ()
1407
1412
{
1413
+ delete mFillLineSymbol ;
1414
+ }
1415
+
1416
+ bool QgsLinePatternFillSymbolLayer::setSubSymbol ( QgsSymbolV2* symbol )
1417
+ {
1418
+ if ( !symbol )
1419
+ {
1420
+ return false ;
1421
+ }
1422
+
1423
+ if ( symbol->type () == QgsSymbolV2::Line )
1424
+ {
1425
+ QgsLineSymbolV2* lineSymbol = dynamic_cast <QgsLineSymbolV2*>( symbol );
1426
+ if ( lineSymbol )
1427
+ {
1428
+ delete mFillLineSymbol ;
1429
+ mFillLineSymbol = lineSymbol;
1430
+
1431
+ return true ;
1432
+ }
1433
+ }
1434
+ delete symbol;
1435
+ return false ;
1436
+ }
1437
+
1438
+ QgsSymbolV2* QgsLinePatternFillSymbolLayer::subSymbol ()
1439
+ {
1440
+ return mFillLineSymbol ;
1441
+ }
1442
+
1443
+ double QgsLinePatternFillSymbolLayer::estimateMaxBleed () const
1444
+ {
1445
+ return 0 ;
1408
1446
}
1409
1447
1410
1448
void QgsLinePatternFillSymbolLayer::setOutputUnit ( QgsSymbolV2::OutputUnit unit )
@@ -1507,8 +1545,10 @@ QString QgsLinePatternFillSymbolLayer::layerType() const
1507
1545
void QgsLinePatternFillSymbolLayer::applyPattern ( const QgsSymbolV2RenderContext& context, QBrush& brush, double lineAngle, double distance,
1508
1546
double lineWidth, const QColor& color )
1509
1547
{
1548
+ Q_UNUSED ( lineWidth );
1549
+ Q_UNUSED ( color );
1510
1550
const QgsRenderContext& ctx = context.renderContext ();
1511
- double outlinePixelWidth = lineWidth * QgsSymbolLayerV2Utils::pixelSizeScaleFactor ( ctx, mLineWidthUnit );
1551
+ // double outlinePixelWidth = lineWidth * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( ctx, mLineWidthUnit );
1512
1552
double outputPixelDist = distance * QgsSymbolLayerV2Utils::pixelSizeScaleFactor ( ctx, mDistanceUnit );
1513
1553
double outputPixelOffset = mOffset * QgsSymbolLayerV2Utils::pixelSizeScaleFactor ( ctx, mOffsetUnit );
1514
1554
@@ -1538,13 +1578,6 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolV2RenderContext
1538
1578
1539
1579
QImage patternImage ( width, height, QImage::Format_ARGB32 );
1540
1580
patternImage.fill ( 0 );
1541
- QPainter p ( &patternImage );
1542
-
1543
- p.setRenderHint ( QPainter::Antialiasing, true );
1544
- QPen pen ( color );
1545
- pen.setWidthF ( outlinePixelWidth );
1546
- pen.setCapStyle ( Qt::FlatCap );
1547
- p.setPen ( pen );
1548
1581
1549
1582
QPoint p1, p2, p3, p4, p5, p6;
1550
1583
if ( qgsDoubleNear ( lineAngle, 0.0 ) || qgsDoubleNear ( lineAngle, 360.0 ) || qgsDoubleNear ( lineAngle, 180.0 ) )
@@ -1607,10 +1640,44 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolV2RenderContext
1607
1640
p2 = QPoint ( tempPt.x (), tempPt.y () );;
1608
1641
}
1609
1642
1610
- p.drawLine ( p1, p2 );
1611
- p.drawLine ( p3, p4 );
1612
- p.drawLine ( p5, p6 );
1613
- p.end ();
1643
+ if ( mFillLineSymbol )
1644
+ {
1645
+ QPainter p ( &patternImage );
1646
+
1647
+ #if 0
1648
+ // DEBUG: Draw rectangle
1649
+ //p.setRenderHint( QPainter::Antialiasing, true );
1650
+ QPen pen( QColor( Qt::black ) );
1651
+ pen.setWidthF( 0.1 );
1652
+ pen.setCapStyle( Qt::FlatCap );
1653
+ p.setPen( pen );
1654
+ QPolygon polygon = QPolygon() << QPoint( 0, 0 ) << QPoint( width, 0 ) << QPoint( width, height ) << QPoint( 0, height ) << QPoint( 0, 0 ) ;
1655
+ p.drawPolygon( polygon );
1656
+ #endif
1657
+
1658
+ // line rendering needs context for drawing on patternImage
1659
+ QgsRenderContext lineRenderContext;
1660
+ lineRenderContext.setPainter ( &p );
1661
+ lineRenderContext.setRasterScaleFactor ( 1.0 );
1662
+ lineRenderContext.setScaleFactor ( context.renderContext ().scaleFactor () * context.renderContext ().rasterScaleFactor () );
1663
+ QgsMapToPixel mtp ( context.renderContext ().mapToPixel ().mapUnitsPerPixel () / context.renderContext ().rasterScaleFactor () );
1664
+ lineRenderContext.setMapToPixel ( mtp );
1665
+ lineRenderContext.setForceVectorOutput ( false );
1666
+
1667
+ mFillLineSymbol ->startRender ( lineRenderContext );
1668
+
1669
+ QVector<QPolygon> polygons;
1670
+ polygons.append ( QPolygon () << p1 << p2 );
1671
+ polygons.append ( QPolygon () << p3 << p4 );
1672
+ polygons.append ( QPolygon () << p5 << p6 );
1673
+ foreach ( QPolygon polygon, polygons )
1674
+ {
1675
+ mFillLineSymbol ->renderPolyline ( polygon, context.feature (), lineRenderContext, -1 , context.selected () );
1676
+ }
1677
+
1678
+ mFillLineSymbol ->stopRender ( lineRenderContext );
1679
+ p.end ();
1680
+ }
1614
1681
1615
1682
// set image to mBrush
1616
1683
if ( !qgsDoubleNear ( context.alpha (), 1.0 ) )
@@ -1633,9 +1700,9 @@ void QgsLinePatternFillSymbolLayer::startRender( QgsSymbolV2RenderContext& conte
1633
1700
{
1634
1701
applyPattern ( context, mBrush , mLineAngle , mDistance , mLineWidth , mColor );
1635
1702
1636
- if ( mOutline )
1703
+ if ( mFillLineSymbol )
1637
1704
{
1638
- mOutline ->startRender ( context.renderContext () );
1705
+ mFillLineSymbol ->startRender ( context.renderContext () );
1639
1706
}
1640
1707
1641
1708
prepareExpressions ( context.layer (), context.renderContext ().rendererScale () );
@@ -1663,9 +1730,9 @@ QgsStringMap QgsLinePatternFillSymbolLayer::properties() const
1663
1730
QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::clone () const
1664
1731
{
1665
1732
QgsLinePatternFillSymbolLayer* clonedLayer = static_cast <QgsLinePatternFillSymbolLayer*>( QgsLinePatternFillSymbolLayer::create ( properties () ) );
1666
- if ( mOutline )
1733
+ if ( mFillLineSymbol )
1667
1734
{
1668
- clonedLayer->setSubSymbol ( mOutline ->clone () );
1735
+ clonedLayer->setSubSymbol ( mFillLineSymbol ->clone () );
1669
1736
}
1670
1737
clonedLayer->setDistanceUnit ( mDistanceUnit );
1671
1738
clonedLayer->setLineWidthUnit ( mLineWidthUnit );
@@ -1713,12 +1780,9 @@ void QgsLinePatternFillSymbolLayer::toSld( QDomDocument &doc, QDomElement &eleme
1713
1780
QPointF lineOffset ( sin ( mLineAngle ) * mOffset , cos ( mLineAngle ) * mOffset );
1714
1781
QgsSymbolLayerV2Utils::createDisplacementElement ( doc, graphicElem, lineOffset );
1715
1782
1716
- if ( mOutline )
1783
+ if ( mFillLineSymbol )
1717
1784
{
1718
- // the outline sub symbol should be stored within the Stroke element,
1719
- // but it will be stored in a separated LineSymbolizer because it could
1720
- // have more than one layer
1721
- mOutline ->toSld ( doc, element, props );
1785
+ mFillLineSymbol ->toSld ( doc, element, props );
1722
1786
}
1723
1787
}
1724
1788
0 commit comments