Skip to content

Commit 8f8ea0e

Browse files
committed
use line pattern fill symbol layer line symbol for fill instead of for outline
1 parent 71e09ec commit 8f8ea0e

File tree

2 files changed

+98
-26
lines changed

2 files changed

+98
-26
lines changed

src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 89 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,12 @@ bool QgsImageFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
870870

871871
double QgsImageFillSymbolLayer::estimateMaxBleed() const
872872
{
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;
875879
}
876880

877881
double QgsImageFillSymbolLayer::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
@@ -936,7 +940,6 @@ QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QByteArray& svgData, double
936940

937941
QgsSVGFillSymbolLayer::~QgsSVGFillSymbolLayer()
938942
{
939-
delete mOutline;
940943
delete mSvgPattern;
941944
}
942945

@@ -1399,12 +1402,47 @@ void QgsSVGFillSymbolLayer::setDefaultSvgParams()
13991402

14001403

14011404
QgsLinePatternFillSymbolLayer::QgsLinePatternFillSymbolLayer(): QgsImageFillSymbolLayer(), mDistanceUnit( QgsSymbolV2::MM ), mLineWidthUnit( QgsSymbolV2::MM ),
1402-
mOffsetUnit( QgsSymbolV2::MM )
1405+
mOffsetUnit( QgsSymbolV2::MM ), mFillLineSymbol( 0 )
14031406
{
1407+
setSubSymbol( new QgsLineSymbolV2() );
1408+
QgsImageFillSymbolLayer::setSubSymbol( 0 ); //no outline
14041409
}
14051410

14061411
QgsLinePatternFillSymbolLayer::~QgsLinePatternFillSymbolLayer()
14071412
{
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;
14081446
}
14091447

14101448
void QgsLinePatternFillSymbolLayer::setOutputUnit( QgsSymbolV2::OutputUnit unit )
@@ -1507,8 +1545,10 @@ QString QgsLinePatternFillSymbolLayer::layerType() const
15071545
void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolV2RenderContext& context, QBrush& brush, double lineAngle, double distance,
15081546
double lineWidth, const QColor& color )
15091547
{
1548+
Q_UNUSED( lineWidth );
1549+
Q_UNUSED( color );
15101550
const QgsRenderContext& ctx = context.renderContext();
1511-
double outlinePixelWidth = lineWidth * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( ctx, mLineWidthUnit );
1551+
//double outlinePixelWidth = lineWidth * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( ctx, mLineWidthUnit );
15121552
double outputPixelDist = distance * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( ctx, mDistanceUnit );
15131553
double outputPixelOffset = mOffset * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( ctx, mOffsetUnit );
15141554

@@ -1538,13 +1578,6 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolV2RenderContext
15381578

15391579
QImage patternImage( width, height, QImage::Format_ARGB32 );
15401580
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 );
15481581

15491582
QPoint p1, p2, p3, p4, p5, p6;
15501583
if ( qgsDoubleNear( lineAngle, 0.0 ) || qgsDoubleNear( lineAngle, 360.0 ) || qgsDoubleNear( lineAngle, 180.0 ) )
@@ -1607,10 +1640,44 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolV2RenderContext
16071640
p2 = QPoint( tempPt.x(), tempPt.y() );;
16081641
}
16091642

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+
}
16141681

16151682
//set image to mBrush
16161683
if ( !qgsDoubleNear( context.alpha(), 1.0 ) )
@@ -1633,9 +1700,9 @@ void QgsLinePatternFillSymbolLayer::startRender( QgsSymbolV2RenderContext& conte
16331700
{
16341701
applyPattern( context, mBrush, mLineAngle, mDistance, mLineWidth, mColor );
16351702

1636-
if ( mOutline )
1703+
if ( mFillLineSymbol )
16371704
{
1638-
mOutline->startRender( context.renderContext() );
1705+
mFillLineSymbol->startRender( context.renderContext() );
16391706
}
16401707

16411708
prepareExpressions( context.layer(), context.renderContext().rendererScale() );
@@ -1663,9 +1730,9 @@ QgsStringMap QgsLinePatternFillSymbolLayer::properties() const
16631730
QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::clone() const
16641731
{
16651732
QgsLinePatternFillSymbolLayer* clonedLayer = static_cast<QgsLinePatternFillSymbolLayer*>( QgsLinePatternFillSymbolLayer::create( properties() ) );
1666-
if ( mOutline )
1733+
if ( mFillLineSymbol )
16671734
{
1668-
clonedLayer->setSubSymbol( mOutline->clone() );
1735+
clonedLayer->setSubSymbol( mFillLineSymbol->clone() );
16691736
}
16701737
clonedLayer->setDistanceUnit( mDistanceUnit );
16711738
clonedLayer->setLineWidthUnit( mLineWidthUnit );
@@ -1713,12 +1780,9 @@ void QgsLinePatternFillSymbolLayer::toSld( QDomDocument &doc, QDomElement &eleme
17131780
QPointF lineOffset( sin( mLineAngle ) * mOffset, cos( mLineAngle ) * mOffset );
17141781
QgsSymbolLayerV2Utils::createDisplacementElement( doc, graphicElem, lineOffset );
17151782

1716-
if ( mOutline )
1783+
if ( mFillLineSymbol )
17171784
{
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 );
17221786
}
17231787
}
17241788

src/core/symbology-ng/qgsfillsymbollayerv2.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class CORE_EXPORT QgsImageFillSymbolLayer: public QgsFillSymbolLayerV2
285285
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
286286
QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
287287

288-
double estimateMaxBleed() const;
288+
virtual double estimateMaxBleed() const;
289289

290290
virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
291291
virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
@@ -407,6 +407,8 @@ class CORE_EXPORT QgsLinePatternFillSymbolLayer: public QgsImageFillSymbolLayer
407407

408408
void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
409409

410+
double estimateMaxBleed() const;
411+
410412
QString ogrFeatureStyleWidth( double widthScaleFactor ) const;
411413

412414
//getters and setters
@@ -433,6 +435,9 @@ class CORE_EXPORT QgsLinePatternFillSymbolLayer: public QgsImageFillSymbolLayer
433435
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
434436
QgsSymbolV2::OutputUnit outputUnit() const;
435437

438+
bool setSubSymbol( QgsSymbolV2* symbol );
439+
QgsSymbolV2* subSymbol();
440+
436441
protected:
437442
/**Distance (in mm or map units) between lines*/
438443
double mDistance;
@@ -452,6 +457,9 @@ class CORE_EXPORT QgsLinePatternFillSymbolLayer: public QgsImageFillSymbolLayer
452457
private:
453458
/**Applies the svg pattern to the brush*/
454459
void applyPattern( const QgsSymbolV2RenderContext& context, QBrush& brush, double lineAngle, double distance, double lineWidth, const QColor& color );
460+
461+
/**Fill line*/
462+
QgsLineSymbolV2* mFillLineSymbol;
455463
};
456464

457465
class CORE_EXPORT QgsPointPatternFillSymbolLayer: public QgsImageFillSymbolLayer

0 commit comments

Comments
 (0)