Skip to content
Permalink
Browse files

Add method for estimating the maximum amount a symbol bleeds out of t…

…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 b5502b6307c688a6a55b6b740ad8fe60e179f71b
@@ -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,
@@ -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 )
@@ -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 ),
@@ -1302,6 +1323,7 @@ void QgsSVGFillSymbolLayer::setDefaultSvgParams()
}
}


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


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

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


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

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


@@ -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;
@@ -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; };
@@ -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
@@ -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; }
@@ -384,7 +384,10 @@ void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderCon
}
}


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

/////////

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

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

@@ -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; }
@@ -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; }
@@ -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;

@@ -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 )
{
@@ -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 );

0 comments on commit b5502b6

Please sign in to comment.
You can’t perform that action at this time.