Skip to content

Commit 9ae3ae2

Browse files
author
wonder
committed
Changed line width to be double, fixed width retrieval from symbol, proportional scaling of symbol layers when settings size/width.
git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11064 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 45ae45f commit 9ae3ae2

17 files changed

+213
-160
lines changed

python/core/symbology-ng-core.sip

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ class QgsLineSymbolLayerV2 : QgsSymbolLayerV2
315315
public:
316316
virtual void renderPolyline(const QPolygonF& points, QgsRenderContext& context) = 0;
317317

318-
void setWidth(int width);
319-
int width() const;
318+
void setWidth(double width);
319+
double width() const;
320320

321321
void drawPreviewIcon(QPainter* painter, QSize size);
322322

@@ -450,8 +450,8 @@ class QgsLineSymbolV2 : QgsSymbolV2
450450
public:
451451
QgsLineSymbolV2(QgsSymbolLayerV2List layers /Transfer/ = QgsSymbolLayerV2List());
452452

453-
void setWidth(int width);
454-
int width();
453+
void setWidth(double width);
454+
double width();
455455

456456
void renderPolyline(const QPolygonF& points, QgsRenderContext& context, int layer = -1);
457457

python/gui/symbology-ng-gui.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public slots:
8686
void setSymbolFromStyle(const QModelIndex & index);
8787
void setSymbolColor();
8888
void setMarkerAngle(double angle);
89-
void setMarkerSize(int size);
90-
void setLineWidth(int width);
89+
void setMarkerSize(double size);
90+
void setLineWidth(double width);
9191

9292
};

src/core/symbology-ng/qgslinesymbollayerv2.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <cmath>
1010

