Skip to content
Permalink
Browse files

Cleaner handling of dxf symbology and linestyles

  • Loading branch information
mhugent committed Jan 10, 2014
1 parent 1d3dd1b commit f847a268ad17732b0097c84380e4ca718c65495f
@@ -884,7 +884,7 @@ void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, cons
{
c = colorFromSymbolLayer( symbolLayer );
}
double width = widthFromSymbolLayer( symbolLayer );
double width = symbolLayer->dxfWidth( *this );;
QString lineStyleName = "CONTINUOUS";
if ( mSymbologyExport != NoSymbology )
{
@@ -981,26 +981,10 @@ int QgsDxfExport::colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer )
return 0;
}

QColor c = symbolLayer->color();
QColor c = symbolLayer->dxfColor();
return closestColorMatch( c.rgba() );
}

double QgsDxfExport::widthFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer ) const
{
//line symbol layer has width and width units
if ( symbolLayer && symbolLayer->type() == QgsSymbolV2::Line )
{
const QgsLineSymbolLayerV2* lineSymbolLayer = static_cast<const QgsLineSymbolLayerV2*>( symbolLayer );
return ( lineSymbolLayer->width() * mapUnitScaleFactor( mSymbologyScaleDenominator, lineSymbolLayer->widthUnit(), mMapUnits ) );
}

return 1.0;

//marker symbol layer: check for embedded line layers?

//mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits )
}

QString QgsDxfExport::lineStyleFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer )
{
QString lineStyleName = "CONTINUOUS";
@@ -1016,17 +1000,7 @@ QString QgsDxfExport::lineStyleFromSymbolLayer( const QgsSymbolLayerV2* symbolLa
}
else
{
//simple line and simple fill have pen style member
if ( symbolLayer->layerType() == "SimpleLine" )
{
const QgsSimpleLineSymbolLayerV2* sl = static_cast< const QgsSimpleLineSymbolLayerV2* >( symbolLayer );
return lineNameFromPenStyle( sl->penStyle() );
}
else if ( symbolLayer->layerType() == "SimpleFill" )
{
const QgsSimpleFillSymbolLayerV2* sf = static_cast< const QgsSimpleFillSymbolLayerV2* >( symbolLayer );
return lineNameFromPenStyle( sf->borderStyle() );
}
return lineNameFromPenStyle( symbolLayer->dxfPenStyle() );
}
return lineStyleName;
}
@@ -1212,18 +1186,13 @@ void QgsDxfExport::writeSymbolLayerLinestyle( const QgsSymbolLayerV2* symbolLaye
return;
}

//QgsSimpleLineSymbolLayer can have customDashVector() / customDashPatternUnit()
const QgsSimpleLineSymbolLayerV2* simpleLine = dynamic_cast< const QgsSimpleLineSymbolLayerV2* >( symbolLayer );
if ( simpleLine )
QgsSymbolV2::OutputUnit unit;
QVector<qreal> customLinestyle = symbolLayer->dxfCustomDashPattern( unit );
if ( customLinestyle.size() < 0 )
{
if ( simpleLine->useCustomDashPattern() )
{
++mSymbolLayerCounter;
QString name = QString( "symbolLayer%1" ).arg( mSymbolLayerCounter );
QVector<qreal> dashPattern = simpleLine->customDashVector();
writeLinestyle( name, dashPattern, simpleLine->customDashPatternUnit() );
mLineStyles.insert( symbolLayer, name );
}
QString name = QString( "symbolLayer%1" ).arg( mSymbolLayerCounter );
writeLinestyle( name, customLinestyle, unit );
mLineStyles.insert( symbolLayer, name );
}
}

@@ -83,6 +83,8 @@ class CORE_EXPORT QgsDxfExport

void writeCircle( const QString& layer, int color, const QgsPoint& pt, double radius );

static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );

private:

QList< QgsMapLayer* > mLayers;
@@ -140,7 +142,6 @@ class CORE_EXPORT QgsDxfExport

//returns dxf palette index from symbol layer color
static int colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer );
double widthFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer ) const;
QString lineStyleFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer );

//functions for dxf palette
@@ -151,7 +152,7 @@ class CORE_EXPORT QgsDxfExport
QgsRenderContext renderContext() const;
void startRender( QgsVectorLayer* vl ) const;
void stopRender( QgsVectorLayer* vl ) const;
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );

QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > symbolLayers();
static int nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> >& symbolLayers );
static bool hasDataDefinedProperties( const QgsSymbolLayerV2* sl, const QgsSymbolV2* symbol );
@@ -15,7 +15,7 @@
#include "qgsfillsymbollayerv2.h"
#include "qgsmarkersymbollayerv2.h"
#include "qgssymbollayerv2utils.h"

