Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Outline width for simple marker
  • Loading branch information
mhugent committed Apr 4, 2013
1 parent e7f8c5f commit 518f235
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 67 deletions.
59 changes: 55 additions & 4 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -48,7 +48,8 @@ static QPointF _rotatedOffset( const QPointF& offset, double angle )
//////

QgsSimpleMarkerSymbolLayerV2::QgsSimpleMarkerSymbolLayerV2( QString name, QColor color, QColor borderColor, double size, double angle, QgsSymbolV2::ScaleMethod scaleMethod )
: mNameExpression( 0 ), mColorExpression( 0 ), mColorBorderExpression( 0 ), mSizeExpression( 0 ), mAngleExpression( 0 ), mOffsetExpression( 0 )
: mOutlineWidth( 0 ), mOutlineWidthUnit( QgsSymbolV2::MM ), mNameExpression( 0 ), mColorExpression( 0 ), mColorBorderExpression( 0 ), mOutlineWidthExpression( 0 ),
mSizeExpression( 0 ), mAngleExpression( 0 ), mOffsetExpression( 0 )
{
mName = name;
mColor = color;
Expand Down Expand Up @@ -91,6 +92,15 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::create( const QgsStringMap& prop
if ( props.contains( "size_unit" ) )
m->setSizeUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["size_unit"] ) );

if ( props.contains( "outline_width" ) )
{
m->setOutlineWidth( props["outline_width"].toDouble() );
}
if ( props.contains( "outline_width_unit" ) )
{
m->setOutlineWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["outline_width_unit"] ) );
}

//data defined properties
if ( props.contains( "name_expression" ) )
{
Expand All @@ -104,6 +114,10 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::create( const QgsStringMap& prop
{
m->setDataDefinedProperty( "color_border", props["color_border_expression"] );
}
if ( props.contains( "outline_width_expression" ) )
{
m->setDataDefinedProperty( "outline_width", props["outline_width_expression"] );
}
if ( props.contains( "size_expression" ) )
{
m->setDataDefinedProperty( "size", props["size_expression"] );
Expand Down Expand Up @@ -135,7 +149,7 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex

mBrush = QBrush( brushColor );
mPen = QPen( penColor );
mPen.setWidthF( context.outputLineWidth( mPen.widthF() ) );
mPen.setWidthF( mOutlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) );

QColor selBrushColor = context.selectionColor();
QColor selPenColor = selBrushColor == mColor ? selBrushColor : mBorderColor;
Expand All @@ -146,7 +160,7 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
}
mSelBrush = QBrush( selBrushColor );
mSelPen = QPen( selPenColor );
mSelPen.setWidthF( context.outputLineWidth( mPen.widthF() ) );
mSelPen.setWidthF( mOutlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) );

bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation;
bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || mSizeExpression;
Expand All @@ -155,7 +169,8 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
// - size, rotation, shape, color, border color is not data-defined
// - drawing to screen (not printer)
mUsingCache = !hasDataDefinedRotation && !hasDataDefinedSize && !context.renderContext().forceVectorOutput()
&& !mNameExpression && !mColorExpression && !mColorBorderExpression && !mSizeExpression && !mAngleExpression;
&& !mNameExpression && !mColorExpression && !mColorBorderExpression && !mOutlineWidthExpression &&
!mSizeExpression && !mAngleExpression;

