Skip to content

Commit 06f5de8

Browse files
author
wonder
committedJul 14, 2009
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

16 files changed

+411
-4
lines changed
 

‎images/themes/default/cap_flat.png

264 Bytes
Loading

‎images/themes/default/cap_round.png

408 Bytes
Loading

‎images/themes/default/cap_square.png

261 Bytes
Loading

‎images/themes/default/cap_style.svg

Lines changed: 112 additions & 0 deletions
Loading

‎images/themes/default/join_bevel.png

658 Bytes
Loading

‎images/themes/default/join_miter.png

701 Bytes
Loading

‎images/themes/default/join_round.png

695 Bytes
Loading

‎images/themes/default/join_style.svg

Lines changed: 100 additions & 0 deletions
Loading

‎src/core/symbology-ng/qgslinesymbollayerv2.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <cmath>
1010

1111
QgsSimpleLineSymbolLayerV2::QgsSimpleLineSymbolLayerV2(QColor color, double width, Qt::PenStyle penStyle)
12-
: mPenStyle(penStyle), mOffset(0)
12+
: mPenStyle(penStyle), mPenJoinStyle(DEFAULT_SIMPLELINE_JOINSTYLE), mPenCapStyle(DEFAULT_SIMPLELINE_CAPSTYLE), mOffset(0)
1313
{
1414
mColor = color;
1515
mWidth = width;
@@ -21,17 +21,24 @@ QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::create(const QgsStringMap& props)
2121
QColor color = DEFAULT_SIMPLELINE_COLOR;
2222
double width = DEFAULT_SIMPLELINE_WIDTH;
2323
Qt::PenStyle penStyle = DEFAULT_SIMPLELINE_PENSTYLE;
24-
24+
Qt::PenJoinStyle joinStyle = DEFAULT_SIMPLELINE_JOINSTYLE;
25+
Qt::PenCapStyle capStyle = DEFAULT_SIMPLELINE_CAPSTYLE;
26+
2527
if (props.contains("color"))
2628
color = QgsSymbolLayerV2Utils::decodeColor(props["color"]);
2729
if (props.contains("width"))
2830
width = props["width"].toDouble();
2931
if (props.contains("penstyle"))
3032
penStyle = QgsSymbolLayerV2Utils::decodePenStyle(props["penstyle"]);
33+
3134

3235
QgsSimpleLineSymbolLayerV2* l = new QgsSimpleLineSymbolLayerV2(color, width, penStyle);
3336
if (props.contains("offset"))
3437
l->setOffset( props["offset"].toDouble() );
38+
if (props.contains("joinstyle"))
39+
l->setPenJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle(props["joinstyle"]) );
40+
if (props.contains("capstyle"))
41+
l->setPenCapStyle( QgsSymbolLayerV2Utils::decodePenCapStyle(props["capstyle"]) );
3542
return l;
3643
}
3744

@@ -47,6 +54,8 @@ void QgsSimpleLineSymbolLayerV2::startRender(QgsRenderContext& context)
4754
mPen.setColor(mColor);
4855
mPen.setWidth(mWidth);
4956
mPen.setStyle(mPenStyle);
57+
mPen.setJoinStyle(mPenJoinStyle);
58+
mPen.setCapStyle(mPenCapStyle);
5059
}
5160

5261
void QgsSimpleLineSymbolLayerV2::stopRender(QgsRenderContext& context)
@@ -72,6 +81,8 @@ QgsStringMap QgsSimpleLineSymbolLayerV2::properties() const
7281
map["color"] = QgsSymbolLayerV2Utils::encodeColor(mColor);
7382
map["width"] = QString::number(mWidth);
7483
map["penstyle"] = QgsSymbolLayerV2Utils::encodePenStyle(mPenStyle);
84+
map["joinstyle"] = QgsSymbolLayerV2Utils::encodePenJoinStyle(mPenJoinStyle);
85+
map["capstyle"] = QgsSymbolLayerV2Utils::encodePenCapStyle(mPenCapStyle);
7586
map["offset"] = QString::number(mOffset);
7687
return map;
7788
}
@@ -80,6 +91,8 @@ QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::clone() const
8091
{
8192
QgsSimpleLineSymbolLayerV2* l = new QgsSimpleLineSymbolLayerV2(mColor, mWidth, mPenStyle);
8293
l->setOffset(mOffset);
94+
l->setPenJoinStyle(mPenJoinStyle);
95+
l->setPenCapStyle(mPenCapStyle);
8396
return l;
8497
}
8598

