Skip to content

Commit

Permalink
simple fill: added border style and width
Browse files Browse the repository at this point in the history
pen style combo box: added "no pen"


git-svn-id: http://svn.osgeo.org/qgis/trunk@12155 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Nov 17, 2009
1 parent af5d94b commit e3b5681
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 25 deletions.
30 changes: 20 additions & 10 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -6,8 +6,8 @@

#include <QPainter>

QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2(QColor color, QColor borderColor, Qt::BrushStyle style)
: mBrushStyle(style), mBorderColor(borderColor)
QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2(QColor color, Qt::BrushStyle style, QColor borderColor, Qt::PenStyle borderStyle, double borderWidth)
: mBrushStyle(style), mBorderColor(borderColor), mBorderStyle(borderStyle), mBorderWidth(borderWidth)
{
mColor = color;
}
Expand All @@ -16,17 +16,23 @@ QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2(QColor color, QColor bord
QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create(const QgsStringMap& props)
{
QColor color = DEFAULT_SIMPLEFILL_COLOR;
QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR;
Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE;

QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR;
Qt::PenStyle borderStyle = DEFAULT_SIMPLEFILL_BORDERSTYLE;
double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH;

if (props.contains("color"))
color = QgsSymbolLayerV2Utils::decodeColor(props["color"]);
if (props.contains("color_border"))
borderColor = QgsSymbolLayerV2Utils::decodeColor(props["color_border"]);
if (props.contains("style"))
style = QgsSymbolLayerV2Utils::decodeBrushStyle(props["style"]);

return new QgsSimpleFillSymbolLayerV2(color, borderColor, style);
if (props.contains("color_border"))
borderColor = QgsSymbolLayerV2Utils::decodeColor(props["color_border"]);
if (props.contains("style_border"))
borderStyle = QgsSymbolLayerV2Utils::decodePenStyle(props["style_border"]);
if (props.contains("width_border"))
borderWidth = props["width_border"].toDouble();

return new QgsSimpleFillSymbolLayerV2(color, style, borderColor, borderStyle, borderWidth);
}


Expand All @@ -39,6 +45,8 @@ void QgsSimpleFillSymbolLayerV2::startRender(QgsRenderContext& context)
{
mBrush = QBrush(mColor, mBrushStyle);
mPen = QPen(mBorderColor);
mPen.setStyle(mBorderStyle);
mPen.setWidthF(mBorderWidth);
}

void QgsSimpleFillSymbolLayerV2::stopRender(QgsRenderContext& context)
Expand Down Expand Up @@ -73,12 +81,14 @@ QgsStringMap QgsSimpleFillSymbolLayerV2::properties() const
{
QgsStringMap map;
map["color"] = QgsSymbolLayerV2Utils::encodeColor(mColor);
map["color_border"] = QgsSymbolLayerV2Utils::encodeColor(mBorderColor);
map["style"] = QgsSymbolLayerV2Utils::encodeBrushStyle(mBrushStyle);
map["color_border"] = QgsSymbolLayerV2Utils::encodeColor(mBorderColor);
map["style_border"] = QgsSymbolLayerV2Utils::encodePenStyle(mBorderStyle);
map["width_border"] = QString::number(mBorderWidth);
return map;
}

QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::clone() const
{
return new QgsSimpleFillSymbolLayerV2(mColor, mBorderColor, mBrushStyle);
return new QgsSimpleFillSymbolLayerV2(mColor, mBrushStyle, mBorderColor, mBorderStyle, mBorderWidth);
}
16 changes: 14 additions & 2 deletions src/core/symbology-ng/qgsfillsymbollayerv2.h
Expand Up @@ -7,6 +7,8 @@
#define DEFAULT_SIMPLEFILL_COLOR QColor(0,0,255)
#define DEFAULT_SIMPLEFILL_STYLE Qt::SolidPattern
#define DEFAULT_SIMPLEFILL_BORDERCOLOR QColor(0,0,0)
#define DEFAULT_SIMPLEFILL_BORDERSTYLE Qt::SolidLine
#define DEFAULT_SIMPLEFILL_BORDERWIDTH 1.0

#include <QPen>
#include <QBrush>
Expand All @@ -15,9 +17,11 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
{
public:
QgsSimpleFillSymbolLayerV2( QColor color = DEFAULT_SIMPLEFILL_COLOR,
Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE,
QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR,
Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE );

Qt::PenStyle borderStyle = DEFAULT_SIMPLEFILL_BORDERSTYLE,
double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH );

// static stuff

static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
Expand All @@ -42,10 +46,18 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
QColor borderColor() const { return mBorderColor; }
void setBorderColor( QColor borderColor ) { mBorderColor = borderColor; }

Qt::PenStyle borderStyle() const { return mBorderStyle; }
void setBorderStyle( Qt::PenStyle borderStyle ) { mBorderStyle = borderStyle; }

double borderWidth() const { return mBorderWidth; }
void setBorderWidth( double borderWidth ) { mBorderWidth = borderWidth; }

protected:
QBrush mBrush;
Qt::BrushStyle mBrushStyle;
QColor mBorderColor;
Qt::PenStyle mBorderStyle;
double mBorderWidth;
QPen mPen;
};