#include "qgsdxfexport.h"
#include "qgsexpression.h"
#include "qgsrendercontext.h"
#include "qgsproject.h"
@@ -289,6 +289,28 @@ double QgsSimpleFillSymbolLayerV2::estimateMaxBleed() const
return penBleed + offsetBleed;
}

double QgsSimpleFillSymbolLayerV2::dxfWidth( const QgsDxfExport& e ) const
{
return mBorderWidth * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mBorderWidthUnit, e.mapUnits() );
}

QColor QgsSimpleFillSymbolLayerV2::dxfColor() const
{
if ( mBrushStyle == Qt::NoBrush )
{
return mBorderColor;
}
else
{
return mColor;
}
}

Qt::PenStyle QgsSimpleFillSymbolLayerV2::dxfPenStyle() const
{
return mBorderStyle;
}

//QgsGradientFillSymbolLayer

QgsGradientFillSymbolLayerV2::QgsGradientFillSymbolLayerV2( QColor color, QColor color2,
@@ -836,6 +858,35 @@ double QgsImageFillSymbolLayer::estimateMaxBleed() const
return subLayerBleed;
}

double QgsImageFillSymbolLayer::dxfWidth( const QgsDxfExport& e ) const
{
return mOutlineWidth * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits() );
}

QColor QgsImageFillSymbolLayer::dxfColor() const
{
if ( !mOutline )
{
return QColor( Qt::black );
}
return mOutline->color();
}

Qt::PenStyle QgsImageFillSymbolLayer::dxfPenStyle() const
{
return Qt::SolidLine;
#if 0
if ( !mOutline )
{
return Qt::SolidLine;
}
else
{
return mOutline->dxfPenStyle();
}
#endif //0
}


//QgsSVGFillSymbolLayer

@@ -85,6 +85,10 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2

double estimateMaxBleed() const;

double dxfWidth( const QgsDxfExport& e ) const;
QColor dxfColor() const;
Qt::PenStyle dxfPenStyle() const;

protected:
QBrush mBrush;
QBrush mSelBrush;
@@ -269,6 +273,10 @@ class CORE_EXPORT QgsImageFillSymbolLayer: public QgsFillSymbolLayerV2

double estimateMaxBleed() const;

virtual double dxfWidth( const QgsDxfExport& e ) const;
virtual QColor dxfColor() const;
virtual Qt::PenStyle dxfPenStyle() const;

protected:
QBrush mBrush;
double mNextAngle; // mAngle / data defined angle
@@ -389,6 +389,12 @@ double QgsSimpleLineSymbolLayerV2::estimateMaxBleed() const
return ( mWidth / 2.0 ) + mOffset;
}

QVector<qreal> QgsSimpleLineSymbolLayerV2::dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const
{
unit = mCustomDashPatternUnit;
return mUseCustomDashPattern ? mCustomDashVector : QVector<qreal>() ;
}

/////////


@@ -91,6 +91,8 @@ class CORE_EXPORT QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
QVector<qreal> customDashVector() const { return mCustomDashVector; }
void setCustomDashVector( const QVector<qreal>& vector ) { mCustomDashVector = vector; }

QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;

protected:
Qt::PenStyle mPenStyle;
Qt::PenJoinStyle mPenJoinStyle;
@@ -94,6 +94,27 @@ bool QgsSymbolLayerV2::writeDxf( QgsDxfExport& e,
return false;
}

double QgsSymbolLayerV2::dxfWidth( const QgsDxfExport& e ) const
{
Q_UNUSED( e );
return 1.0;
}

QColor QgsSymbolLayerV2::dxfColor() const
{
return color();
}

QVector<qreal> QgsSymbolLayerV2::dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const
{
Q_UNUSED( unit );
return QVector<qreal>();
}

Qt::PenStyle QgsSymbolLayerV2::dxfPenStyle() const
{
return Qt::SolidLine;
}

void QgsSymbolLayerV2::prepareExpressions( const QgsVectorLayer* vl, double scale )
{
@@ -342,6 +363,11 @@ void QgsLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<
}
}

double QgsLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e ) const
{
return ( width() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() ) );
}


void QgsFillSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
{
@@ -107,6 +107,13 @@ class CORE_EXPORT QgsSymbolLayerV2
const QgsFeature* f,
const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;

virtual double dxfWidth( const QgsDxfExport& e ) const;

virtual QColor dxfColor() const;

virtual QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;
virtual Qt::PenStyle dxfPenStyle() const;

protected:
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false )
: mType( type ), mLocked( locked ), mRenderingPass( 0 ) {}
@@ -235,6 +242,8 @@ class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2

void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );

virtual double dxfWidth( const QgsDxfExport& e ) const;

protected:
QgsLineSymbolLayerV2( bool locked = false );

0 comments on commit f847a26

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