// use either QPolygonF or QPainterPath for drawing
// TODO: find out whether drawing directly doesn't bring overhead - if not, use it for all shapes
Expand Down Expand Up @@ -517,6 +532,13 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
if ( mColorBorderExpression )
{
mPen.setColor( QgsSymbolLayerV2Utils::decodeColor( mColorBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
mSelPen.setColor( QgsSymbolLayerV2Utils::decodeColor( mColorBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
}
if ( mOutlineWidthExpression )
{
double outlineWidth = mOutlineWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
mPen.setWidthF( outlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) );
mSelPen.setWidthF( outlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) );
}

p->setBrush( context.selected() ? mSelBrush : mBrush );
Expand All @@ -542,6 +564,8 @@ QgsStringMap QgsSimpleMarkerSymbolLayerV2::properties() const
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
map["scale_method"] = QgsSymbolLayerV2Utils::encodeScaleMethod( mScaleMethod );
map["outline_width"] = QString::number( mOutlineWidth );
map["outline_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOutlineWidthUnit );

//data define properties
if ( mNameExpression )
Expand All @@ -556,6 +580,10 @@ QgsStringMap QgsSimpleMarkerSymbolLayerV2::properties() const
{
map["color_border_expression"] = mColorBorderExpression->dump();
}
if ( mOutlineWidthExpression )
{
map["outline_width_expression"] = mOutlineWidthExpression->dump();
}
if ( mSizeExpression )
{
map["size_expression"] = mSizeExpression->dump();
Expand All @@ -577,6 +605,8 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::clone() const
m->setOffset( mOffset );
m->setSizeUnit( mSizeUnit );
m->setOffsetUnit( mOffsetUnit );
m->setOutlineWidth( mOutlineWidth );
m->setOutlineWidthUnit( mOutlineWidthUnit );

//data defined properties
if ( mNameExpression )
Expand All @@ -591,6 +621,10 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::clone() const
{
m->setDataDefinedProperty( "color_border", mColorBorderExpression->dump() );
}
if ( mOutlineWidthExpression )
{
m->setDataDefinedProperty( "outline_width", mOutlineWidthExpression->dump() );
}
if ( mSizeExpression )
{
m->setDataDefinedProperty( "size", mSizeExpression->dump() );
Expand Down Expand Up @@ -708,6 +742,10 @@ const QgsExpression* QgsSimpleMarkerSymbolLayerV2::dataDefinedProperty( const QS
{
return mColorBorderExpression;
}
else if ( property == "outline_width" )
{
return mOutlineWidthExpression;
}
else if ( property == "size" )
{
return mSizeExpression;
Expand Down Expand Up @@ -743,6 +781,10 @@ void QgsSimpleMarkerSymbolLayerV2::setDataDefinedProperty( const QString& proper
{
delete mColorBorderExpression; mColorBorderExpression = new QgsExpression( expressionString );
}
else if ( property == "outline_width" )
{
delete mOutlineWidthExpression; mOutlineWidthExpression = new QgsExpression( expressionString );
}
else if ( property == "size" )
{
delete mSizeExpression; mSizeExpression = new QgsExpression( expressionString );
Expand Down Expand Up @@ -771,6 +813,10 @@ void QgsSimpleMarkerSymbolLayerV2::removeDataDefinedProperty( const QString& pro
{
delete mColorBorderExpression; mColorBorderExpression = 0;
}
else if ( property == "outline_width" )
{
delete mOutlineWidthExpression; mOutlineWidthExpression = 0;
}
else if ( property == "size" )
{
delete mSizeExpression; mSizeExpression = 0;
Expand All @@ -790,6 +836,7 @@ void QgsSimpleMarkerSymbolLayerV2::removeDataDefinedProperties()
delete mNameExpression; mNameExpression = 0;
delete mColorExpression; mColorExpression = 0;
delete mColorBorderExpression; mColorBorderExpression = 0;
delete mOutlineWidthExpression; mOutlineWidthExpression = 0;
delete mSizeExpression; mSizeExpression = 0;
delete mAngleExpression; mAngleExpression = 0;
delete mOffsetExpression; mOffsetExpression = 0;
Expand All @@ -807,6 +854,8 @@ QSet<QString> QgsSimpleMarkerSymbolLayerV2::usedAttributes() const
columns.append( mColorExpression->referencedColumns() );
if ( mColorBorderExpression )
columns.append( mColorBorderExpression->referencedColumns() );
if ( mOutlineWidthExpression )
columns.append( mOutlineWidthExpression->referencedColumns() );
if ( mSizeExpression )
columns.append( mSizeExpression->referencedColumns() );
if ( mAngleExpression )
Expand Down Expand Up @@ -884,6 +933,8 @@ void QgsSimpleMarkerSymbolLayerV2::prepareExpressions( const QgsVectorLayer* vl
mColorExpression->prepare( fields );
if ( mColorBorderExpression )
mColorBorderExpression->prepare( fields );
if ( mOutlineWidthExpression )
mOutlineWidthExpression->prepare( fields );
if ( mSizeExpression )
mSizeExpression->prepare( fields );
if ( mAngleExpression )
Expand Down
9 changes: 9 additions & 0 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.h
Expand Up @@ -71,6 +71,12 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
QColor borderColor() const { return mBorderColor; }
void setBorderColor( QColor color ) { mBorderColor = color; }

double outlineWidth() const { return mOutlineWidth; }
void setOutlineWidth( double w ) { mOutlineWidth = w; }

QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; }

const QgsExpression* dataDefinedProperty( const QString& property ) const;
QString dataDefinedPropertyString( const QString& property ) const;
void setDataDefinedProperty( const QString& property, const QString& expressionString );
Expand All @@ -89,6 +95,8 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
void prepareCache( QgsSymbolV2RenderContext& context );

QColor mBorderColor;
double mOutlineWidth;
QgsSymbolV2::OutputUnit mOutlineWidthUnit;
QPen mPen;
QBrush mBrush;
QPolygonF mPolygon;
Expand All @@ -104,6 +112,7 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
QgsExpression* mNameExpression;
QgsExpression* mColorExpression;
QgsExpression* mColorBorderExpression;
QgsExpression* mOutlineWidthExpression;
QgsExpression* mSizeExpression;
QgsExpression* mAngleExpression;
QgsExpression* mOffsetExpression;
Expand Down
2 changes: 0 additions & 2 deletions src/core/symbology-ng/qgssymbollayerv2.cpp
Expand Up @@ -23,8 +23,6 @@
#include <QPointF>
#include <QPolygonF>



QgsMarkerSymbolLayerV2::QgsMarkerSymbolLayerV2( bool locked )
: QgsSymbolLayerV2( QgsSymbolV2::Marker, locked ), mSizeUnit( QgsSymbolV2::MM ), mOffsetUnit( QgsSymbolV2::MM )
{
Expand Down
23 changes: 23 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -298,6 +298,7 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer
btnChangeColorFill->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
spinSize->setValue( mLayer->size() );
spinAngle->setValue( mLayer->angle() );
mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );

// without blocking signals the value gets changed because of slot setOffset()
spinOffsetX->blockSignals( true );
Expand All @@ -313,6 +314,9 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer
mOffsetUnitComboBox->blockSignals( true );
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
mOffsetUnitComboBox->blockSignals( false );
mOutlineWidthUnitComboBox->blockSignals( true );
mOutlineWidthUnitComboBox->setCurrentIndex( mLayer->outlineWidthUnit() );
mOutlineWidthUnitComboBox->blockSignals( false );
}

QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2Widget::symbolLayer()
Expand Down Expand Up @@ -356,6 +360,15 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setOffset()
emit changed();
}

void QgsSimpleMarkerSymbolLayerV2Widget::on_mOutlineWidthSpinBox_valueChanged( double d )
{
if ( mLayer )
{
mLayer->setOutlineWidth( d );
emit changed();
}
}

void QgsSimpleMarkerSymbolLayerV2Widget::on_mSizeUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
Expand All @@ -374,6 +387,15 @@ void QgsSimpleMarkerSymbolLayerV2Widget::on_mOffsetUnitComboBox_currentIndexChan
}
}

void QgsSimpleMarkerSymbolLayerV2Widget::on_mOutlineWidthUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setOutlineWidthUnit(( QgsSymbolV2::OutputUnit ) index );
emit changed();
}
}

void QgsSimpleMarkerSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
{
if ( !mLayer )
Expand All @@ -385,6 +407,7 @@ void QgsSimpleMarkerSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked
dataDefinedProperties.insert( "name", qMakePair( tr( "Name" ), mLayer->dataDefinedPropertyString( "name" ) ) );
dataDefinedProperties.insert( "color", qMakePair( tr( "Fill color" ), mLayer->dataDefinedPropertyString( "color" ) ) );
dataDefinedProperties.insert( "color_border", qMakePair( tr( "Border color" ), mLayer->dataDefinedPropertyString( "color_border" ) ) );
dataDefinedProperties.insert( "outline_width", qMakePair( tr( "Outline width" ), mLayer->dataDefinedPropertyString( "outline_width" ) ) );
dataDefinedProperties.insert( "size", qMakePair( tr( "Size" ), mLayer->dataDefinedPropertyString( "size" ) ) );
dataDefinedProperties.insert( "angle", qMakePair( tr( "Angle" ), mLayer->dataDefinedPropertyString( "angle" ) ) );
dataDefinedProperties.insert( "offset", qMakePair( tr( "Offset" ), mLayer->dataDefinedPropertyString( "offset" ) ) );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Expand Up @@ -107,7 +107,9 @@ class GUI_EXPORT QgsSimpleMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Wid
void setOffset();
void on_mSizeUnitComboBox_currentIndexChanged( int index );
void on_mOffsetUnitComboBox_currentIndexChanged( int index );
void on_mOutlineWidthUnitComboBox_currentIndexChanged( int index );
void on_mDataDefinedPropertiesButton_clicked();
void on_mOutlineWidthSpinBox_valueChanged( double d );

protected:
QgsSimpleMarkerSymbolLayerV2* mLayer;
Expand Down

0 comments on commit 518f235

Please sign in to comment.