Skip to content

Commit

Permalink
Forgot to add support for data defined shape
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jun 15, 2011
1 parent b16f611 commit aafd837
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
34 changes: 26 additions & 8 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mFillColor( Qt::black ), mOutlineColor( Qt::white ), mOutlineWidth( 0 )
mOutlineWidthField.first = -1;
mFillColorField.first = -1;
mOutlineColorField.first = -1;
mSymbolNameField.first = -1;
}

QgsEllipseSymbolLayerV2::~QgsEllipseSymbolLayerV2()
Expand Down Expand Up @@ -83,6 +84,10 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
{
layer->setOutlineColorField( properties["outline_color_index"].toInt(), properties["outline_color_field"] );
}
if( properties.contains("symbol_name_index") && properties.contains("symbol_name_field") )
{
layer->setSymbolNameField( properties["symbol_name_index"].toInt(), properties["symbol_name_field"] );
}

return layer;
}
Expand All @@ -107,9 +112,10 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
mPen.setColor( QColor( f->attributeMap()[mOutlineColorField.first].toString() ) );
}

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

Expand Down Expand Up @@ -151,7 +157,7 @@ void QgsEllipseSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
{
if( !hasDataDefinedProperty() )
{
preparePath( context );
preparePath( mSymbolName, context );
}
mPen.setColor( mOutlineColor );
mPen.setWidth( context.outputLineWidth( mOutlineWidth ) );
Expand Down Expand Up @@ -189,6 +195,8 @@ 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_field"] = mSymbolNameField.second;
return map;
}

Expand All @@ -198,7 +206,7 @@ bool QgsEllipseSymbolLayerV2::hasDataDefinedProperty() const
|| mFillColorField.first != -1 || mOutlineColorField.first != -1 );
}

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

Expand All @@ -222,22 +230,22 @@ void QgsEllipseSymbolLayerV2::preparePath( QgsSymbolV2RenderContext& context, co
height = context.outputLineWidth( mSymbolHeight );
}

if( mSymbolName == "circle" )
if( symbolName == "circle" )
{
mPainterPath.addEllipse( QRectF( -width / 2.0, -height / 2.0, width, height ) );
}
else if( mSymbolName == "rectangle" )
else if( symbolName == "rectangle" )
{
mPainterPath.addRect( QRectF( -width / 2.0, -height / 2.0, width, height ) );
}
else if( mSymbolName == "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( mSymbolName == "triangle" )
else if( symbolName == "triangle" )
{
mPainterPath.moveTo( 0, -height / 2.0 );
mPainterPath.lineTo( -width / 2.0, height / 2.0 );
Expand Down Expand Up @@ -273,9 +281,19 @@ QSet<QString> QgsEllipseSymbolLayerV2::usedAttributes() const
{
dataDefinedAttributes.insert( mOutlineColorField.second );
}
if( mSymbolNameField.first != -1 )
{
dataDefinedAttributes.insert( mSymbolNameField.second );
}
return dataDefinedAttributes;
}

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

void QgsEllipseSymbolLayerV2::setWidthField( int index, const QString& field )
{
mWidthField.first = index;
Expand Down
10 changes: 7 additions & 3 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
void setSymbolName( const QString& name ){ mSymbolName = name; }
QString symbolName() const{ return mSymbolName; }

void setSymbolNameField( int index, const QString& field );
const QPair<int, QString>& symbolNameField() const { return mSymbolNameField; }

void setSymbolWidth( double w ){ mSymbolWidth = w; }
double symbolWidth() const { return mSymbolWidth; }

Expand Down Expand Up @@ -74,20 +77,21 @@ class QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
QPair<int, QString> mRotationField;
/**Take outline width from attribute (-1 if fixed outline width)*/
QPair<int, QString> mOutlineWidthField;

/**Take fill color from attribute (-1 if fixed fill color)*/
QPair<int, QString> mFillColorField;

/**Take outline color from attribute (-1 if fixed outline color)*/
QPair<int, QString> mOutlineColorField;
/**Take shape name from attribute (-1 if fixed shape type)*/
QPair<int, QString> mSymbolNameField;

QPainterPath mPainterPath;

QPen mPen;
QBrush mBrush;

/**Setup mPainterPath
@param feature to render (0 if no data defined rendering)*/
void preparePath( QgsSymbolV2RenderContext& context, const QgsFeature* f = 0 );
void preparePath( const QString& symbolName, QgsSymbolV2RenderContext& context, const QgsFeature* f = 0 );

/**True if this symbol layer uses a data defined property*/
bool hasDataDefinedProperty() const;
Expand Down
9 changes: 8 additions & 1 deletion src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
{
mDDOutlineColorComboBox->setCurrentIndex( mDDOutlineColorComboBox->findText( mLayer->outlineColorField().second ) );
}
if( mLayer->symbolNameField().first != -1 )
{
mDDShapeComboBox->setCurrentIndex( mDDShapeComboBox->findText( mLayer->symbolNameField().second ) );
}
}
blockComboSignals( false );
}
Expand Down Expand Up @@ -255,7 +259,10 @@ void QgsEllipseSymbolLayerV2Widget::on_mDDOutlineColorComboBox_currentIndexChang

void QgsEllipseSymbolLayerV2Widget::on_mDDShapeComboBox_currentIndexChanged( int idx )
{
//todo...
if( mLayer )
{
mLayer->setSymbolNameField( mDDShapeComboBox->itemData( idx ).toInt(), mDDShapeComboBox->itemText( idx ) );
}
}

void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block )
Expand Down

0 comments on commit aafd837

Please sign in to comment.