11-
QgsSimpleLineSymbolLayerV2::QgsSimpleLineSymbolLayerV2(QColor color, int width, Qt::PenStyle penStyle)
11+
QgsSimpleLineSymbolLayerV2::QgsSimpleLineSymbolLayerV2(QColor color, double width, Qt::PenStyle penStyle)
1212
: mPenStyle(penStyle), mOffset(0)
1313
{
1414
mColor = color;
@@ -19,13 +19,13 @@ QgsSimpleLineSymbolLayerV2::QgsSimpleLineSymbolLayerV2(QColor color, int width,
1919
QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::create(const QgsStringMap& props)
2020
{
2121
QColor color = DEFAULT_SIMPLELINE_COLOR;
22-
int width = DEFAULT_SIMPLELINE_WIDTH;
22+
double width = DEFAULT_SIMPLELINE_WIDTH;
2323
Qt::PenStyle penStyle = DEFAULT_SIMPLELINE_PENSTYLE;
2424

2525
if (props.contains("color"))
2626
color = QgsSymbolLayerV2Utils::decodeColor(props["color"]);
2727
if (props.contains("width"))
28-
width = props["width"].toInt();
28+
width = props["width"].toDouble();
2929
if (props.contains("penstyle"))
3030
penStyle = QgsSymbolLayerV2Utils::decodePenStyle(props["penstyle"]);
3131

src/core/symbology-ng/qgslinesymbollayerv2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
1515
{
1616
public:
1717
QgsSimpleLineSymbolLayerV2(QColor color = DEFAULT_SIMPLELINE_COLOR,
18-
int width = DEFAULT_SIMPLELINE_WIDTH,
18+
double width = DEFAULT_SIMPLELINE_WIDTH,
1919
Qt::PenStyle penStyle = DEFAULT_SIMPLELINE_PENSTYLE);
2020

2121
// static stuff

src/core/symbology-ng/qgssymbollayerv2.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ class QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
8989
public:
9090
virtual void renderPolyline(const QPolygonF& points, QgsRenderContext& context) = 0;
9191

92-
void setWidth(int width) { mWidth = width; }
93-
int width() const { return mWidth; }
92+
void setWidth(double width) { mWidth = width; }
93+
double width() const { return mWidth; }
9494

9595
void drawPreviewIcon(QPainter* painter, QSize size);
9696

9797
protected:
9898
QgsLineSymbolLayerV2(bool locked = false);
9999

100-
int mWidth;
100+
double mWidth;
101101
};
102102

103103
class QgsFillSymbolLayerV2 : public QgsSymbolLayerV2

src/core/symbology-ng/qgssymbolv2.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,21 @@ double QgsMarkerSymbolV2::angle()
252252
return 0;
253253
}
254254

255-
void QgsMarkerSymbolV2::setSize(double size)
255+
void QgsMarkerSymbolV2::setSize(double s)
256256
{
257-
// TODO: proportionally set size of layers
257+
double origSize = size();
258+
258259
for (QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it)
259260
{
260261
QgsMarkerSymbolLayerV2* layer = (QgsMarkerSymbolLayerV2*) *it;
261-
layer->setSize(size);
262+
if (layer->size() == origSize)
263+
layer->setSize(s);
264+
else
265+
{
266+
// proportionally scale size
267+
if (origSize != 0)
268+
layer->setSize(layer->size() * s / origSize);
269+
}
262270
}
263271
}
264272

@@ -308,24 +316,34 @@ QgsLineSymbolV2::QgsLineSymbolV2(QgsSymbolLayerV2List layers)
308316
mLayers.append(new QgsSimpleLineSymbolLayerV2());
309317
}
310318

311-
void QgsLineSymbolV2::setWidth(int width)
319+
void QgsLineSymbolV2::setWidth(double w)
312320
{
313-
// TODO: proportionally set width of layers
321+
double origWidth = width();
322+
314323
for (QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it)
315324
{
316325
QgsLineSymbolLayerV2* layer = (QgsLineSymbolLayerV2*) *it;
317-
layer->setWidth(width);
326+
if (layer->width() == origWidth)
327+
{
328+
layer->setWidth(w);
329+
}
330+
else
331+
{
332+
// proportionally scale the width
333+
if (origWidth != 0)
334+
layer->setWidth( layer->width() * w / origWidth );
335+
}
318336
}
319337
}
320338

321-
int QgsLineSymbolV2::width()
339+
double QgsLineSymbolV2::width()
322340
{
323-
int maxWidth = 0;
341+
double maxWidth = 0;
324342
for (QgsSymbolLayerV2List::const_iterator it = mLayers.begin(); it != mLayers.end(); ++it)
325343
{
326344
const QgsLineSymbolLayerV2* layer = (const QgsLineSymbolLayerV2*) *it;
327-
int width = layer->width();
328-
if (maxWidth > width)
345+
double width = layer->width();
346+
if (width > maxWidth)
329347
maxWidth = width;
330348
}
331349
return maxWidth;

src/core/symbology-ng/qgssymbolv2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class QgsLineSymbolV2 : public QgsSymbolV2
106106
public:
107107
QgsLineSymbolV2(QgsSymbolLayerV2List layers = QgsSymbolLayerV2List());
108108

109-
void setWidth(int width);
110-
int width();
109+
void setWidth(double width);
110+
double width();
111111

112112
void renderPolyline(const QPolygonF& points, QgsRenderContext& context, int layer = -1);
113113

src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ QgsSimpleLineSymbolLayerV2Widget::QgsSimpleLineSymbolLayerV2Widget(QWidget* pare
3232

3333
setupUi(this);
3434

35-
connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(penWidthChanged()));
35+
connect(spinWidth, SIGNAL(valueChanged(double)), this, SLOT(penWidthChanged()));
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()));
@@ -114,7 +114,7 @@ QgsSimpleMarkerSymbolLayerV2Widget::QgsSimpleMarkerSymbolLayerV2Widget(QWidget*
114114
connect(lstNames, SIGNAL(currentRowChanged(int)), this, SLOT(setName()));
115115
connect(btnChangeColorBorder, SIGNAL(clicked()), this, SLOT(setColorBorder()));
116116
connect(btnChangeColorFill, SIGNAL(clicked()), this, SLOT(setColorFill()));
117-
connect(spinSize, SIGNAL(valueChanged(int)), this, SLOT(setSize()));
117+
connect(spinSize, SIGNAL(valueChanged(double)), this, SLOT(setSize()));
118118
connect(spinAngle, SIGNAL(valueChanged(double)), this, SLOT(setAngle()));
119119
connect(spinOffsetX, SIGNAL(valueChanged(double)), this, SLOT(setOffset()));
120120
connect(spinOffsetY, SIGNAL(valueChanged(double)), this, SLOT(setOffset()));
@@ -270,7 +270,7 @@ QgsMarkerLineSymbolLayerV2Widget::QgsMarkerLineSymbolLayerV2Widget(QWidget* pare
270270

271271
setupUi(this);
272272

273-
connect(spinInterval, SIGNAL(valueChanged(int)), this, SLOT(setInterval(int)));
273+
connect(spinInterval, SIGNAL(valueChanged(double)), this, SLOT(setInterval(double)));
274274
connect(btnChangeMarker, SIGNAL(clicked()), this, SLOT(setMarker()));
275275
connect(chkRotateMarker, SIGNAL(clicked()), this, SLOT(setRotate()));
276276
connect(spinOffset, SIGNAL(valueChanged(double)), this, SLOT(setOffset()));
@@ -296,7 +296,7 @@ QgsSymbolLayerV2* QgsMarkerLineSymbolLayerV2Widget::symbolLayer()
296296
return mLayer;
297297
}
298298

299-
void QgsMarkerLineSymbolLayerV2Widget::setInterval(int val)
299+
void QgsMarkerLineSymbolLayerV2Widget::setInterval(double val)
300300
{
301301
mLayer->setInterval(val);
302302
emit changed();
@@ -345,7 +345,7 @@ QgsSvgMarkerSymbolLayerV2Widget::QgsSvgMarkerSymbolLayerV2Widget(QWidget* parent
345345
populateList();
346346

347347
connect(viewImages->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(setName(const QModelIndex&)));
348-
connect(spinSize, SIGNAL(valueChanged(int)), this, SLOT(setSize()));
348+
connect(spinSize, SIGNAL(valueChanged(double)), this, SLOT(setSize()));
349349
connect(spinAngle, SIGNAL(valueChanged(double)), this, SLOT(setAngle()));
350350
connect(spinOffsetX, SIGNAL(valueChanged(double)), this, SLOT(setOffset()));
351351
connect(spinOffsetY, SIGNAL(valueChanged(double)), this, SLOT(setOffset()));

src/gui/symbology-ng/qgssymbollayerv2widget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class QgsMarkerLineSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private
131131

132132
public slots:
133133

134-
void setInterval(int val);
134+
void setInterval(double val);
135135
void setMarker();
136136
void setRotate();
137137
void setOffset();

src/gui/symbology-ng/qgssymbolv2selectordialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsSty
3636

3737
connect(btnSetColor, SIGNAL(clicked()), this, SLOT(setSymbolColor()));
3838
connect(spinAngle, SIGNAL(valueChanged(double)), this, SLOT(setMarkerAngle(double)));
39-
connect(spinSize, SIGNAL(valueChanged(int)), this, SLOT(setMarkerSize(int)));
40-
connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(setLineWidth(int)));
39+
connect(spinSize, SIGNAL(valueChanged(double)), this, SLOT(setMarkerSize(double)));
40+
connect(spinWidth, SIGNAL(valueChanged(double)), this, SLOT(setLineWidth(double)));
4141

4242
}
4343

@@ -154,7 +154,7 @@ void QgsSymbolV2SelectorDialog::setMarkerAngle(double angle)
154154
updateSymbolPreview();
155155
}
156156

157-
void QgsSymbolV2SelectorDialog::setMarkerSize(int size)
157+
void QgsSymbolV2SelectorDialog::setMarkerSize(double size)
158158
{
159159
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>(mSymbol);
160160
if (markerSymbol->size() == size)
@@ -163,7 +163,7 @@ void QgsSymbolV2SelectorDialog::setMarkerSize(int size)
163163
updateSymbolPreview();
164164
}
165165

166-
void QgsSymbolV2SelectorDialog::setLineWidth(int width)
166+
void QgsSymbolV2SelectorDialog::setLineWidth(double width)
167167
{
168168
QgsLineSymbolV2* lineSymbol = static_cast<QgsLineSymbolV2*>(mSymbol);
169169
if (lineSymbol->width() == width)

0 commit comments

Comments
 (0)