Skip to content

Commit

Permalink
Add method for estimating the maximum amount a symbol bleeds out of t…
Browse files Browse the repository at this point in the history
…he drawn polygon. Eg, half of the border width is actually drawn outside of a rectangle. Calculated values are an estimate only since the symbology may be affected by data defined parameters.
  • Loading branch information
nyalldawson committed Jan 4, 2014
1 parent 1215d0b commit b5502b6
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -282,6 +282,13 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::createFromSld( QDomElement &elemen
return sl;
}

double QgsSimpleFillSymbolLayerV2::estimateMaxBleed() const
{
double penBleed = mBorderStyle == Qt::NoPen ? 0 : ( mBorderWidth / 2.0 );
double offsetBleed = mOffset.x() > mOffset.y() ? mOffset.x() : mOffset.y();
return penBleed + offsetBleed;
}

//QgsGradientFillSymbolLayer

QgsGradientFillSymbolLayerV2::QgsGradientFillSymbolLayerV2( QColor color, QColor color2,
Expand Down Expand Up @@ -729,6 +736,12 @@ QgsSymbolLayerV2* QgsGradientFillSymbolLayerV2::clone() const
return sl;
}

double QgsGradientFillSymbolLayerV2::estimateMaxBleed() const
{
double offsetBleed = mOffset.x() > mOffset.y() ? mOffset.x() : mOffset.y();
return offsetBleed;
}

//QgsImageFillSymbolLayer

QgsImageFillSymbolLayer::QgsImageFillSymbolLayer(): mOutlineWidth( 0.0 ), mOutlineWidthUnit( QgsSymbolV2::MM ), mOutline( 0 )
Expand Down Expand Up @@ -816,6 +829,14 @@ bool QgsImageFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
return false;
}


double QgsImageFillSymbolLayer::estimateMaxBleed() const
{
double subLayerBleed = mOutline->symbolLayer( 0 )->estimateMaxBleed();
return subLayerBleed;
}


//QgsSVGFillSymbolLayer

QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QString& svgFilePath, double width, double angle ): QgsImageFillSymbolLayer(), mPatternWidth( width ),
Expand Down Expand Up @@ -1302,6 +1323,7 @@ void QgsSVGFillSymbolLayer::setDefaultSvgParams()
}
}


QgsLinePatternFillSymbolLayer::QgsLinePatternFillSymbolLayer(): QgsImageFillSymbolLayer(), mDistanceUnit( QgsSymbolV2::MM ), mLineWidthUnit( QgsSymbolV2::MM ),
mOffsetUnit( QgsSymbolV2::MM )
{
Expand Down Expand Up @@ -1741,6 +1763,7 @@ QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::createFromSld( QDomElement &ele
return sl;
}


////////////////////////

QgsPointPatternFillSymbolLayer::QgsPointPatternFillSymbolLayer(): QgsImageFillSymbolLayer(), mMarkerSymbol( 0 ), mDistanceX( 15 ),
Expand Down Expand Up @@ -2043,6 +2066,12 @@ void QgsPointPatternFillSymbolLayer::applyDataDefinedSettings( const QgsSymbolV2
applyPattern( context, mBrush, distanceX, distanceY, displacementX, displacementY );
}


double QgsPointPatternFillSymbolLayer::estimateMaxBleed() const
{
return 0;
}

//////////////


Expand Down
8 changes: 8 additions & 0 deletions src/core/symbology-ng/qgsfillsymbollayerv2.h
Expand Up @@ -83,6 +83,8 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;

double estimateMaxBleed() const;

protected:
QBrush mBrush;
QBrush mSelBrush;
Expand Down Expand Up @@ -160,6 +162,8 @@ class CORE_EXPORT QgsGradientFillSymbolLayerV2 : public QgsFillSymbolLayerV2

QgsSymbolLayerV2* clone() const;

double estimateMaxBleed() const;

/**Type of gradient, eg linear or radial*/
GradientType gradientType() const { return mGradientType; };
void setGradientType( GradientType gradientType ) { mGradientType = gradientType; };
Expand Down Expand Up @@ -261,6 +265,8 @@ class CORE_EXPORT QgsImageFillSymbolLayer: public QgsFillSymbolLayerV2
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }

