Skip to content
Permalink
Browse files

Started point pattern fill renderer

  • Loading branch information
mhugent committed Jul 15, 2011
1 parent de74d2f commit 7dc8fbda7aa9625b53fe4ddfec8841e4ef78b2cc
@@ -174,7 +174,14 @@ void QgsImageFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPol

bool QgsImageFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
{
if ( !symbol || symbol->type() != QgsSymbolV2::Line )
if( !symbol ) //unset current outline
{
delete mOutline;
mOutline = 0;
return true;
}

if ( symbol->type() != QgsSymbolV2::Line )
{
delete symbol;
return false;
@@ -499,6 +506,10 @@ void QgsLinePatternFillSymbolLayer::startRender( QgsSymbolV2RenderContext& conte
//set image to mBrush
mBrush.setTextureImage( patternImage );

QTransform brushTransform;
brushTransform.scale( 1.0 / context.renderContext().rasterScaleFactor(), 1.0 / context.renderContext().rasterScaleFactor() );
mBrush.setTransform( brushTransform );

if ( mOutline )
{
mOutline->startRender( context.renderContext() );
@@ -529,6 +540,132 @@ QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::clone() const
return clonedLayer;
}

////////////////////////

QgsPointPatternFillSymbolLayer::QgsPointPatternFillSymbolLayer(): QgsImageFillSymbolLayer(), mMarkerSymbol( 0 ), mDistanceX( 15 ),
mDistanceY( 15 ), mDisplacementX( 0 ), mDisplacementY( 0 )
{
mDistanceX = 15;
mDistanceY = 15;
mDisplacementX = 0;
mDisplacementY = 0;
setSubSymbol( new QgsMarkerSymbolV2() );
QgsImageFillSymbolLayer::setSubSymbol( 0 ); //no outline
}

QgsPointPatternFillSymbolLayer::~QgsPointPatternFillSymbolLayer()
{
}

QgsSymbolLayerV2* QgsPointPatternFillSymbolLayer::create( const QgsStringMap& properties )
{
QgsPointPatternFillSymbolLayer* layer = new QgsPointPatternFillSymbolLayer();
if( properties.contains("distance_x") )
{
layer->setDistanceX( properties["distance_x"].toDouble() );
}
if( properties.contains("distance_y") )
{
layer->setDistanceY( properties["distance_y"].toDouble() );
}
if( properties.contains("displacement_x") )
{
layer->setDisplacementX( properties["displacement_x"].toDouble() );
}
if( properties.contains("displacement_y") )
{
layer->setDisplacementY( properties["displacement_y"].toDouble() );
}
return layer;
}

QString QgsPointPatternFillSymbolLayer::layerType() const
{
return "PointPatternFill";
}

void QgsPointPatternFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
{
double width = context.outputPixelSize( mDistanceX );
double height = context.outputPixelSize( mDistanceY );

QImage patternImage( width, height, QImage::Format_ARGB32 );
patternImage.fill( 0 );


//create render context for image
QgsRenderContext pointRenderContext;

if( mMarkerSymbol )
{
QPainter p( &patternImage );
pointRenderContext.setPainter( &p );
pointRenderContext.setRasterScaleFactor( context.renderContext().rasterScaleFactor() );
pointRenderContext.setScaleFactor( context.renderContext().scaleFactor() );

//mMarkerSymbol->setOutputUnit( context.outputUnit() );
mMarkerSymbol->startRender( pointRenderContext );
mMarkerSymbol->renderPoint( QPointF( 0, 0 ), pointRenderContext );
mMarkerSymbol->renderPoint( QPointF( width, 0 ), pointRenderContext );
mMarkerSymbol->renderPoint( QPointF( 0, height ), pointRenderContext );
mMarkerSymbol->renderPoint( QPointF( width, height ), pointRenderContext );
mMarkerSymbol->stopRender( pointRenderContext );
}

mBrush.setTextureImage( patternImage );
QTransform brushTransform;
brushTransform.scale( 1.0 / context.renderContext().rasterScaleFactor(), 1.0 / context.renderContext().rasterScaleFactor() );
mBrush.setTransform( brushTransform );

if ( mOutline )
{
mOutline->startRender( context.renderContext() );
}
}

void QgsPointPatternFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context )
{
if ( mOutline )
{
mOutline->stopRender( context.renderContext() );
}
}

QgsStringMap QgsPointPatternFillSymbolLayer::properties() const
{
QgsStringMap propertyMap;
propertyMap["distance_x"] = QString::number( mDistanceX );
propertyMap["distance_y"] = QString::number( mDistanceY );
propertyMap["displacement_x"] = QString::number( mDisplacementX );
propertyMap["displacement_y"] = QString::number( mDisplacementY );
return propertyMap;
}

QgsSymbolLayerV2* QgsPointPatternFillSymbolLayer::clone() const
{
QgsSymbolLayerV2* clonedLayer = QgsPointPatternFillSymbolLayer::create( properties() );
if( mMarkerSymbol )
{
clonedLayer->setSubSymbol( mMarkerSymbol->clone() );
}
return clonedLayer;
}

bool QgsPointPatternFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
{
if( !symbol )
{
return false;
}

if(symbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( symbol );
delete mMarkerSymbol;
mMarkerSymbol = markerSymbol;
}
return true;
}

//////////////

@@ -75,8 +75,8 @@ class CORE_EXPORT QgsImageFillSymbolLayer: public QgsFillSymbolLayerV2
virtual ~QgsImageFillSymbolLayer();
void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );

QgsSymbolV2* subSymbol() { return mOutline; }
bool setSubSymbol( QgsSymbolV2* symbol );
virtual QgsSymbolV2* subSymbol() { return mOutline; }
virtual bool setSubSymbol( QgsSymbolV2* symbol );

protected:
QBrush mBrush;
@@ -168,7 +168,46 @@ class CORE_EXPORT QgsLinePatternFillSymbolLayer: public QgsImageFillSymbolLayer
double mAngle;
};

