1
0
mirror of https://github.com/qgis/QGIS.git synced 2025-03-12 00:02:25 -04:00

Added line pattern symbol layer

This commit is contained in:
Marco Hugentobler 2011-07-06 11:18:35 +02:00
parent 91cddd15fb
commit ae176a9a05
7 changed files with 278 additions and 0 deletions

@ -352,6 +352,82 @@ bool QgsSVGFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
return false;
}
QgsLinePatternFillSymbolLayer::QgsLinePatternFillSymbolLayer()
{
}
QgsLinePatternFillSymbolLayer::~QgsLinePatternFillSymbolLayer()
{
}
QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::create( const QgsStringMap& properties )
{
QgsLinePatternFillSymbolLayer* patternLayer = new QgsLinePatternFillSymbolLayer();
//default values
double angle = 45;
double distance = 5;
double lineWidth = 0.5;
QColor color( Qt::black );
if( properties.contains("angle") )
{
angle = properties["angle"].toDouble();
}
patternLayer->setAngle( angle );
if( properties.contains("distance") )
{
distance = properties["distance"].toDouble();
}
patternLayer->setDistance( distance );
if( properties.contains("linewidth") )
{
lineWidth = properties["linewidth"].toDouble();
}
patternLayer->setLineWidth( lineWidth );
if( properties.contains("color") )
{
color = QgsSymbolLayerV2Utils::decodeColor( properties["color"] );
}
patternLayer->setColor( color );
return patternLayer;
}
QString QgsLinePatternFillSymbolLayer::layerType() const
{
return "LinePatternFill";
}
void QgsLinePatternFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
{
}
void QgsLinePatternFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context )
{
}
void QgsLinePatternFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
{
}
QgsStringMap QgsLinePatternFillSymbolLayer::properties() const
{
QgsStringMap map;
map.insert( "angle", QString::number( mAngle ) );
map.insert( "distance", QString::number( mDistance ) );
map.insert( "linewidth", QString::number( mLineWidth ) );
map.insert( "color", QgsSymbolLayerV2Utils::encodeColor( mColor ) );
return map;
}
QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::clone() const
{
return QgsLinePatternFillSymbolLayer::create( properties() );
}
//////////////

@ -121,6 +121,47 @@ class CORE_EXPORT QgsSVGFillSymbolLayer: public QgsFillSymbolLayerV2
void storeViewBox();
};
class CORE_EXPORT QgsLinePatternFillSymbolLayer: public QgsFillSymbolLayerV2
{
public:
QgsLinePatternFillSymbolLayer();
~QgsLinePatternFillSymbolLayer();
static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
QString layerType() const;
void startRender( QgsSymbolV2RenderContext& context );
void stopRender( QgsSymbolV2RenderContext& context );
void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, 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:
/**Line angle*/
double mAngle;
/**Distance (in mm or map units) between lines*/
double mDistance;
/**Line width (in mm or map units)*/
double mLineWidth;
QColor mColor;
//todo: line type
};
class CORE_EXPORT QgsCentroidFillSymbolLayerV2 : public QgsFillSymbolLayerV2

@ -30,6 +30,8 @@ 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 ) );
}
QgsSymbolLayerV2Registry::~QgsSymbolLayerV2Registry()

@ -910,6 +910,71 @@ void QgsSVGFillSymbolLayerWidget::updateOutlineIcon()
/////////////
QgsLinePatternFillSymbolLayerWidget::QgsLinePatternFillSymbolLayerWidget( QWidget* parent ): QgsSymbolLayerV2Widget( parent ), 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 );
}
}
void QgsLinePatternFillSymbolLayerWidget::on_mDistanceSpinBox_valueChanged( double d )
{
if( mLayer )
{
mLayer->setDistance( d );
}
}
void QgsLinePatternFillSymbolLayerWidget::on_mLineWidthSpinBox_valueChanged( double d )
{
if( mLayer )
{
mLayer->setLineWidth( d );
}
}
void QgsLinePatternFillSymbolLayerWidget::on_mColorPushButton_clicked()
{
if( mLayer )
{
QColor c = QColorDialog::getColor( mLayer->color() );
if( c.isValid() )
{
mLayer->setColor( c );
}
}
}
/////////////
QgsFontMarkerSymbolLayerV2Widget::QgsFontMarkerSymbolLayerV2Widget( QWidget* parent )
: QgsSymbolLayerV2Widget( parent )
{

@ -259,6 +259,34 @@ class GUI_EXPORT QgsSVGFillSymbolLayerWidget : public QgsSymbolLayerV2Widget, pr
//////////
#include "ui_widget_linepatternfill.h"
class QgsLinePatternFillSymbolLayer;
class GUI_EXPORT QgsLinePatternFillSymbolLayerWidget : public QgsSymbolLayerV2Widget, private Ui::WidgetLinePatternFill
{
Q_OBJECT
public:
QgsLinePatternFillSymbolLayerWidget( QWidget* parent = NULL );
static QgsSymbolLayerV2Widget* create() { return new QgsLinePatternFillSymbolLayerWidget(); }
virtual void setSymbolLayer( QgsSymbolLayerV2* layer);
virtual QgsSymbolLayerV2* symbolLayer();
protected:
QgsLinePatternFillSymbolLayer* mLayer;
private slots:
void on_mAngleSpinBox_valueChanged( double d );
void on_mDistanceSpinBox_valueChanged( double d );
void on_mLineWidthSpinBox_valueChanged( double d );
void on_mColorPushButton_clicked();
};
//////////
#include "ui_widget_fontmarker.h"

@ -94,6 +94,7 @@ static void _initWidgetFunctions()
_initWidgetFunction( "SimpleFill", QgsSimpleFillSymbolLayerV2Widget::create );
_initWidgetFunction( "SVGFill", QgsSVGFillSymbolLayerWidget::create );
_initWidgetFunction( "CentroidFill", QgsCentroidFillSymbolLayerV2Widget::create );
_initWidgetFunction( "LinePatternFill", QgsLinePatternFillSymbolLayerWidget::create );
initialized = true;
}

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WidgetLinePatternFill</class>
<widget class="QWidget" name="WidgetLinePatternFill">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>156</width>
<height>122</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="mAngleLabel">
<property name="text">
<string>Angle</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="mAngleSpinBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mDistanceLabel">
<property name="text">
<string>Distance</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="mDistanceSpinBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mLineWidthLabel">
<property name="text">
<string>Line width</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="mLineWidthSpinBox"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mColorLabel">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="mColorPushButton">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>