double estimateMaxBleed() const;

protected:
QBrush mBrush;
double mNextAngle; // mAngle / data defined angle
Expand Down Expand Up @@ -445,6 +451,8 @@ class CORE_EXPORT QgsPointPatternFillSymbolLayer: public QgsImageFillSymbolLayer

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

double estimateMaxBleed() const;

//getters and setters
double distanceX() const { return mDistanceX; }
void setDistanceX( double d ) { mDistanceX = d; }
Expand Down
11 changes: 10 additions & 1 deletion src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -384,7 +384,10 @@ void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderCon
}
}


double QgsSimpleLineSymbolLayerV2::estimateMaxBleed() const
{
return ( mWidth / 2.0 ) + mOffset;
}

/////////

Expand Down Expand Up @@ -1096,3 +1099,9 @@ QgsSymbolV2::OutputUnit QgsMarkerLineSymbolLayerV2::outputUnit() const
}
return unit;
}

double QgsMarkerLineSymbolLayerV2::estimateMaxBleed() const
{
return ( mMarker->size() / 2.0 ) + mOffset;
}

4 changes: 4 additions & 0 deletions src/core/symbology-ng/qgslinesymbollayerv2.h
Expand Up @@ -63,6 +63,8 @@ class CORE_EXPORT QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;

double estimateMaxBleed() const;

// new stuff

Qt::PenStyle penStyle() const { return mPenStyle; }
Expand Down Expand Up @@ -161,6 +163,8 @@ class CORE_EXPORT QgsMarkerLineSymbolLayerV2 : public QgsLineSymbolLayerV2
virtual void setWidth( double width );
virtual double width() const;

double estimateMaxBleed() const;

// new stuff

bool rotateMarker() const { return mRotateMarker; }
Expand Down
6 changes: 6 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2.h
Expand Up @@ -77,6 +77,12 @@ class CORE_EXPORT QgsSymbolLayerV2
void setLocked( bool locked ) { mLocked = locked; }
bool isLocked() const { return mLocked; }

/**Returns the estimated maximum distance which the layer style will bleed outside
the drawn shape. Eg, polygons drawn with an outline will draw half the width
of the outline outside of the polygon. This amount is estimated, since it may
be affected by data defined symbology rules.*/
virtual double estimateMaxBleed() const { return 0; }

virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit ) { Q_UNUSED( unit ); } //= 0;
virtual QgsSymbolV2::OutputUnit outputUnit() const { return QgsSymbolV2::Mixed; } //= 0;

Expand Down
12 changes: 12 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -505,6 +505,18 @@ QPixmap QgsSymbolLayerV2Utils::symbolPreviewPixmap( QgsSymbolV2* symbol, QSize s
return pixmap;
}

double QgsSymbolLayerV2Utils::estimateMaxSymbolBleed( QgsSymbolV2* symbol )
{
double maxBleed = 0;
for ( int i = 0; i < symbol->symbolLayerCount(); i++ )
{
QgsSymbolLayerV2* layer = symbol->symbolLayer( i );
double layerMaxBleed = layer->estimateMaxBleed();
maxBleed = layerMaxBleed > maxBleed ? layerMaxBleed : maxBleed;
}

return maxBleed;
}

QIcon QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, QgsSymbolV2::OutputUnit u, QSize size )
{
Expand Down
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.h
Expand Up @@ -102,6 +102,9 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
static QPixmap symbolPreviewPixmap( QgsSymbolV2* symbol, QSize size );
static QPixmap colorRampPreviewPixmap( QgsVectorColorRampV2* ramp, QSize size );

/**Returns the maximum estimated bleed for the symbol */
static double estimateMaxSymbolBleed( QgsSymbolV2* symbol );

static QgsSymbolV2* loadSymbol( QDomElement& element );
static QgsSymbolLayerV2* loadSymbolLayer( QDomElement& element );
static QDomElement saveSymbol( QString symbolName, QgsSymbolV2* symbol, QDomDocument& doc );
Expand Down

0 comments on commit b5502b6

Please sign in to comment.