class CORE_EXPORT QgsPointPatternFillSymbolLayer: public QgsImageFillSymbolLayer
{
public:
QgsPointPatternFillSymbolLayer();
~QgsPointPatternFillSymbolLayer();

static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
QString layerType() const;

void startRender( QgsSymbolV2RenderContext& context );

void stopRender( QgsSymbolV2RenderContext& context );

QgsStringMap properties() const;

QgsSymbolLayerV2* clone() const;

//getters and setters
double distanceX() const { return mDistanceX; }
void setDistanceX( double d ) { mDistanceX = d; }

double distanceY() const { return mDistanceY; }
void setDistanceY( double d ) { mDistanceY = d; }

double displacementX() const { return mDisplacementX; }
void setDisplacementX( double d ){ mDisplacementX = d; }

double displacementY() const { return mDisplacementY; }
void setDisplacementY( double d ){ mDisplacementY = d; }

bool setSubSymbol( QgsSymbolV2* symbol );
virtual QgsSymbolV2* subSymbol() { return mMarkerSymbol; }

protected:
QgsMarkerSymbolV2* mMarkerSymbol;
double mDistanceX;
double mDistanceY;
double mDisplacementX;
double mDisplacementY;
};

class CORE_EXPORT QgsCentroidFillSymbolLayerV2 : public QgsFillSymbolLayerV2
{
@@ -32,6 +32,8 @@ QgsSymbolLayerV2Registry::QgsSymbolLayerV2Registry()
QgsCentroidFillSymbolLayerV2::create ) );
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "LinePatternFill", QObject::tr("Line pattern fill"), QgsSymbolV2::Fill,
QgsLinePatternFillSymbolLayer::create ) );
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "PointPatternFill", QObject::tr("Point pattern fill"), QgsSymbolV2::Fill,
QgsPointPatternFillSymbolLayer::create ) );
}

QgsSymbolLayerV2Registry::~QgsSymbolLayerV2Registry()
@@ -994,6 +994,96 @@ void QgsLinePatternFillSymbolLayerWidget::on_mOutlinePushButton_clicked()

/////////////

