Skip to content

Commit 7dc8fbd

Browse files
committedJul 15, 2011
Started point pattern fill renderer
1 parent de74d2f commit 7dc8fbd

File tree

7 files changed

+394
-3
lines changed

7 files changed

+394
-3
lines changed
 

‎src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,14 @@ void QgsImageFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPol
174174

175175
bool QgsImageFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
176176
{
177-
if ( !symbol || symbol->type() != QgsSymbolV2::Line )
177+
if( !symbol ) //unset current outline
178+
{
179+
delete mOutline;
180+
mOutline = 0;
181+
return true;
182+
}
183+
184+
if ( symbol->type() != QgsSymbolV2::Line )
178185
{
179186
delete symbol;
180187
return false;
@@ -499,6 +506,10 @@ void QgsLinePatternFillSymbolLayer::startRender( QgsSymbolV2RenderContext& conte
499506
//set image to mBrush
500507
mBrush.setTextureImage( patternImage );
501508

509+
QTransform brushTransform;
510+
brushTransform.scale( 1.0 / context.renderContext().rasterScaleFactor(), 1.0 / context.renderContext().rasterScaleFactor() );
511+
mBrush.setTransform( brushTransform );
512+
502513
if ( mOutline )
503514
{
504515
mOutline->startRender( context.renderContext() );
@@ -529,6 +540,132 @@ QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::clone() const
529540
return clonedLayer;
530541
}
531542

543+
////////////////////////
544+
545+
QgsPointPatternFillSymbolLayer::QgsPointPatternFillSymbolLayer(): QgsImageFillSymbolLayer(), mMarkerSymbol( 0 ), mDistanceX( 15 ),
546+
mDistanceY( 15 ), mDisplacementX( 0 ), mDisplacementY( 0 )
547+
{
548+
mDistanceX = 15;
549+
mDistanceY = 15;
550+
mDisplacementX = 0;
551+
mDisplacementY = 0;
552+
setSubSymbol( new QgsMarkerSymbolV2() );
553+
QgsImageFillSymbolLayer::setSubSymbol( 0 ); //no outline
554+
}
555+
556+
QgsPointPatternFillSymbolLayer::~QgsPointPatternFillSymbolLayer()
557+
{
558+
}
559+
560+
QgsSymbolLayerV2* QgsPointPatternFillSymbolLayer::create( const QgsStringMap& properties )
561+
{
562+
QgsPointPatternFillSymbolLayer* layer = new QgsPointPatternFillSymbolLayer();
563+
if( properties.contains("distance_x") )
564+
{
565+
layer->setDistanceX( properties["distance_x"].toDouble() );
566+
}
567+
if( properties.contains("distance_y") )
568+
{
569+
layer->setDistanceY( properties["distance_y"].toDouble() );
570+
}
571+
if( properties.contains("displacement_x") )
572+
{
573+
layer->setDisplacementX( properties["displacement_x"].toDouble() );
574+
}
575+
if( properties.contains("displacement_y") )
576+
{
577+
layer->setDisplacementY( properties["displacement_y"].toDouble() );
578+
}
579+
return layer;
580+
}
581+
582+
QString QgsPointPatternFillSymbolLayer::layerType() const
583+
{
584+
return "PointPatternFill";
585+
}
586+
587+
void QgsPointPatternFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
588+
{
589+
double width = context.outputPixelSize( mDistanceX );
590+
double height = context.outputPixelSize( mDistanceY );
591+
592+
QImage patternImage( width, height, QImage::Format_ARGB32 );
593+
patternImage.fill( 0 );
594+
595+
596+
//create render context for image
597+
QgsRenderContext pointRenderContext;
598+
599+
if( mMarkerSymbol )
600+
{
601+
QPainter p( &patternImage );
602+
pointRenderContext.setPainter( &p );
603+
pointRenderContext.setRasterScaleFactor( context.renderContext().rasterScaleFactor() );
604+
pointRenderContext.setScaleFactor( context.renderContext().scaleFactor() );
605+
606+
//mMarkerSymbol->setOutputUnit( context.outputUnit() );
607+
mMarkerSymbol->startRender( pointRenderContext );
608+
mMarkerSymbol->renderPoint( QPointF( 0, 0 ), pointRenderContext );
609+
mMarkerSymbol->renderPoint( QPointF( width, 0 ), pointRenderContext );
610+
mMarkerSymbol->renderPoint( QPointF( 0, height ), pointRenderContext );
611+
mMarkerSymbol->renderPoint( QPointF( width, height ), pointRenderContext );
612+
mMarkerSymbol->stopRender( pointRenderContext );
613+
}
614+
615+
mBrush.setTextureImage( patternImage );
616+
QTransform brushTransform;
617+
brushTransform.scale( 1.0 / context.renderContext().rasterScaleFactor(), 1.0 / context.renderContext().rasterScaleFactor() );
618+
mBrush.setTransform( brushTransform );
619+
620+
if ( mOutline )
621+
{
622+
mOutline->startRender( context.renderContext() );
623+
}
624+
}
625+
626+
void QgsPointPatternFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context )
627+
{
628+
if ( mOutline )
629+
{
630+
mOutline->stopRender( context.renderContext() );
631+
}
632+
}
633+
634+
QgsStringMap QgsPointPatternFillSymbolLayer::properties() const
635+
{
636+
QgsStringMap propertyMap;
637+
propertyMap["distance_x"] = QString::number( mDistanceX );
638+
propertyMap["distance_y"] = QString::number( mDistanceY );
639+
propertyMap["displacement_x"] = QString::number( mDisplacementX );
640+
propertyMap["displacement_y"] = QString::number( mDisplacementY );
641+
return propertyMap;
642+
}
643+
644+
QgsSymbolLayerV2* QgsPointPatternFillSymbolLayer::clone() const
645+
{
646+
QgsSymbolLayerV2* clonedLayer = QgsPointPatternFillSymbolLayer::create( properties() );
647+
if( mMarkerSymbol )
648+
{
649+
clonedLayer->setSubSymbol( mMarkerSymbol->clone() );
650+
}
651+
return clonedLayer;
652+
}
653+
654+
bool QgsPointPatternFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
655+
{
656+
if( !symbol )
657+
{
658+
return false;
659+
}
660+
661+
if(symbol->type() == QgsSymbolV2::Marker )
662+
{
663+
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( symbol );
664+
delete mMarkerSymbol;
665+
mMarkerSymbol = markerSymbol;
666+
}
667+
return true;
668+
}
532669

533670
//////////////
534671

‎src/core/symbology-ng/qgsfillsymbollayerv2.h

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class CORE_EXPORT QgsImageFillSymbolLayer: public QgsFillSymbolLayerV2
7575
virtual ~QgsImageFillSymbolLayer();
7676
void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );
7777

78-
QgsSymbolV2* subSymbol() { return mOutline; }
79-
bool setSubSymbol( QgsSymbolV2* symbol );
78+
virtual QgsSymbolV2* subSymbol() { return mOutline; }
79+
virtual bool setSubSymbol( QgsSymbolV2* symbol );
8080

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

171+
class CORE_EXPORT QgsPointPatternFillSymbolLayer: public QgsImageFillSymbolLayer
172+
{
173+
public:
174+
QgsPointPatternFillSymbolLayer();
175+
~QgsPointPatternFillSymbolLayer();
176+
177+
static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
178+
QString layerType() const;
179+
180+
void startRender( QgsSymbolV2RenderContext& context );
181+
182+
void stopRender( QgsSymbolV2RenderContext& context );
183+
184+
QgsStringMap properties() const;
171185

186+
QgsSymbolLayerV2* clone() const;
187+
188+
//getters and setters
189+
double distanceX() const { return mDistanceX; }
190+
void setDistanceX( double d ) { mDistanceX = d; }
191+
192+
double distanceY() const { return mDistanceY; }
193+
void setDistanceY( double d ) { mDistanceY = d; }
194+
195+
double displacementX() const { return mDisplacementX; }
196+
void setDisplacementX( double d ){ mDisplacementX = d; }
197+
198+
double displacementY() const { return mDisplacementY; }
199+
void setDisplacementY( double d ){ mDisplacementY = d; }
200+
201+
bool setSubSymbol( QgsSymbolV2* symbol );
202+
virtual QgsSymbolV2* subSymbol() { return mMarkerSymbol; }
203+
204+
protected:
205+
QgsMarkerSymbolV2* mMarkerSymbol;
206+
double mDistanceX;
207+
double mDistanceY;
208+
double mDisplacementX;
209+
double mDisplacementY;
210+
};
172211

173212
class CORE_EXPORT QgsCentroidFillSymbolLayerV2 : public QgsFillSymbolLayerV2
174213
{

‎src/core/symbology-ng/qgssymbollayerv2registry.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ QgsSymbolLayerV2Registry::QgsSymbolLayerV2Registry()
3232
QgsCentroidFillSymbolLayerV2::create ) );
3333
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "LinePatternFill", QObject::tr("Line pattern fill"), QgsSymbolV2::Fill,
3434
QgsLinePatternFillSymbolLayer::create ) );
35+
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "PointPatternFill", QObject::tr("Point pattern fill"), QgsSymbolV2::Fill,
36+
QgsPointPatternFillSymbolLayer::create ) );
3537
}
3638

