Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve data defined rotation
  • Loading branch information
Marco Hugentobler committed Jun 10, 2011
1 parent 7072290 commit b16f611
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
29 changes: 14 additions & 15 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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" ) )
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 0 additions & 4 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.h
Expand Up @@ -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; }

Expand Down Expand Up @@ -65,7 +62,6 @@ class QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
QString mSymbolName;
double mSymbolWidth;
double mSymbolHeight;
double mRotation;
QColor mFillColor;
QColor mOutlineColor;
double mOutlineWidth;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -122,7 +122,7 @@ void QgsEllipseSymbolLayerV2Widget::on_mRotationSpinBox_valueChanged( double d )
{
if( mLayer )
{
mLayer->setRotation( d );
mLayer->setAngle( d );
emit changed();
}
}
Expand Down

0 comments on commit b16f611

Please sign in to comment.