‎src/core/symbology-ng/qgslinesymbollayerv2.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#define DEFAULT_SIMPLELINE_COLOR QColor(0,0,0)
1010
#define DEFAULT_SIMPLELINE_WIDTH 1
1111
#define DEFAULT_SIMPLELINE_PENSTYLE Qt::SolidLine
12+
#define DEFAULT_SIMPLELINE_JOINSTYLE Qt::BevelJoin
13+
#define DEFAULT_SIMPLELINE_CAPSTYLE Qt::SquareCap
1214

1315

1416
class QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
@@ -17,7 +19,7 @@ class QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
1719
QgsSimpleLineSymbolLayerV2(QColor color = DEFAULT_SIMPLELINE_COLOR,
1820
double width = DEFAULT_SIMPLELINE_WIDTH,
1921
Qt::PenStyle penStyle = DEFAULT_SIMPLELINE_PENSTYLE);
20-
22+
2123
// static stuff
2224

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

46+
Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
47+
void setPenJoinStyle(Qt::PenJoinStyle style) { mPenJoinStyle = style; }
48+
49+
Qt::PenCapStyle penCapStyle() const { return mPenCapStyle; }
50+
void setPenCapStyle(Qt::PenCapStyle style) { mPenCapStyle = style; }
51+
4452
double offset() const { return mOffset; }
4553
void setOffset(double offset) { mOffset = offset; }
4654

4755
protected:
4856
Qt::PenStyle mPenStyle;
57+
Qt::PenJoinStyle mPenJoinStyle;
58+
Qt::PenCapStyle mPenCapStyle;
4959
QPen mPen;
5060
double mOffset;
5161
};

‎src/core/symbology-ng/qgssymbollayerv2utils.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,45 @@ Qt::PenStyle QgsSymbolLayerV2Utils::decodePenStyle(QString str)
4545
return Qt::SolidLine;
4646
}
4747

