Skip to content
Permalink
Browse files

Improve data defined rotation

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Jun 10, 2011
1 parent 7072290 commit b16f611cc4ee04efa8ef97cd5ef0e7468c032eb3
@@ -4,14 +4,16 @@
#include <QPainter>
#include <QSet>

QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName("circle"), mSymbolWidth(4), mSymbolHeight(3), mRotation(0), mFillColor( Qt::black ), mOutlineColor( Qt::white )
QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName("circle"), mSymbolWidth(4), mSymbolHeight(3),
mFillColor( Qt::black ), mOutlineColor( Qt::white ), mOutlineWidth( 0 )
{
mPen.setColor( mOutlineColor );
mPen.setWidth( 1.0 );
mPen.setJoinStyle( Qt::MiterJoin );
mBrush.setColor( mFillColor );
mBrush.setStyle( Qt::SolidPattern );

mAngle = 0;
mWidthField.first = -1;
mHeightField.first = -1;
mRotationField.first = -1;
@@ -39,9 +41,9 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
{
layer->setSymbolHeight( properties["symbol_height"].toDouble() );
}
if( properties.contains("rotation") )
if( properties.contains("angle") )
{
layer->setRotation( properties["rotation"].toDouble() );
layer->setAngle( properties["angle"].toDouble() );
}
if( properties.contains( "outline_width" ) )
{
@@ -117,22 +119,15 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
return;
}

//priority for rotation: 1. data defined, 2. symbol layer rotation (mRotation), 3. symbol rotation (mAngle)
//priority for rotation: 1. data defined, 2. symbol layer rotation (mAngle)
double rotation = 0.0;
if( mRotationField.first != -1 )
if( f && mRotationField.first != -1 )
{
rotation = f->attributeMap()[mRotationField.first].toDouble();
}
else
else if( !doubleNear( mAngle, 0.0 ) )
{
if( !doubleNear( mRotation, 0.0 ) )
{
rotation = mRotation;
}
else if( !doubleNear( mAngle, 0.0 ) )
{
rotation = mAngle;
}
rotation = mAngle;
}

QMatrix transform;
@@ -182,7 +177,7 @@ QgsStringMap QgsEllipseSymbolLayerV2::properties() const
map["symbol_height"] = QString::number( mSymbolHeight );
map["height_index"] = QString::number( mHeightField.first );
map["height_field"] = mHeightField.second;
map["rotation"] = QString::number( mRotation );
map["angle"] = QString::number( mAngle );
map["rotation_index"] = QString::number( mRotationField.first );
map["rotation_field"] = mRotationField.second;
map["outline_width"] = QString::number( mOutlineWidth );
@@ -262,6 +257,10 @@ QSet<QString> QgsEllipseSymbolLayerV2::usedAttributes() const
{
dataDefinedAttributes.insert( mHeightField.second );
}
if( mRotationField.first != -1 )
{
dataDefinedAttributes.insert( mRotationField.second );
}
if( mOutlineWidthField.first != -1 )
{
dataDefinedAttributes.insert( mOutlineWidthField.second );
@@ -35,9 +35,6 @@ class QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
void setHeightField( int index, const QString& field );
const QPair<int, QString>& heightField() const { return mHeightField; }

void setRotation( double r ){ mRotation = r; }
double rotation() const { return mRotation; }

void setRotationField( int index, const QString& field );
const QPair<int, QString>& rotationField() const { return mRotationField; }

@@ -65,7 +62,6 @@ class QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
QString mSymbolName;
double mSymbolWidth;
double mSymbolHeight;
double mRotation;
QColor mFillColor;
QColor mOutlineColor;
double mOutlineWidth;
@@ -41,7 +41,7 @@ void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
mLayer = static_cast<QgsEllipseSymbolLayerV2*>( layer );
mWidthSpinBox->setValue( mLayer->symbolWidth() );
mHeightSpinBox->setValue( mLayer->symbolHeight() );
mRotationSpinBox->setValue( mLayer->rotation() );
mRotationSpinBox->setValue( mLayer->angle() );
mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );

QList<QListWidgetItem *> symbolItemList = mShapeListWidget->findItems( mLayer->symbolName(), Qt::MatchExactly );
@@ -122,7 +122,7 @@ void QgsEllipseSymbolLayerV2Widget::on_mRotationSpinBox_valueChanged( double d )
{
if( mLayer )
{
mLayer->setRotation( d );
mLayer->setAngle( d );
emit changed();
}
}

0 comments on commit b16f611

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