Skip to content
Permalink
Browse files

Added pen cap style and pen join style combo boxes.

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
wonder committed Jul 14, 2009
1 parent 9ae3ae2 commit 06f5de8f15f085baadafd33978169fe80f6efebc
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.46"
version="1.0"
inkscape:export-filename="/home/wonder/cap_square.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90"
sodipodi:docname="cap_style.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<defs
id="defs4">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective10" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
gridtolerance="10000"
guidetolerance="10"
objecttolerance="10"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="35.375"
inkscape:cx="5.3152953"
inkscape:cy="6.869258"
inkscape:document-units="px"
inkscape:current-layer="layer4"
showgrid="false"
inkscape:window-width="1270"
inkscape:window-height="769"
inkscape:window-x="0"
inkscape:window-y="0" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="square cap"
inkscape:groupmode="layer"
id="layer1"
style="display:inline">
<rect
style="opacity:1;fill:#6389b8;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect3165"
width="16.282686"
height="8.4522972"
x="-2.0353358"
y="3.7738514" />
</g>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="flat cap"
style="display:none">
<rect
style="opacity:1;fill:#6389b8;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect3167"
width="16.282686"
height="8.4522972"
x="-5.2854118"
y="3.7738514" />
</g>
<g
inkscape:groupmode="layer"
id="layer4"
inkscape:label="round cap"
style="display:none">
<path
style="opacity:1;fill:#6389b8;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
d="M -6.4375,3.78125 L -6.4375,12.21875 L 9.84375,12.21875 L 9.7306758,12.244037 C 10.134161,12.218685 10.418569,12.21875 10.483547,12.21875 C 12.808579,12.21875 14.25,10.325032 14.25,8 C 14.25,5.6749682 12.356282,3.78125 10.03125,3.78125 C 9.966272,3.78125 8.5793902,3.8661211 9.84375,3.8125 L 9.7872129,3.8095186 L -6.4375,3.78125 z"
id="path3176"
sodipodi:nodetypes="ccccsssccc" />
</g>
<g
inkscape:groupmode="layer"
id="layer3"
inkscape:label="line">
<path
style="fill:none;fill-rule:evenodd;stroke:#d3c02d;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:2, 1;stroke-dashoffset:0;stroke-opacity:1"
d="M 0.14215003,8 L 10.488441,8"
id="path2393"
inkscape:export-filename="/home/wonder/cap_square.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90" />
</g>
</svg>
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
id="svg3203"
sodipodi:version="0.32"
inkscape:version="0.46"
version="1.0"
sodipodi:docname="join_style.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<defs
id="defs3205">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective3211" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
gridtolerance="10000"
guidetolerance="10"
objecttolerance="10"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="35.375"
inkscape:cx="8"
inkscape:cy="8"
inkscape:document-units="px"
inkscape:current-layer="layer7"
showgrid="false"
inkscape:window-width="1270"
inkscape:window-height="769"
inkscape:window-x="0"
inkscape:window-y="0" />
<metadata
id="metadata3208">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:groupmode="layer"
id="layer5"
inkscape:label="miter join"
style="display:none">
<path
style="fill:#6389b8;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 8.21875,2.3125 L 6.4375,4.09375 L -2.75,13.28125 L 0.78125,16.8125 L 8.21875,9.40625 L 15.71875,16.90625 L 19.25,13.34375 L 10,4.09375 L 8.21875,2.3125 z"
id="path3724" />
</g>
<g
inkscape:groupmode="layer"
id="layer6"
inkscape:label="bevel join"
style="display:none">
<path
style="fill:#6389b8;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
d="M 6.46875,4.125 L -2.71875,13.3125 L 0.8125,16.875 L 8.25,9.4375 L 15.75,16.9375 L 19.28125,13.40625 L 10,4.125 L 6.46875,4.125 z"
id="path3735" />
</g>
<g
inkscape:groupmode="layer"
id="layer7"
inkscape:label="round join"
style="display:inline">
<path
style="fill:#6389b8;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;display:inline"
d="M 7.96875,3.40625 C 7.401375,3.4676239 6.8720695,3.7212494 6.46875,4.125 L -2.71875,13.3125 L 0.8125,16.875 L 8.25,9.4375 L 15.75,16.9375 L 19.28125,13.40625 L 10,4.125 C 9.4661818,3.5909923 8.7196282,3.3268272 7.96875,3.40625 L 7.96875,3.40625 z"
id="path3743" />
</g>
<g
inkscape:label="line"
inkscape:groupmode="layer"
id="layer1"
style="display:inline">
<path
style="fill:none;fill-rule:evenodd;stroke:#d3c02d;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:2, 1;stroke-dashoffset:0;stroke-opacity:1"
d="M -0.96113074,15.095406 L 8.2402827,5.8939929 L 17.512367,15.166078"
id="path3213" />
</g>
</svg>
@@ -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;
@@ -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;
}

@@ -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)
@@ -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;
}
@@ -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;
}

@@ -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
@@ -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());
@@ -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;
};
@@ -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)
@@ -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);

0 comments on commit 06f5de8

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