Skip to content

Commit

Permalink
Changed line width to be double, fixed width retrieval from symbol, p…
Browse files Browse the repository at this point in the history
…roportional 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
  • Loading branch information
wonder committed Jul 14, 2009
1 parent 45ae45f commit 9ae3ae2
Show file tree
Hide file tree
Showing 17 changed files with 213 additions and 160 deletions.
8 changes: 4 additions & 4 deletions python/core/symbology-ng-core.sip
Expand Up @@ -315,8 +315,8 @@ class QgsLineSymbolLayerV2 : QgsSymbolLayerV2
public:
virtual void renderPolyline(const QPolygonF& points, QgsRenderContext& context) = 0;

void setWidth(int width);
int width() const;
void setWidth(double width);
double width() const;

void drawPreviewIcon(QPainter* painter, QSize size);

Expand Down Expand Up @@ -450,8 +450,8 @@ class QgsLineSymbolV2 : QgsSymbolV2
public:
QgsLineSymbolV2(QgsSymbolLayerV2List layers /Transfer/ = QgsSymbolLayerV2List());

void setWidth(int width);
int width();
void setWidth(double width);
double width();

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

Expand Down
4 changes: 2 additions & 2 deletions python/gui/symbology-ng-gui.sip
Expand Up @@ -86,7 +86,7 @@ public slots:
void setSymbolFromStyle(const QModelIndex & index);
void setSymbolColor();
void setMarkerAngle(double angle);
void setMarkerSize(int size);
void setLineWidth(int width);
void setMarkerSize(double size);
void setLineWidth(double width);

};
6 changes: 3 additions & 3 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -8,7 +8,7 @@

#include <cmath>

