Skip to content
Permalink
Browse files

Fix preview with data defined settings, indentation

  • Loading branch information
mhugent committed Jun 15, 2011
1 parent 3213d3d commit 2f3fb2800a2a83635e42d90b16c1a2a15bdf4197
Showing with 68 additions and 50 deletions.
  1. +49 −49 src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
  2. +19 −1 src/ui/symbollayer/widget_ellipse.ui
@@ -4,8 +4,8 @@
#include <QPainter>
#include <QSet>

QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName("circle"), mSymbolWidth(4), mSymbolHeight(3),
mFillColor( Qt::black ), mOutlineColor( Qt::white ), mOutlineWidth( 0 )
QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName( "circle" ), mSymbolWidth( 4 ), mSymbolHeight( 3 ),
mFillColor( Qt::black ), mOutlineColor( Qt::white ), mOutlineWidth( 0 )
{
mPen.setColor( mOutlineColor );
mPen.setWidth( 1.0 );
@@ -30,61 +30,61 @@ QgsEllipseSymbolLayerV2::~QgsEllipseSymbolLayerV2()
QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& properties )
{
QgsEllipseSymbolLayerV2* layer = new QgsEllipseSymbolLayerV2();
if( properties.contains( "symbol_name" ) )
if ( properties.contains( "symbol_name" ) )
{
layer->setSymbolName( properties[ "symbol_name" ] );
}
if( properties.contains( "symbol_width" ) )
if ( properties.contains( "symbol_width" ) )
{
layer->setSymbolWidth( properties["symbol_width"].toDouble() );
}
if( properties.contains("symbol_height") )
if ( properties.contains( "symbol_height" ) )
{
layer->setSymbolHeight( properties["symbol_height"].toDouble() );
}
if( properties.contains("angle") )
if ( properties.contains( "angle" ) )
{
layer->setAngle( properties["angle"].toDouble() );
}
if( properties.contains( "outline_width" ) )
if ( properties.contains( "outline_width" ) )
{
layer->setOutlineWidth( properties["outline_width"].toDouble() );
}
if( properties.contains( "fill_color" ) )
if ( properties.contains( "fill_color" ) )
{
layer->setFillColor( QgsSymbolLayerV2Utils::decodeColor( properties["fill_color"] ) );
}
if( properties.contains( "outline_color" ) )
if ( properties.contains( "outline_color" ) )
{
layer->setOutlineColor( QgsSymbolLayerV2Utils::decodeColor( properties["outline_color"] ) );
}

//data defined properties
if( properties.contains( "height_index" ) && properties.contains( "height_field") )
if ( properties.contains( "height_index" ) && properties.contains( "height_field" ) )
{
layer->setHeightField( properties["height_index"].toInt(), properties["height_field"] );
}
if( properties.contains( "width_index") && properties.contains("width_field") )
if ( properties.contains( "width_index" ) && properties.contains( "width_field" ) )
{
layer->setWidthField( properties["width_index"].toInt(), properties["width_field"]);
layer->setWidthField( properties["width_index"].toInt(), properties["width_field"] );
}
if( properties.contains( "rotation_index" ) && properties.contains("rotation_field") )
if ( properties.contains( "rotation_index" ) && properties.contains( "rotation_field" ) )
{
layer->setRotationField( properties["rotation_index"].toInt(), properties["rotation_field"] );
}
if( properties.contains("outline_width_index") && properties.contains("outline_width_field") )
if ( properties.contains( "outline_width_index" ) && properties.contains( "outline_width_field" ) )
{
layer->setOutlineWidthField( properties["outline_width_index"].toInt(), properties["outline_width_field"] );
}
if( properties.contains("fill_color_index") && properties.contains("fill_color_field") )
if ( properties.contains( "fill_color_index" ) && properties.contains( "fill_color_field" ) )
{
layer->setFillColorField( properties["fill_color_index"].toInt(), properties["fill_color_field"] );
}
if( properties.contains("outline_color_index") && properties.contains("outline_color_field") )
if ( properties.contains( "outline_color_index" ) && properties.contains( "outline_color_field" ) )
{
layer->setOutlineColorField( properties["outline_color_index"].toInt(), properties["outline_color_field"] );
}
if( properties.contains("symbol_name_index") && properties.contains("symbol_name_field") )
if ( properties.contains( "symbol_name_index" ) && properties.contains( "symbol_name_field" ) )
{
layer->setSymbolNameField( properties["symbol_name_index"].toInt(), properties["symbol_name_field"] );
}
@@ -96,49 +96,49 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
{
const QgsFeature* f = context.feature();

if( f )
if ( f )
{
if( mOutlineWidthField.first != -1 )
if ( mOutlineWidthField.first != -1 )
{
double width = context.outputLineWidth( f->attributeMap()[mOutlineWidthField.first].toDouble() );
mPen.setWidth( width );
}
if( mFillColorField.first != -1 )
if ( mFillColorField.first != -1 )
{
mBrush.setColor( QColor( f->attributeMap()[mFillColorField.first].toString() ) );
}
if( mOutlineColorField.first != -1 )
if ( mOutlineColorField.first != -1 )
{
mPen.setColor( QColor( f->attributeMap()[mOutlineColorField.first].toString() ) );
}

if( mWidthField.first != -1 || mHeightField.first != -1 || mSymbolNameField.first != -1 )
if ( mWidthField.first != -1 || mHeightField.first != -1 || mSymbolNameField.first != -1 )
{
QString symbolName = ( mSymbolNameField.first == -1 ) ? mSymbolName : f->attributeMap()[mSymbolNameField.first].toString();
preparePath( symbolName, context, f );
}
}

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

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

QMatrix transform;
transform.translate( point.x(), point.y() );
if( !doubleNear( rotation, 0.0 ) )
if ( !doubleNear( rotation, 0.0 ) )
{
transform.rotate( rotation );
}
@@ -155,7 +155,7 @@ QString QgsEllipseSymbolLayerV2::layerType() const

void QgsEllipseSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
{
if( !hasDataDefinedProperty() )
if ( !context.feature() || !hasDataDefinedProperty() )
{
preparePath( mSymbolName, context );
}
@@ -176,7 +176,7 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::clone() const
QgsStringMap QgsEllipseSymbolLayerV2::properties() const
{
QgsStringMap map;
map["symbol_name"] = mSymbolName;
map["symbol_name"] = mSymbolName;
map["symbol_width"] = QString::number( mSymbolWidth );
map["width_index"] = QString::number( mWidthField.first );
map["width_field"] = mWidthField.second;
@@ -195,23 +195,23 @@ QgsStringMap QgsEllipseSymbolLayerV2::properties() const
map["outline_color"] = QgsSymbolLayerV2Utils::encodeColor( mOutlineColor );
map["outline_color_index"] = QString::number( mOutlineColorField.first );
map["outline_color_field"] = mOutlineColorField.second;
map["symbol_name_index"] = QString::number(mSymbolNameField.first);
map["symbol_name_index"] = QString::number( mSymbolNameField.first );
map["symbol_name_field"] = mSymbolNameField.second;
return map;
}

bool QgsEllipseSymbolLayerV2::hasDataDefinedProperty() const
{
return ( mWidthField.first != -1 || mHeightField.first != -1 || mOutlineWidthField.first != -1
|| mFillColorField.first != -1 || mOutlineColorField.first != -1 );
return ( mWidthField.first != -1 || mHeightField.first != -1 || mOutlineWidthField.first != -1
|| mFillColorField.first != -1 || mOutlineColorField.first != -1 );
}

void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV2RenderContext& context, const QgsFeature* f )
{
mPainterPath = QPainterPath();

double width = 0;
if( f && mWidthField.first != -1 )
if ( f && mWidthField.first != -1 )
{
width = context.outputLineWidth( f->attributeMap()[mWidthField.first].toDouble() );
}
@@ -221,7 +221,7 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
}

double height = 0;
if( f && mHeightField.first != -1 )
if ( f && mHeightField.first != -1 )
{
height = context.outputLineWidth( f->attributeMap()[mHeightField.first].toDouble() );
}
@@ -230,22 +230,22 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
height = context.outputLineWidth( mSymbolHeight );
}

if( symbolName == "circle" )
if ( symbolName == "circle" )
{
mPainterPath.addEllipse( QRectF( -width / 2.0, -height / 2.0, width, height ) );
}
else if( symbolName == "rectangle" )
else if ( symbolName == "rectangle" )
{
mPainterPath.addRect( QRectF( -width / 2.0, -height / 2.0, width, height ) );
}
else if( symbolName == "cross" )
else if ( symbolName == "cross" )
{
mPainterPath.moveTo( 0, -height / 2.0 );
mPainterPath.lineTo( 0, height / 2.0 );
mPainterPath.moveTo( -width / 2.0, 0 );
mPainterPath.lineTo( width / 2.0, 0 );
}
else if( symbolName == "triangle" )
else if ( symbolName == "triangle" )
{
mPainterPath.moveTo( 0, -height / 2.0 );
mPainterPath.lineTo( -width / 2.0, height / 2.0 );
@@ -257,31 +257,31 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
QSet<QString> QgsEllipseSymbolLayerV2::usedAttributes() const
{
QSet<QString> dataDefinedAttributes;
if( mWidthField.first != -1 )
if ( mWidthField.first != -1 )
{
dataDefinedAttributes.insert( mWidthField.second );
}
if( mHeightField.first != -1 )
if ( mHeightField.first != -1 )
{
dataDefinedAttributes.insert( mHeightField.second );
}
if( mRotationField.first != -1 )
if ( mRotationField.first != -1 )
{
dataDefinedAttributes.insert( mRotationField.second );
}
if( mOutlineWidthField.first != -1 )
if ( mOutlineWidthField.first != -1 )
{
dataDefinedAttributes.insert( mOutlineWidthField.second );
}
if( mFillColorField.first != -1 )
if ( mFillColorField.first != -1 )
{
dataDefinedAttributes.insert( mFillColorField.second );
}
if( mOutlineColorField.first != -1 )
if ( mOutlineColorField.first != -1 )
{
dataDefinedAttributes.insert( mOutlineColorField.second );
}
if( mSymbolNameField.first != -1 )
if ( mSymbolNameField.first != -1 )
{
dataDefinedAttributes.insert( mSymbolNameField.second );
}
@@ -306,11 +306,11 @@ void QgsEllipseSymbolLayerV2::setHeightField( int index, const QString& field )
mHeightField.second = field;
}

void QgsEllipseSymbolLayerV2::setRotationField( int index, const QString& field )
{
mRotationField.first = index;
mRotationField.second = field;
}
void QgsEllipseSymbolLayerV2::setRotationField( int index, const QString& field )
{
mRotationField.first = index;
mRotationField.second = field;
}

void QgsEllipseSymbolLayerV2::setOutlineWidthField( int index, const QString& field )
{
@@ -106,23 +106,41 @@
<item row="6" column="0" colspan="2">
<widget class="QListWidget" name="mShapeListWidget">
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
<enum>QAbstractItemView::DropOnly</enum>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="spacing">
<number>4</number>
</property>
<property name="gridSize">
<size>
<width>30</width>
<height>24</height>
</size>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="selectionRectVisible">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">

0 comments on commit 2f3fb28

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