3739
QgsSymbolLayerV2Registry::~QgsSymbolLayerV2Registry()

‎src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,96 @@ void QgsLinePatternFillSymbolLayerWidget::on_mOutlinePushButton_clicked()
994994

995995
/////////////
996996

997+
QgsPointPatternFillSymbolLayerWidget::QgsPointPatternFillSymbolLayerWidget( QWidget* parent ): QgsSymbolLayerV2Widget( parent ), mLayer( 0 )
998+
{
999+
setupUi( this );
1000+
updateMarkerIcon();
1001+
}
1002+
1003+
void QgsPointPatternFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* layer)
1004+
{
1005+
if( !layer || layer->layerType() != "PointPatternFill" )
1006+
{
1007+
return;
1008+
}
1009+
1010+
mLayer = static_cast<QgsPointPatternFillSymbolLayer*>( layer );
1011+
mHorizontalDistanceSpinBox->setValue( mLayer->distanceX() );
1012+
mVerticalDistanceSpinBox->setValue( mLayer->distanceY() );
1013+
mHorizontalDisplacementSpinBox->setValue( mLayer->displacementX() );
1014+
mVerticalDisplacementSpinBox->setValue( mLayer->displacementY() );
1015+
updateMarkerIcon();
1016+
}
1017+
1018+
QgsSymbolLayerV2* QgsPointPatternFillSymbolLayerWidget::symbolLayer()
1019+
{
1020+
return mLayer;
1021+
}
1022+
1023+
void QgsPointPatternFillSymbolLayerWidget::updateMarkerIcon()
1024+
{
1025+
if ( mLayer )
1026+
{
1027+
QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mLayer->subSymbol(), mChangeMarkerButton->iconSize() );
1028+
mChangeMarkerButton->setIcon( icon );
1029+
}
1030+
}
1031+
1032+
void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDistanceSpinBox_valueChanged ( double d )
1033+
{
1034+
if( mLayer )
1035+
{
1036+
mLayer->setDistanceX( d );
1037+
emit changed();
1038+
}
1039+
}
1040+
1041+
void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDistanceSpinBox_valueChanged ( double d )
1042+
{
1043+
if( mLayer )
1044+
{
1045+
mLayer->setDistanceY( d );
1046+
emit changed();
1047+
}
1048+
}
1049+
1050+
void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDisplacementSpinBox_valueChanged ( double d )
1051+
{
1052+
if( mLayer )
1053+
{
1054+
mLayer->setDisplacementX( d );
1055+
emit changed();
1056+
}
1057+
}
1058+
1059+
void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDisplacementSpinBox_valueChanged ( double d )
1060+
{
1061+
if( mLayer )
1062+
{
1063+
mLayer->setDisplacementY( d );
1064+
emit changed();
1065+
}
1066+
}
1067+
1068+
void QgsPointPatternFillSymbolLayerWidget::on_mChangeMarkerButton_clicked()
1069+
{
1070+
if( !mLayer )
1071+
{
1072+
return;
1073+
}
1074+
1075+
QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), this );
1076+
if ( dlg.exec() == QDialog::Rejected )
1077+
{
1078+
return;
1079+
}
1080+
1081+
updateMarkerIcon();
1082+
emit changed();
1083+
}
1084+
1085+
/////////////
1086+
9971087
QgsFontMarkerSymbolLayerV2Widget::QgsFontMarkerSymbolLayerV2Widget( QWidget* parent )
9981088
: QgsSymbolLayerV2Widget( parent )
9991089
{

‎src/gui/symbology-ng/qgssymbollayerv2widget.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,34 @@ class GUI_EXPORT QgsLinePatternFillSymbolLayerWidget : public QgsSymbolLayerV2Wi
288288

289289
//////////
290290

291+
#include "ui_widget_pointpatternfill.h"
292+
293+
class QgsPointPatternFillSymbolLayer;
294+
295+
class GUI_EXPORT QgsPointPatternFillSymbolLayerWidget: public QgsSymbolLayerV2Widget, private Ui::WidgetPointPatternFill
296+
{
297+
Q_OBJECT
298+
299+
public:
300+
QgsPointPatternFillSymbolLayerWidget( QWidget* parent = NULL );
301+
static QgsSymbolLayerV2Widget* create() { return new QgsPointPatternFillSymbolLayerWidget(); }
302+
303+
virtual void setSymbolLayer( QgsSymbolLayerV2* layer);
304+
virtual QgsSymbolLayerV2* symbolLayer();
305+
306+
protected:
307+
QgsPointPatternFillSymbolLayer* mLayer;
308+
void updateMarkerIcon();
309+
310+
private slots:
311+
void on_mHorizontalDistanceSpinBox_valueChanged ( double d );
312+
void on_mVerticalDistanceSpinBox_valueChanged ( double d );
313+
void on_mHorizontalDisplacementSpinBox_valueChanged ( double d );
314+
void on_mVerticalDisplacementSpinBox_valueChanged ( double d );
315+
void on_mChangeMarkerButton_clicked();
316+
};
317+
318+
/////////
291319

292320
#include "ui_widget_fontmarker.h"
293321

‎src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static void _initWidgetFunctions()
9595
_initWidgetFunction( "SVGFill", QgsSVGFillSymbolLayerWidget::create );
9696
_initWidgetFunction( "CentroidFill", QgsCentroidFillSymbolLayerV2Widget::create );
9797
_initWidgetFunction( "LinePatternFill", QgsLinePatternFillSymbolLayerWidget::create );
98+
_initWidgetFunction( "PointPatternFill", QgsPointPatternFillSymbolLayerWidget::create );
9899

99100
initialized = true;
100101
}

0 commit comments

Comments
 (0)
Please sign in to comment.