Skip to content
Permalink
Browse files

[FEATURE]: Add point and line pattern symbol layers

  • Loading branch information
marco
marco committed Jul 28, 2011
2 parents a1cc666 + a5f8a82 commit 4a34e9d4174bb402f053217e051d4f81d9e1cfbd

Large diffs are not rendered by default.

@@ -67,9 +67,29 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
QPointF mOffset;
};

/**Base class for polygon renderers generating texture images*/
class CORE_EXPORT QgsImageFillSymbolLayer: public QgsFillSymbolLayerV2
{
public:
QgsImageFillSymbolLayer();
virtual ~QgsImageFillSymbolLayer();
void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );

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

protected:
QBrush mBrush;

/**Outline width*/
double mOutlineWidth;
/**Custom outline*/
QgsLineSymbolV2* mOutline;
};

/**A class for svg fill patterns. The class automatically scales the pattern to
the appropriate pixel dimensions of the output device*/
class CORE_EXPORT QgsSVGFillSymbolLayer: public QgsFillSymbolLayerV2
class CORE_EXPORT QgsSVGFillSymbolLayer: public QgsImageFillSymbolLayer
{
public:
QgsSVGFillSymbolLayer( const QString& svgFilePath = "", double width = 20, double rotation = 0.0 );
@@ -85,8 +105,6 @@ class CORE_EXPORT QgsSVGFillSymbolLayer: public QgsFillSymbolLayerV2
void startRender( QgsSymbolV2RenderContext& context );
void stopRender( QgsSymbolV2RenderContext& context );

void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context );

QgsStringMap properties() const;

QgsSymbolLayerV2* clone() const;
@@ -97,9 +115,6 @@ class CORE_EXPORT QgsSVGFillSymbolLayer: public QgsFillSymbolLayerV2
void setPatternWidth( double width ) { mPatternWidth = width;}
double patternWidth() const { return mPatternWidth; }

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

protected:
/**Width of the pattern (in QgsSymbolV2 output units)*/
double mPatternWidth;
@@ -109,19 +124,90 @@ class CORE_EXPORT QgsSVGFillSymbolLayer: public QgsFillSymbolLayerV2
QString mSvgFilePath;
/**SVG view box (to keep the aspect ratio */
QRectF mSvgViewBox;
/**Brush that receives rendered pixel image in startRender() method*/
QBrush mBrush;
/**Outline width*/
double mOutlineWidth;
/**Custom outline*/
QgsLineSymbolV2* mOutline;

private:
/**Helper function that gets the view box from the byte array*/
void storeViewBox();
};

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

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
void setAngle( double a ){ mAngle = a; }
double angle() const { return mAngle; }
void setDistance( double d ){ mDistance = d; }
double distance() const { return mDistance; }
void setLineWidth( double w ){ mLineWidth = w; }
double lineWidth() const { return mLineWidth; }
void setColor( const QColor& c ){ mColor = c; }
QColor color() const{ return mColor; }

protected:
/**Distance (in mm or map units) between lines*/
double mDistance;
/**Line width (in mm or map units)*/
double mLineWidth;
QColor mColor;
//todo: line type
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
{
@@ -33,6 +33,10 @@ QgsSymbolLayerV2Registry::QgsSymbolLayerV2Registry()
QgsSVGFillSymbolLayer::create ) );
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "CentroidFill", QObject::tr( "Centroid fill" ), QgsSymbolV2::Fill,
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()
@@ -910,6 +910,183 @@ void QgsSVGFillSymbolLayerWidget::updateOutlineIcon()

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

QgsLinePatternFillSymbolLayerWidget::QgsLinePatternFillSymbolLayerWidget( const QgsVectorLayer* vl, QWidget* parent ):
QgsSymbolLayerV2Widget( parent, vl ), mLayer( 0 )
{
setupUi( this );
}

void QgsLinePatternFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* layer)
{
if( layer->layerType() != "LinePatternFill" )
{
return;
}

QgsLinePatternFillSymbolLayer* patternLayer = static_cast<QgsLinePatternFillSymbolLayer*>( layer );
if( patternLayer )
{
mLayer = patternLayer;
mAngleSpinBox->setValue( mLayer->angle() );
mDistanceSpinBox->setValue( mLayer->distance() );
mLineWidthSpinBox->setValue( mLayer->lineWidth() );
}
}

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

void QgsLinePatternFillSymbolLayerWidget::on_mAngleSpinBox_valueChanged( double d )
{
if( mLayer )
{
mLayer->setAngle( d );
emit changed();
}
}

void QgsLinePatternFillSymbolLayerWidget::on_mDistanceSpinBox_valueChanged( double d )
{
if( mLayer )
{
mLayer->setDistance( d );
emit changed();
}
}

void QgsLinePatternFillSymbolLayerWidget::on_mLineWidthSpinBox_valueChanged( double d )
{
if( mLayer )
{
mLayer->setLineWidth( d );
emit changed();
}
}

void QgsLinePatternFillSymbolLayerWidget::on_mColorPushButton_clicked()
{
if( mLayer )
{
QColor c = QColorDialog::getColor( mLayer->color() );
if( c.isValid() )
{
mLayer->setColor( c );
emit changed();
}
}
}

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

//updateOutlineIcon();
emit changed();
}
}

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

QgsPointPatternFillSymbolLayerWidget::QgsPointPatternFillSymbolLayerWidget( const QgsVectorLayer* vl, QWidget* parent ):
QgsSymbolLayerV2Widget( parent, vl ), 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(), mVectorLayer, this );
if ( dlg.exec() == QDialog::Rejected )
{
return;
}

updateMarkerIcon();
emit changed();
}

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

QgsFontMarkerSymbolLayerV2Widget::QgsFontMarkerSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent )
: QgsSymbolLayerV2Widget( parent, vl )
{

0 comments on commit 4a34e9d

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