QgsSimpleLineSymbolLayerV2::QgsSimpleLineSymbolLayerV2(QColor color, int width, Qt::PenStyle penStyle)
QgsSimpleLineSymbolLayerV2::QgsSimpleLineSymbolLayerV2(QColor color, double width, Qt::PenStyle penStyle)
: mPenStyle(penStyle), mOffset(0)
{
mColor = color;
Expand All @@ -19,13 +19,13 @@ QgsSimpleLineSymbolLayerV2::QgsSimpleLineSymbolLayerV2(QColor color, int width,
QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::create(const QgsStringMap& props)
{
QColor color = DEFAULT_SIMPLELINE_COLOR;
int width = DEFAULT_SIMPLELINE_WIDTH;
double width = DEFAULT_SIMPLELINE_WIDTH;
Qt::PenStyle penStyle = DEFAULT_SIMPLELINE_PENSTYLE;

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

Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgslinesymbollayerv2.h
Expand Up @@ -15,7 +15,7 @@ class QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
{
public:
QgsSimpleLineSymbolLayerV2(QColor color = DEFAULT_SIMPLELINE_COLOR,
int width = DEFAULT_SIMPLELINE_WIDTH,
double width = DEFAULT_SIMPLELINE_WIDTH,
Qt::PenStyle penStyle = DEFAULT_SIMPLELINE_PENSTYLE);

// static stuff
Expand Down
6 changes: 3 additions & 3 deletions src/core/symbology-ng/qgssymbollayerv2.h
Expand Up @@ -89,15 +89,15 @@ class QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
public:
virtual void renderPolyline(const QPolygonF& points, QgsRenderContext& context) = 0;

void setWidth(int width) { mWidth = width; }
int width() const { return mWidth; }
void setWidth(double width) { mWidth = width; }
double width() const { return mWidth; }

void drawPreviewIcon(QPainter* painter, QSize size);

protected:
QgsLineSymbolLayerV2(bool locked = false);

int mWidth;
double mWidth;
};

class QgsFillSymbolLayerV2 : public QgsSymbolLayerV2
Expand Down
38 changes: 28 additions & 10 deletions src/core/symbology-ng/qgssymbolv2.cpp
Expand Up @@ -252,13 +252,21 @@ double QgsMarkerSymbolV2::angle()
return 0;
}

void QgsMarkerSymbolV2::setSize(double size)
void QgsMarkerSymbolV2::setSize(double s)
{
// TODO: proportionally set size of layers
double origSize = size();

for (QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it)
{
QgsMarkerSymbolLayerV2* layer = (QgsMarkerSymbolLayerV2*) *it;
layer->setSize(size);
if (layer->size() == origSize)
layer->setSize(s);
else
{
// proportionally scale size
if (origSize != 0)
layer->setSize(layer->size() * s / origSize);
}
}
}

Expand Down Expand Up @@ -308,24 +316,34 @@ QgsLineSymbolV2::QgsLineSymbolV2(QgsSymbolLayerV2List layers)
mLayers.append(new QgsSimpleLineSymbolLayerV2());
}

void QgsLineSymbolV2::setWidth(int width)
void QgsLineSymbolV2::setWidth(double w)
{
// TODO: proportionally set width of layers
double origWidth = width();

for (QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it)
{
QgsLineSymbolLayerV2* layer = (QgsLineSymbolLayerV2*) *it;
layer->setWidth(width);
if (layer->width() == origWidth)
{
layer->setWidth(w);
}
else
{
// proportionally scale the width
if (origWidth != 0)
layer->setWidth( layer->width() * w / origWidth );
}
}
}

int QgsLineSymbolV2::width()
double QgsLineSymbolV2::width()
{
int maxWidth = 0;
double maxWidth = 0;
for (QgsSymbolLayerV2List::const_iterator it = mLayers.begin(); it != mLayers.end(); ++it)
{
const QgsLineSymbolLayerV2* layer = (const QgsLineSymbolLayerV2*) *it;
int width = layer->width();
if (maxWidth > width)
double width = layer->width();
if (width > maxWidth)
maxWidth = width;
}
return maxWidth;
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgssymbolv2.h
Expand Up @@ -106,8 +106,8 @@ class QgsLineSymbolV2 : public QgsSymbolV2
public:
QgsLineSymbolV2(QgsSymbolLayerV2List layers = QgsSymbolLayerV2List());

void setWidth(int width);
int width();
void setWidth(double width);
double width();

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

Expand Down
10 changes: 5 additions & 5 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -32,7 +32,7 @@ QgsSimpleLineSymbolLayerV2Widget::QgsSimpleLineSymbolLayerV2Widget(QWidget* pare

setupUi(this);

connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(penWidthChanged()));
connect(spinWidth, SIGNAL(valueChanged(double)), this, SLOT(penWidthChanged()));
connect(btnChangeColor, SIGNAL(clicked()), this, SLOT(colorChanged()));
connect(cboPenStyle, SIGNAL(currentIndexChanged(int)), this, SLOT(penStyleChanged()));
connect(spinOffset, SIGNAL(valueChanged(double)), this, SLOT(offsetChanged()));
Expand Down Expand Up @@ -114,7 +114,7 @@ QgsSimpleMarkerSymbolLayerV2Widget::QgsSimpleMarkerSymbolLayerV2Widget(QWidget*
connect(lstNames, SIGNAL(currentRowChanged(int)), this, SLOT(setName()));
connect(btnChangeColorBorder, SIGNAL(clicked()), this, SLOT(setColorBorder()));
connect(btnChangeColorFill, SIGNAL(clicked()), this, SLOT(setColorFill()));
connect(spinSize, SIGNAL(valueChanged(int)), this, SLOT(setSize()));
connect(spinSize, SIGNAL(valueChanged(double)), this, SLOT(setSize()));
connect(spinAngle, SIGNAL(valueChanged(double)), this, SLOT(setAngle()));
connect(spinOffsetX, SIGNAL(valueChanged(double)), this, SLOT(setOffset()));
connect(spinOffsetY, SIGNAL(valueChanged(double)), this, SLOT(setOffset()));
Expand Down Expand Up @@ -270,7 +270,7 @@ QgsMarkerLineSymbolLayerV2Widget::QgsMarkerLineSymbolLayerV2Widget(QWidget* pare

setupUi(this);

connect(spinInterval, SIGNAL(valueChanged(int)), this, SLOT(setInterval(int)));
connect(spinInterval, SIGNAL(valueChanged(double)), this, SLOT(setInterval(double)));
connect(btnChangeMarker, SIGNAL(clicked()), this, SLOT(setMarker()));
connect(chkRotateMarker, SIGNAL(clicked()), this, SLOT(setRotate()));
connect(spinOffset, SIGNAL(valueChanged(double)), this, SLOT(setOffset()));
Expand All @@ -296,7 +296,7 @@ QgsSymbolLayerV2* QgsMarkerLineSymbolLayerV2Widget::symbolLayer()
return mLayer;
}

void QgsMarkerLineSymbolLayerV2Widget::setInterval(int val)
void QgsMarkerLineSymbolLayerV2Widget::setInterval(double val)
{
mLayer->setInterval(val);
emit changed();
Expand Down Expand Up @@ -345,7 +345,7 @@ QgsSvgMarkerSymbolLayerV2Widget::QgsSvgMarkerSymbolLayerV2Widget(QWidget* parent
populateList();

connect(viewImages->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(setName(const QModelIndex&)));
connect(spinSize, SIGNAL(valueChanged(int)), this, SLOT(setSize()));
connect(spinSize, SIGNAL(valueChanged(double)), this, SLOT(setSize()));
connect(spinAngle, SIGNAL(valueChanged(double)), this, SLOT(setAngle()));
connect(spinOffsetX, SIGNAL(valueChanged(double)), this, SLOT(setOffset()));
connect(spinOffsetY, SIGNAL(valueChanged(double)), this, SLOT(setOffset()));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology-ng/qgssymbollayerv2widget.h
Expand Up @@ -131,7 +131,7 @@ class QgsMarkerLineSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private

public slots:

void setInterval(int val);
void setInterval(double val);
void setMarker();
void setRotate();
void setOffset();
Expand Down
8 changes: 4 additions & 4 deletions src/gui/symbology-ng/qgssymbolv2selectordialog.cpp
Expand Up @@ -36,8 +36,8 @@ QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsSty

connect(btnSetColor, SIGNAL(clicked()), this, SLOT(setSymbolColor()));
connect(spinAngle, SIGNAL(valueChanged(double)), this, SLOT(setMarkerAngle(double)));
connect(spinSize, SIGNAL(valueChanged(int)), this, SLOT(setMarkerSize(int)));
connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(setLineWidth(int)));
connect(spinSize, SIGNAL(valueChanged(double)), this, SLOT(setMarkerSize(double)));
connect(spinWidth, SIGNAL(valueChanged(double)), this, SLOT(setLineWidth(double)));

}

Expand Down Expand Up @@ -154,7 +154,7 @@ void QgsSymbolV2SelectorDialog::setMarkerAngle(double angle)
updateSymbolPreview();
}

void QgsSymbolV2SelectorDialog::setMarkerSize(int size)
void QgsSymbolV2SelectorDialog::setMarkerSize(double size)
{
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>(mSymbol);
if (markerSymbol->size() == size)
Expand All @@ -163,7 +163,7 @@ void QgsSymbolV2SelectorDialog::setMarkerSize(int size)
updateSymbolPreview();
}

void QgsSymbolV2SelectorDialog::setLineWidth(int width)
void QgsSymbolV2SelectorDialog::setLineWidth(double width)
{
QgsLineSymbolV2* lineSymbol = static_cast<QgsLineSymbolV2*>(mSymbol);
if (lineSymbol->width() == width)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/symbology-ng/qgssymbolv2selectordialog.h
Expand Up @@ -28,8 +28,8 @@ public slots:
void setSymbolFromStyle(const QModelIndex & index);
void setSymbolColor();
void setMarkerAngle(double angle);
void setMarkerSize(int size);
void setLineWidth(int width);
void setMarkerSize(double size);
void setLineWidth(double width);

protected:
QgsStyleV2* mStyle;
Expand Down
8 changes: 6 additions & 2 deletions src/ui/qgsrendererv2propsdialogbase.ui
Expand Up @@ -95,7 +95,7 @@
<item row="0" column="2">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="pageSingleSymbol">
<layout class="QGridLayout">
Expand Down Expand Up @@ -394,7 +394,11 @@
</layout>
</item>
<item>
<widget class="QTreeView" name="viewGraduated"/>
<widget class="QTreeView" name="viewGraduated">
<property name="rootIsDecorated">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
Expand Down

0 comments on commit 9ae3ae2

Please sign in to comment.