Expand Down
2 changes: 2 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -31,6 +31,7 @@ QString QgsSymbolLayerV2Utils::encodePenStyle( Qt::PenStyle style )
{
switch ( style )
{
case Qt::NoPen: return "no";
case Qt::SolidLine: return "solid";
case Qt::DashLine: return "dash";
case Qt::DotLine: return "dot";
Expand All @@ -42,6 +43,7 @@ QString QgsSymbolLayerV2Utils::encodePenStyle( Qt::PenStyle style )

Qt::PenStyle QgsSymbolLayerV2Utils::decodePenStyle( QString str )
{
if ( str == "no" ) return Qt::NoPen;
if ( str == "solid" ) return Qt::SolidLine;
if ( str == "dash" ) return Qt::DashLine;
if ( str == "dot" ) return Qt::DotLine;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/symbology-ng/qgspenstylecombobox.cpp
Expand Up @@ -17,7 +17,8 @@ QgsPenStyleComboBox::QgsPenStyleComboBox(QWidget* parent)
<< qMakePair(Qt::DashLine, QString("Dash Line"))
<< qMakePair(Qt::DotLine, QString("Dot Line"))
<< qMakePair(Qt::DashDotLine, QString("Dash Dot Line"))
<< qMakePair(Qt::DashDotDotLine, QString("Dash Dot Dot Line"));
<< qMakePair(Qt::DashDotDotLine, QString("Dash Dot Dot Line"))
<< qMakePair(Qt::NoPen, QString("No Pen"));

setIconSize(QSize(32,12));

Expand Down
20 changes: 18 additions & 2 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -212,8 +212,10 @@ QgsSimpleFillSymbolLayerV2Widget::QgsSimpleFillSymbolLayerV2Widget(QWidget* pare
setupUi(this);

connect(btnChangeColor, SIGNAL(clicked()), this, SLOT(setColor()));
connect(btnChangeBorderColor, SIGNAL(clicked()), this, SLOT(setBorderColor()));
connect(cboFillStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(setBrushStyle()));
connect(btnChangeBorderColor, SIGNAL(clicked()), this, SLOT(setBorderColor()));
connect(spinBorderWidth, SIGNAL(valueChanged(double)), this, SLOT(borderWidthChanged()));
connect(cboBorderStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(borderStyleChanged()));
}

void QgsSimpleFillSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
Expand All @@ -226,8 +228,10 @@ void QgsSimpleFillSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)

// set values
btnChangeColor->setColor(mLayer->color());
btnChangeBorderColor->setColor(mLayer->borderColor());
cboFillStyle->setBrushStyle(mLayer->brushStyle());
btnChangeBorderColor->setColor(mLayer->borderColor());
cboBorderStyle->setPenStyle(mLayer->borderStyle());
spinBorderWidth->setValue(mLayer->borderWidth());
}

QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2Widget::symbolLayer()
Expand Down Expand Up @@ -261,6 +265,18 @@ void QgsSimpleFillSymbolLayerV2Widget::setBrushStyle()
emit changed();
}

void QgsSimpleFillSymbolLayerV2Widget::borderWidthChanged()
{
mLayer->setBorderWidth(spinBorderWidth->value());
emit changed();
}

void QgsSimpleFillSymbolLayerV2Widget::borderStyleChanged()
{
mLayer->setBorderStyle(cboBorderStyle->penStyle());
emit changed();
}

///////////

QgsMarkerLineSymbolLayerV2Widget::QgsMarkerLineSymbolLayerV2Widget(QWidget* parent)
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Expand Up @@ -105,6 +105,8 @@ class GUI_EXPORT QgsSimpleFillSymbolLayerV2Widget : public QgsSymbolLayerV2Widge
void setColor();
void setBorderColor();
void setBrushStyle();
void borderWidthChanged();
void borderStyleChanged();

protected:
QgsSimpleFillSymbolLayerV2* mLayer;
Expand Down
51 changes: 41 additions & 10 deletions src/ui/symbollayer/widget_simplefill.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>335</width>
<height>154</height>
<height>206</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -30,7 +30,7 @@
</property>
</widget>
</item>
<item row="0" column="2" rowspan="3">
<item row="0" column="2" rowspan="5">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -47,26 +47,50 @@
</spacer>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Fill style:</string>
<string>Border color:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QgsColorButtonV2" name="btnChangeBorderColor">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsBrushStyleComboBox" name="cboFillStyle"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Border color:</string>
<string>Fill style:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButtonV2" name="btnChangeBorderColor">
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Change</string>
<string>Border style:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QgsPenStyleComboBox" name="cboBorderStyle"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Border width:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="spinBorderWidth">
<property name="decimals">
<number>1</number>
</property>
</widget>
</item>
Expand Down Expand Up @@ -98,11 +122,18 @@
<extends>QPushButton</extends>
<header>qgscolorbutton.h</header>
</customwidget>
<customwidget>
<class>QgsPenStyleComboBox</class>
<extends>QComboBox</extends>
<header>qgspenstylecombobox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>btnChangeColor</tabstop>
<tabstop>btnChangeBorderColor</tabstop>
<tabstop>cboFillStyle</tabstop>
<tabstop>btnChangeBorderColor</tabstop>
<tabstop>cboBorderStyle</tabstop>
<tabstop>spinBorderWidth</tabstop>
</tabstops>
<resources/>
<connections/>
Expand Down

0 comments on commit e3b5681

Please sign in to comment.