Skip to content
Permalink
Browse files

remove line decoration symbol layer (fixes #8379)

  • Loading branch information
jef-n committed Aug 22, 2013
1 parent 7f8b259 commit aaef9478004e27d3b77c356deca0091bcb86b249
@@ -138,41 +138,3 @@ class QgsMarkerLineSymbolLayerV2 : QgsLineSymbolLayerV2
void renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context );
void renderPolylineCentral( const QPolygonF& points, QgsSymbolV2RenderContext& context );
};

/////////

class QgsLineDecorationSymbolLayerV2 : QgsLineSymbolLayerV2
{
%TypeHeaderCode
#include <qgslinesymbollayerv2.h>
%End

public:
QgsLineDecorationSymbolLayerV2( QColor color = DEFAULT_LINEDECORATION_COLOR,
double width = DEFAULT_LINEDECORATION_WIDTH );

~QgsLineDecorationSymbolLayerV2();

// static stuff

static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ) /Factory/;

// implemented from base classes

QString layerType() const;

void startRender( QgsSymbolV2RenderContext& context );

void stopRender( QgsSymbolV2RenderContext& context );

void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );

QgsStringMap properties() const;

QgsSymbolLayerV2* clone() const /Factory/;

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

void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;
};
@@ -24,9 +24,7 @@ class QgsSymbolLayerV2
break;

case QgsSymbolV2::Line:
if (dynamic_cast<QgsLineDecorationSymbolLayerV2*>(sipCpp) != NULL)
sipClass = sipClass_QgsLineDecorationSymbolLayerV2;
else if (dynamic_cast<QgsMarkerLineSymbolLayerV2*>(sipCpp) != NULL)
if (dynamic_cast<QgsMarkerLineSymbolLayerV2*>(sipCpp) != NULL)
sipClass = sipClass_QgsMarkerLineSymbolLayerV2;
else if (dynamic_cast<QgsSimpleLineSymbolLayerV2*>(sipCpp) != NULL)
sipClass = sipClass_QgsSimpleLineSymbolLayerV2;
@@ -183,29 +183,6 @@ class QgsSvgMarkerSymbolLayerV2Widget : QgsSymbolLayerV2Widget

///////////

class QgsLineDecorationSymbolLayerV2Widget : QgsSymbolLayerV2Widget
{
%TypeHeaderCode
#include <qgssymbollayerv2widget.h>
%End

public:
QgsLineDecorationSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent = NULL );

static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) /Factory/;

// from base class
virtual void setSymbolLayer( QgsSymbolLayerV2* layer );
virtual QgsSymbolLayerV2* symbolLayer();

public slots:
void colorChanged( const QColor& color );
void penWidthChanged();
void on_mWidthUnitComboBox_currentIndexChanged( int index );
};

//////////

class QgsSVGFillSymbolLayerWidget : QgsSymbolLayerV2Widget
{
%TypeHeaderCode
@@ -1086,155 +1086,3 @@ QgsSymbolV2::OutputUnit QgsMarkerLineSymbolLayerV2::outputUnit() const
}
return unit;
}

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

QgsLineDecorationSymbolLayerV2::QgsLineDecorationSymbolLayerV2( QColor color, double width )
{
mColor = color;
mWidth = width;
}

QgsLineDecorationSymbolLayerV2::~QgsLineDecorationSymbolLayerV2()
{
}

QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2::create( const QgsStringMap& props )
{
QColor color = DEFAULT_LINEDECORATION_COLOR;
double width = DEFAULT_LINEDECORATION_WIDTH;

if ( props.contains( "color" ) )
color = QgsSymbolLayerV2Utils::decodeColor( props["color"] );
if ( props.contains( "width" ) )
width = props["width"].toDouble();


QgsLineDecorationSymbolLayerV2* layer = new QgsLineDecorationSymbolLayerV2( color, width );
if ( props.contains( "width_unit" ) )
{
layer->setWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["width_unit"] ) );
}
return layer;
}

QString QgsLineDecorationSymbolLayerV2::layerType() const
{
return "LineDecoration";
}

void QgsLineDecorationSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
{
QColor penColor = mColor;
penColor.setAlphaF( mColor.alphaF() * context.alpha() );

double width = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
mPen.setWidth( width );
mPen.setColor( penColor );
QColor selColor = context.renderContext().selectionColor();
if ( ! selectionIsOpaque )
selColor.setAlphaF( context.alpha() );
mSelPen.setWidth( width ); //context.outputLineWidth( width ) );
mSelPen.setColor( selColor );
}

void QgsLineDecorationSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
{
Q_UNUSED( context );
}

void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
{
// draw arrow at the end of line

QPainter* p = context.renderContext().painter();
if ( !p )
{
return;
}

int cnt = points.count();
if ( cnt < 2 )
{
return;
}
QPointF p2 = points.at( --cnt );
QPointF p1 = points.at( --cnt );
while ( p2 == p1 && cnt )
p1 = points.at( --cnt );
if ( p1 == p2 )
{
// this is a collapsed line... don't bother drawing an arrow
// with arbitrary orientation
return;
}

double angle = atan2( p2.y() - p1.y(), p2.x() - p1.x() );
double size = ( mWidth * 8 ) * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
double angle1 = angle + M_PI / 6;
double angle2 = angle - M_PI / 6;

QPointF p2_1 = p2 - QPointF( size * cos( angle1 ), size * sin( angle1 ) );
QPointF p2_2 = p2 - QPointF( size * cos( angle2 ), size * sin( angle2 ) );

p->setPen( context.selected() ? mSelPen : mPen );
p->drawLine( p2, p2_1 );
p->drawLine( p2, p2_2 );
}

QgsStringMap QgsLineDecorationSymbolLayerV2::properties() const
{
QgsStringMap map;
map["color"] = QgsSymbolLayerV2Utils::encodeColor( mColor );
map["width"] = QString::number( mWidth );
map["width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mWidthUnit );
return map;
}

QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2::clone() const
{
QgsLineDecorationSymbolLayerV2* layer = new QgsLineDecorationSymbolLayerV2( mColor, mWidth );
layer->setWidthUnit( mWidthUnit );
return layer;
}

void QgsLineDecorationSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
{
QDomElement symbolizerElem = doc.createElement( "se:LineSymbolizer" );
if ( !props.value( "uom", "" ).isEmpty() )
symbolizerElem.setAttribute( "uom", props.value( "uom", "" ) );
element.appendChild( symbolizerElem );

QgsSymbolLayerV2Utils::createGeometryElement( doc, symbolizerElem, props.value( "geom" , "" ) );

// <Stroke>
QDomElement strokeElem = doc.createElement( "se:Stroke" );
symbolizerElem.appendChild( strokeElem );

// <GraphicStroke>
QDomElement graphicStrokeElem = doc.createElement( "se:GraphicStroke" );
strokeElem.appendChild( graphicStrokeElem );

// <Graphic>
QDomElement graphicElem = doc.createElement( "se:Graphic" );
graphicStrokeElem.appendChild( graphicElem );

// <Mark>
QgsSymbolLayerV2Utils::wellKnownMarkerToSld( doc, graphicElem, "arrowhead", QColor(), mColor, mWidth, mWidth*8 );

// <Rotation>
QgsSymbolLayerV2Utils::createRotationElement( doc, graphicElem, props.value( "angle", "" ) );

// use <VendorOption> to draw the decoration at end of the line
symbolizerElem.appendChild( QgsSymbolLayerV2Utils::createVendorOptionElement( doc, "placement", "lastPoint" ) );
}

void QgsLineDecorationSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
{
mWidthUnit = unit;
}

QgsSymbolV2::OutputUnit QgsLineDecorationSymbolLayerV2::outputUnit() const
{
return mWidthUnit;
}
@@ -200,46 +200,4 @@ class CORE_EXPORT QgsMarkerLineSymbolLayerV2 : public QgsLineSymbolLayerV2
Placement mPlacement;
};

/////////

