Skip to content

Commit

Permalink
Added pen cap style and pen join style combo boxes.
Browse files Browse the repository at this point in the history
Added possibility to set cap and join style for simple line symbol layers.


git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11065 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jul 14, 2009
1 parent 9ae3ae2 commit 06f5de8
Show file tree
Hide file tree
Showing 16 changed files with 411 additions and 4 deletions.
Binary file added images/themes/default/cap_flat.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/cap_round.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/cap_square.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions images/themes/default/cap_style.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/join_bevel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/join_miter.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/join_round.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions images/themes/default/join_style.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -9,7 +9,7 @@
#include <cmath>

QgsSimpleLineSymbolLayerV2::QgsSimpleLineSymbolLayerV2(QColor color, double width, Qt::PenStyle penStyle)
: mPenStyle(penStyle), mOffset(0)
: mPenStyle(penStyle), mPenJoinStyle(DEFAULT_SIMPLELINE_JOINSTYLE), mPenCapStyle(DEFAULT_SIMPLELINE_CAPSTYLE), mOffset(0)
{
mColor = color;
mWidth = width;
Expand All @@ -21,17 +21,24 @@ QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::create(const QgsStringMap& props)
QColor color = DEFAULT_SIMPLELINE_COLOR;
double width = DEFAULT_SIMPLELINE_WIDTH;
Qt::PenStyle penStyle = DEFAULT_SIMPLELINE_PENSTYLE;

Qt::PenJoinStyle joinStyle = DEFAULT_SIMPLELINE_JOINSTYLE;
Qt::PenCapStyle capStyle = DEFAULT_SIMPLELINE_CAPSTYLE;

if (props.contains("color"))
color = QgsSymbolLayerV2Utils::decodeColor(props["color"]);
if (props.contains("width"))
width = props["width"].toDouble();
if (props.contains("penstyle"))
penStyle = QgsSymbolLayerV2Utils::decodePenStyle(props["penstyle"]);


QgsSimpleLineSymbolLayerV2* l = new QgsSimpleLineSymbolLayerV2(color, width, penStyle);
if (props.contains("offset"))
l->setOffset( props["offset"].toDouble() );
if (props.contains("joinstyle"))
l->setPenJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle(props["joinstyle"]) );
if (props.contains("capstyle"))
l->setPenCapStyle( QgsSymbolLayerV2Utils::decodePenCapStyle(props["capstyle"]) );
return l;
}

Expand All @@ -47,6 +54,8 @@ void QgsSimpleLineSymbolLayerV2::startRender(QgsRenderContext& context)
mPen.setColor(mColor);
mPen.setWidth(mWidth);
mPen.setStyle(mPenStyle);
mPen.setJoinStyle(mPenJoinStyle);
mPen.setCapStyle(mPenCapStyle);
}

void QgsSimpleLineSymbolLayerV2::stopRender(QgsRenderContext& context)
Expand All @@ -72,6 +81,8 @@ QgsStringMap QgsSimpleLineSymbolLayerV2::properties() const
map["color"] = QgsSymbolLayerV2Utils::encodeColor(mColor);
map["width"] = QString::number(mWidth);
map["penstyle"] = QgsSymbolLayerV2Utils::encodePenStyle(mPenStyle);
map["joinstyle"] = QgsSymbolLayerV2Utils::encodePenJoinStyle(mPenJoinStyle);
map["capstyle"] = QgsSymbolLayerV2Utils::encodePenCapStyle(mPenCapStyle);
map["offset"] = QString::number(mOffset);
return map;
}
Expand All @@ -80,6 +91,8 @@ QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::clone() const
{
QgsSimpleLineSymbolLayerV2* l = new QgsSimpleLineSymbolLayerV2(mColor, mWidth, mPenStyle);
l->setOffset(mOffset);
l->setPenJoinStyle(mPenJoinStyle);
l->setPenCapStyle(mPenCapStyle);
return l;
}