QgsPointPatternFillSymbolLayerWidget::QgsPointPatternFillSymbolLayerWidget( QWidget* parent ): QgsSymbolLayerV2Widget( parent ), mLayer( 0 )
{
setupUi( this );
updateMarkerIcon();
}

void QgsPointPatternFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* layer)
{
if( !layer || layer->layerType() != "PointPatternFill" )
{
return;
}

mLayer = static_cast<QgsPointPatternFillSymbolLayer*>( layer );
mHorizontalDistanceSpinBox->setValue( mLayer->distanceX() );
mVerticalDistanceSpinBox->setValue( mLayer->distanceY() );
mHorizontalDisplacementSpinBox->setValue( mLayer->displacementX() );
mVerticalDisplacementSpinBox->setValue( mLayer->displacementY() );
updateMarkerIcon();
}

QgsSymbolLayerV2* QgsPointPatternFillSymbolLayerWidget::symbolLayer()
{
return mLayer;
}

void QgsPointPatternFillSymbolLayerWidget::updateMarkerIcon()
{
if ( mLayer )
{
QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mLayer->subSymbol(), mChangeMarkerButton->iconSize() );
mChangeMarkerButton->setIcon( icon );
}
}

void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDistanceSpinBox_valueChanged ( double d )
{
if( mLayer )
{
mLayer->setDistanceX( d );
emit changed();
}
}

void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDistanceSpinBox_valueChanged ( double d )
{
if( mLayer )
{
mLayer->setDistanceY( d );
emit changed();
}
}

void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDisplacementSpinBox_valueChanged ( double d )
{
if( mLayer )
{
mLayer->setDisplacementX( d );
emit changed();
}
}

void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDisplacementSpinBox_valueChanged ( double d )
{
if( mLayer )
{
mLayer->setDisplacementY( d );
emit changed();
}
}

void QgsPointPatternFillSymbolLayerWidget::on_mChangeMarkerButton_clicked()
{
if( !mLayer )
{
return;
}

QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), this );
if ( dlg.exec() == QDialog::Rejected )
{
return;
}

updateMarkerIcon();
emit changed();
}

/////////////

QgsFontMarkerSymbolLayerV2Widget::QgsFontMarkerSymbolLayerV2Widget( QWidget* parent )
: QgsSymbolLayerV2Widget( parent )
{
@@ -288,6 +288,34 @@ class GUI_EXPORT QgsLinePatternFillSymbolLayerWidget : public QgsSymbolLayerV2Wi

//////////

#include "ui_widget_pointpatternfill.h"

class QgsPointPatternFillSymbolLayer;

class GUI_EXPORT QgsPointPatternFillSymbolLayerWidget: public QgsSymbolLayerV2Widget, private Ui::WidgetPointPatternFill
{
Q_OBJECT

public:
QgsPointPatternFillSymbolLayerWidget( QWidget* parent = NULL );
static QgsSymbolLayerV2Widget* create() { return new QgsPointPatternFillSymbolLayerWidget(); }

virtual void setSymbolLayer( QgsSymbolLayerV2* layer);
virtual QgsSymbolLayerV2* symbolLayer();

protected:
QgsPointPatternFillSymbolLayer* mLayer;
void updateMarkerIcon();

private slots:
void on_mHorizontalDistanceSpinBox_valueChanged ( double d );
void on_mVerticalDistanceSpinBox_valueChanged ( double d );
void on_mHorizontalDisplacementSpinBox_valueChanged ( double d );
void on_mVerticalDisplacementSpinBox_valueChanged ( double d );
void on_mChangeMarkerButton_clicked();
};

/////////

#include "ui_widget_fontmarker.h"

@@ -95,6 +95,7 @@ static void _initWidgetFunctions()
_initWidgetFunction( "SVGFill", QgsSVGFillSymbolLayerWidget::create );
_initWidgetFunction( "CentroidFill", QgsCentroidFillSymbolLayerV2Widget::create );
_initWidgetFunction( "LinePatternFill", QgsLinePatternFillSymbolLayerWidget::create );
_initWidgetFunction( "PointPatternFill", QgsPointPatternFillSymbolLayerWidget::create );

initialized = true;
}

0 comments on commit 7dc8fbd

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