#define DEFAULT_LINEDECORATION_COLOR QColor(0,0,0)
#define DEFAULT_LINEDECORATION_WIDTH DEFAULT_LINE_WIDTH

class CORE_EXPORT QgsLineDecorationSymbolLayerV2 : public QgsLineSymbolLayerV2
{
public:
QgsLineDecorationSymbolLayerV2( QColor color = DEFAULT_LINEDECORATION_COLOR,
double width = DEFAULT_LINEDECORATION_WIDTH );

~QgsLineDecorationSymbolLayerV2();

// static stuff

static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );

// implemented from base classes

QString layerType() const;

void startRender( QgsSymbolV2RenderContext& context );

void stopRender( QgsSymbolV2RenderContext& context );

void renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context );

QgsStringMap properties() const;

QgsSymbolLayerV2* clone() const;

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

void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;

protected:
QPen mPen;
QPen mSelPen;

};

#endif
@@ -30,8 +30,6 @@ QgsSymbolLayerV2Registry::QgsSymbolLayerV2Registry()
QgsSimpleLineSymbolLayerV2::create, QgsSimpleLineSymbolLayerV2::createFromSld ) );
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "MarkerLine", QObject::tr( "Marker line" ), QgsSymbolV2::Line,
QgsMarkerLineSymbolLayerV2::create, QgsMarkerLineSymbolLayerV2::createFromSld ) );
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "LineDecoration", QObject::tr( "Line decoration" ), QgsSymbolV2::Line,
QgsLineDecorationSymbolLayerV2::create ) );

addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleMarker", QObject::tr( "Simple marker" ), QgsSymbolV2::Marker,
QgsSimpleMarkerSymbolLayerV2::create, QgsSimpleMarkerSymbolLayerV2::createFromSld ) );
@@ -59,7 +59,6 @@ static void _initWidgetFunctions()

_initWidgetFunction( "SimpleLine", QgsSimpleLineSymbolLayerV2Widget::create );
_initWidgetFunction( "MarkerLine", QgsMarkerLineSymbolLayerV2Widget::create );
_initWidgetFunction( "LineDecoration", QgsLineDecorationSymbolLayerV2Widget::create );

_initWidgetFunction( "SimpleMarker", QgsSimpleMarkerSymbolLayerV2Widget::create );
_initWidgetFunction( "SvgMarker", QgsSvgMarkerSymbolLayerV2Widget::create );
@@ -1151,63 +1151,6 @@ void QgsSvgMarkerSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
}
}

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

QgsLineDecorationSymbolLayerV2Widget::QgsLineDecorationSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent )
: QgsSymbolLayerV2Widget( parent, vl )
{
mLayer = NULL;

setupUi( this );

connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( colorChanged( const QColor& ) ) );
connect( spinWidth, SIGNAL( valueChanged( double ) ), this, SLOT( penWidthChanged() ) );
}

void QgsLineDecorationSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
{
if ( layer->layerType() != "LineDecoration" )
return;

// layer type is correct, we can do the cast
mLayer = static_cast<QgsLineDecorationSymbolLayerV2*>( layer );

// set values
btnChangeColor->setColor( mLayer->color() );
btnChangeColor->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
spinWidth->setValue( mLayer->width() );

mWidthUnitComboBox->blockSignals( true );
mWidthUnitComboBox->setCurrentIndex( mLayer->widthUnit() );
mWidthUnitComboBox->blockSignals( false );
}

QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2Widget::symbolLayer()
{
return mLayer;
}

void QgsLineDecorationSymbolLayerV2Widget::colorChanged( const QColor& color )
{
mLayer->setColor( color );
emit changed();
}

void QgsLineDecorationSymbolLayerV2Widget::penWidthChanged()
{
mLayer->setWidth( spinWidth->value() );
emit changed();
}

void QgsLineDecorationSymbolLayerV2Widget::on_mWidthUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setWidthUnit(( QgsSymbolV2::OutputUnit ) index );
}
emit changed();
}

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

#include <QFileDialog>

0 comments on commit aaef947

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