48+
QString QgsSymbolLayerV2Utils::encodePenJoinStyle(Qt::PenJoinStyle style)
49+
{
50+
switch (style)
51+
{
52+
case Qt::BevelJoin: return "bevel";
53+
case Qt::MiterJoin: return "miter";
54+
case Qt::RoundJoin: return "round";
55+
default: return "???";
56+
}
57+
}
58+
59+
Qt::PenJoinStyle QgsSymbolLayerV2Utils::decodePenJoinStyle(QString str)
60+
{
61+
if (str == "bevel") return Qt::BevelJoin;
62+
if (str == "miter") return Qt::MiterJoin;
63+
if (str == "round") return Qt::RoundJoin;
64+
return Qt::BevelJoin;
65+
}
66+
67+
QString QgsSymbolLayerV2Utils::encodePenCapStyle(Qt::PenCapStyle style)
68+
{
69+
switch (style)
70+
{
71+
case Qt::SquareCap: return "square";
72+
case Qt::FlatCap: return "flat";
73+
case Qt::RoundCap: return "round";
74+
default: return "???";
75+
}
76+
}
77+
78+
Qt::PenCapStyle QgsSymbolLayerV2Utils::decodePenCapStyle(QString str)
79+
{
80+
if (str == "square") return Qt::SquareCap;
81+
if (str == "flat") return Qt::FlatCap;
82+
if (str == "round") return Qt::RoundCap;
83+
return Qt::SquareCap;
84+
}
85+
86+
4887
QString QgsSymbolLayerV2Utils::encodeBrushStyle(Qt::BrushStyle style)
4988
{
5089
switch (style)

‎src/core/symbology-ng/qgssymbollayerv2utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class QgsSymbolLayerV2Utils
2828
static QString encodePenStyle(Qt::PenStyle style);
2929
static Qt::PenStyle decodePenStyle(QString str);
3030

31+
static QString encodePenJoinStyle(Qt::PenJoinStyle style);
32+
static Qt::PenJoinStyle decodePenJoinStyle(QString str);
33+
34+
static QString encodePenCapStyle(Qt::PenCapStyle style);
35+
static Qt::PenCapStyle decodePenCapStyle(QString str);
36+
3137
static QString encodeBrushStyle(Qt::BrushStyle style);
3238
static Qt::BrushStyle decodeBrushStyle(QString str);
3339

‎src/gui/symbology-ng/qgspenstylecombobox.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
#include "qgspenstylecombobox.h"
33

4+
#include "qgsapplication.h"
5+
46
#include <QList>
57
#include <QPair>
68

@@ -54,3 +56,51 @@ QIcon QgsPenStyleComboBox::iconForPen(Qt::PenStyle style)
5456

5557
return QIcon(pix);
5658
}
59+
60+
61+
/////////
62+
// join
63+
64+
QgsPenJoinStyleComboBox::QgsPenJoinStyleComboBox(QWidget* parent)
65+
: QComboBox(parent)
66+
{
67+
QString path = QgsApplication::defaultThemePath();
68+
addItem(QIcon(path + "/join_bevel.png"), tr("Bevel"), QVariant(Qt::BevelJoin));
69+
addItem(QIcon(path + "/join_miter.png"), tr("Miter"), QVariant(Qt::MiterJoin));
70+
addItem(QIcon(path + "/join_round.png"), tr("Round"), QVariant(Qt::RoundJoin));
71+
}
72+
73+
Qt::PenJoinStyle QgsPenJoinStyleComboBox::penJoinStyle() const
74+
{
75+
return (Qt::PenJoinStyle) itemData(currentIndex()).toInt();
76+
}
77+
78+
void QgsPenJoinStyleComboBox::setPenJoinStyle(Qt::PenJoinStyle style)
79+
{
80+
int idx = findData(QVariant(style));
81+
setCurrentIndex( idx == -1 ? 0 : idx );
82+
}
83+
84+
85+
/////////
86+
// cap
87+
88+
QgsPenCapStyleComboBox::QgsPenCapStyleComboBox(QWidget* parent)
89+
: QComboBox(parent)
90+
{
91+
QString path = QgsApplication::defaultThemePath();
92+
addItem(QIcon(path + "/cap_square.png"), tr("Square"), QVariant(Qt::SquareCap));
93+
addItem(QIcon(path + "/cap_flat.png"), tr("Flat"), QVariant(Qt::FlatCap));
94+
addItem(QIcon(path + "/cap_round.png"), tr("Round"), QVariant(Qt::RoundCap));
95+
}
96+
97+
Qt::PenCapStyle QgsPenCapStyleComboBox::penCapStyle() const
98+
{
99+
return (Qt::PenCapStyle) itemData(currentIndex()).toInt();
100+
}
101+
102+
void QgsPenCapStyleComboBox::setPenCapStyle(Qt::PenCapStyle style)
103+
{
104+
int idx = findData(QVariant(style));
105+
setCurrentIndex( idx == -1 ? 0 : idx );
106+
}

‎src/gui/symbology-ng/qgspenstylecombobox.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,24 @@ class QgsPenStyleComboBox : public QComboBox
1818

1919
};
2020

21+
class QgsPenJoinStyleComboBox : public QComboBox
22+
{
23+
public:
24+
QgsPenJoinStyleComboBox(QWidget* parent = NULL);
25+
26+
Qt::PenJoinStyle penJoinStyle() const;
27+
28+
void setPenJoinStyle(Qt::PenJoinStyle style);
29+
};
30+
31+
class QgsPenCapStyleComboBox : public QComboBox
32+
{
33+
public:
34+
QgsPenCapStyleComboBox(QWidget* parent = NULL);
35+
36+
Qt::PenCapStyle penCapStyle() const;
37+
38+
void setPenCapStyle(Qt::PenCapStyle style);
39+
};
40+
2141
#endif