Expand Down
12 changes: 11 additions & 1 deletion src/core/symbology-ng/qgslinesymbollayerv2.h
Expand Up @@ -9,6 +9,8 @@
#define DEFAULT_SIMPLELINE_COLOR QColor(0,0,0)
#define DEFAULT_SIMPLELINE_WIDTH 1
#define DEFAULT_SIMPLELINE_PENSTYLE Qt::SolidLine
#define DEFAULT_SIMPLELINE_JOINSTYLE Qt::BevelJoin
#define DEFAULT_SIMPLELINE_CAPSTYLE Qt::SquareCap


class QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
Expand All @@ -17,7 +19,7 @@ class QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
QgsSimpleLineSymbolLayerV2(QColor color = DEFAULT_SIMPLELINE_COLOR,
double width = DEFAULT_SIMPLELINE_WIDTH,
Qt::PenStyle penStyle = DEFAULT_SIMPLELINE_PENSTYLE);

// static stuff

static QgsSymbolLayerV2* create(const QgsStringMap& properties = QgsStringMap());
Expand All @@ -41,11 +43,19 @@ class QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
Qt::PenStyle penStyle() const { return mPenStyle; }
void setPenStyle(Qt::PenStyle style) { mPenStyle = style; }

Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
void setPenJoinStyle(Qt::PenJoinStyle style) { mPenJoinStyle = style; }

Qt::PenCapStyle penCapStyle() const { return mPenCapStyle; }
void setPenCapStyle(Qt::PenCapStyle style) { mPenCapStyle = style; }

double offset() const { return mOffset; }
void setOffset(double offset) { mOffset = offset; }

protected:
Qt::PenStyle mPenStyle;
Qt::PenJoinStyle mPenJoinStyle;
Qt::PenCapStyle mPenCapStyle;
QPen mPen;
double mOffset;
};
Expand Down
39 changes: 39 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -45,6 +45,45 @@ Qt::PenStyle QgsSymbolLayerV2Utils::decodePenStyle(QString str)
return Qt::SolidLine;
}

QString QgsSymbolLayerV2Utils::encodePenJoinStyle(Qt::PenJoinStyle style)
{
switch (style)
{
case Qt::BevelJoin: return "bevel";
case Qt::MiterJoin: return "miter";
case Qt::RoundJoin: return "round";
default: return "???";
}
}

Qt::PenJoinStyle QgsSymbolLayerV2Utils::decodePenJoinStyle(QString str)
{
if (str == "bevel") return Qt::BevelJoin;
if (str == "miter") return Qt::MiterJoin;
if (str == "round") return Qt::RoundJoin;
return Qt::BevelJoin;
}

QString QgsSymbolLayerV2Utils::encodePenCapStyle(Qt::PenCapStyle style)
{
switch (style)
{
case Qt::SquareCap: return "square";
case Qt::FlatCap: return "flat";
case Qt::RoundCap: return "round";
default: return "???";
}
}

Qt::PenCapStyle QgsSymbolLayerV2Utils::decodePenCapStyle(QString str)
{
if (str == "square") return Qt::SquareCap;
if (str == "flat") return Qt::FlatCap;
if (str == "round") return Qt::RoundCap;
return Qt::SquareCap;
}


QString QgsSymbolLayerV2Utils::encodeBrushStyle(Qt::BrushStyle style)
{
switch (style)
Expand Down
6 changes: 6 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.h
Expand Up @@ -28,6 +28,12 @@ class QgsSymbolLayerV2Utils
static QString encodePenStyle(Qt::PenStyle style);
static Qt::PenStyle decodePenStyle(QString str);

static QString encodePenJoinStyle(Qt::PenJoinStyle style);
static Qt::PenJoinStyle decodePenJoinStyle(QString str);

static QString encodePenCapStyle(Qt::PenCapStyle style);
static Qt::PenCapStyle decodePenCapStyle(QString str);

static QString encodeBrushStyle(Qt::BrushStyle style);
static Qt::BrushStyle decodeBrushStyle(QString str);

Expand Down

0 comments on commit 06f5de8

Please sign in to comment.