‎src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ QgsSimpleLineSymbolLayerV2Widget::QgsSimpleLineSymbolLayerV2Widget(QWidget* pare
3636
connect(btnChangeColor, SIGNAL(clicked()), this, SLOT(colorChanged()));
3737
connect(cboPenStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(penStyleChanged()));
3838
connect(spinOffset, SIGNAL(valueChanged(double)), this, SLOT(offsetChanged()));
39+
connect(cboCapStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(penStyleChanged()));
40+
connect(cboJoinStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(penStyleChanged()));
41+
3942
}
4043

4144
void QgsSimpleLineSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
@@ -51,6 +54,8 @@ void QgsSimpleLineSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
5154
updateColorButton(btnChangeColor, mLayer->color());
5255
cboPenStyle->setPenStyle(mLayer->penStyle());
5356
spinOffset->setValue(mLayer->offset());
57+
cboJoinStyle->setPenJoinStyle(mLayer->penJoinStyle());
58+
cboCapStyle->setPenCapStyle(mLayer->penCapStyle());
5459
}
5560

5661
QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2Widget::symbolLayer()
@@ -77,6 +82,8 @@ void QgsSimpleLineSymbolLayerV2Widget::colorChanged()
7782
void QgsSimpleLineSymbolLayerV2Widget::penStyleChanged()
7883
{
7984
mLayer->setPenStyle(cboPenStyle->penStyle());
85+
mLayer->setPenJoinStyle(cboJoinStyle->penJoinStyle());
86+
mLayer->setPenCapStyle(cboCapStyle->penCapStyle());
8087
emit changed();
8188
}
8289

‎src/ui/symbollayer/widget_simpleline.ui

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
16-
<layout class="QVBoxLayout">
16+
<layout class="QVBoxLayout" name="verticalLayout">
1717
<item>
1818
<layout class="QGridLayout">
1919
<item row="0" column="0">
@@ -123,6 +123,46 @@
123123
</property>
124124
</spacer>
125125
</item>
126+
<item>
127+
<layout class="QGridLayout" name="gridLayout">
128+
<item row="0" column="0">
129+
<widget class="QLabel" name="label_5">
130+
<property name="text">
131+
<string>Join style:</string>
132+
</property>
133+
</widget>
134+
</item>
135+
<item row="0" column="1">
136+
<widget class="QgsPenJoinStyleComboBox" name="cboJoinStyle"/>
137+
</item>
138+
<item row="0" column="2" rowspan="2">
139+
<spacer name="horizontalSpacer">
140+
<property name="orientation">
141+
<enum>Qt::Horizontal</enum>
142+
</property>
143+
<property name="sizeType">
144+
<enum>QSizePolicy::Preferred</enum>
145+
</property>
146+
<property name="sizeHint" stdset="0">
147+
<size>
148+
<width>40</width>
149+
<height>38</height>
150+
</size>
151+
</property>
152+
</spacer>
153+
</item>
154+
<item row="1" column="0">
155+
<widget class="QLabel" name="label_6">
156+
<property name="text">
157+
<string>Cap style:</string>
158+
</property>
159+
</widget>
160+
</item>
161+
<item row="1" column="1">
162+
<widget class="QgsPenCapStyleComboBox" name="cboCapStyle"/>
163+
</item>
164+
</layout>
165+
</item>
126166
</layout>
127167
</widget>
128168
<customwidgets>
@@ -131,6 +171,16 @@
131171
<extends>QComboBox</extends>
132172
<header>qgspenstylecombobox.h</header>
133173
</customwidget>
174+
<customwidget>
175+
<class>QgsPenJoinStyleComboBox</class>
176+
<extends>QComboBox</extends>
177+
<header>qgspenstylecombobox.h</header>
178+
</customwidget>
179+
<customwidget>
180+
<class>QgsPenCapStyleComboBox</class>
181+
<extends>QComboBox</extends>
182+
<header>qgspenstylecombobox.h</header>
183+
</customwidget>
134184
</customwidgets>
135185
<resources/>
136186
<connections/>

0 commit comments

Comments
 (0)
Please sign in to comment.