Skip to content
Permalink
Browse files

Added offset property (X,Y) also for marker symbol layers.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@10809 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed May 17, 2009
1 parent 1188ebb commit 276b81d038d728080912def066e7d58830781766
@@ -26,6 +26,7 @@ QgsSimpleMarkerSymbolLayerV2::QgsSimpleMarkerSymbolLayerV2(QString name, QColor
mBorderColor = borderColor;
mSize = size;
mAngle = angle;
mOffset = QPointF(0,0);
}

QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::create(const QgsStringMap& props)
@@ -47,7 +48,10 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::create(const QgsStringMap& props
if (props.contains("angle"))
angle = props["angle"].toDouble();

return new QgsSimpleMarkerSymbolLayerV2(name, color, borderColor, size, angle);
QgsSimpleMarkerSymbolLayerV2* m = new QgsSimpleMarkerSymbolLayerV2(name, color, borderColor, size, angle);
if (props.contains("offset"))
m->setOffset( QgsSymbolLayerV2Utils::decodePoint(props["offset"]) );
return m;
}


@@ -184,7 +188,7 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint(const QPointF& point, QgsRenderCo
//drawMarker(p);
double s = mCache.width();
//if (mCache.isValid())
p->drawImage(point + QPointF(-s/2.0, -s/2.0), mCache);
p->drawImage(point + QPointF(-s/2.0, -s/2.0) + mOffset, mCache);

//p->restore();
}
@@ -198,12 +202,15 @@ QgsStringMap QgsSimpleMarkerSymbolLayerV2::properties() const
map["color_border"] = QgsSymbolLayerV2Utils::encodeColor(mBorderColor);
map["size"] = QString::number(mSize);
map["angle"] = QString::number(mAngle);
map["offset"] = QgsSymbolLayerV2Utils::encodePoint(mOffset);
return map;
}

QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::clone() const
{
return new QgsSimpleMarkerSymbolLayerV2(mName, mColor, mBorderColor, mSize, mAngle);
QgsSimpleMarkerSymbolLayerV2* m = new QgsSimpleMarkerSymbolLayerV2(mName, mColor, mBorderColor, mSize, mAngle);
m->setOffset( mOffset );
return m;
}

void QgsSimpleMarkerSymbolLayerV2::drawMarker(QPainter* p)
@@ -244,6 +251,7 @@ QgsSvgMarkerSymbolLayerV2::QgsSvgMarkerSymbolLayerV2(QString name, double size,
mName = name;
mSize = size;
mAngle = angle;
mOffset = QPointF(0,0);
}


@@ -260,7 +268,10 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::create(const QgsStringMap& props)
if (props.contains("angle"))
angle = props["angle"].toDouble();

return new QgsSvgMarkerSymbolLayerV2(name, size, angle);
QgsSvgMarkerSymbolLayerV2* m = new QgsSvgMarkerSymbolLayerV2(name, size, angle);
if (props.contains("offset"))
m->setOffset( QgsSymbolLayerV2Utils::decodePoint(props["offset"]) );
return m;
}


@@ -288,15 +299,18 @@ void QgsSvgMarkerSymbolLayerV2::stopRender(QgsRenderContext& context)
void QgsSvgMarkerSymbolLayerV2::renderPoint(const QPointF& point, QgsRenderContext& context)
{
QPainter* p = context.painter();
p->translate(point);
p->save();
p->translate(point + mOffset);

if (mAngle != 0)
p->rotate(mAngle);

p->drawPicture(0,0, mPicture);

if (mAngle != 0)
p->rotate(-mAngle);
p->translate(-point); // TODO: maybe save+restore is faster?

p->restore();
}


@@ -306,10 +320,13 @@ QgsStringMap QgsSvgMarkerSymbolLayerV2::properties() const
map["name"] = mName;
map["size"] = QString::number(mSize);
map["angle"] = QString::number(mAngle);
map["offset"] = QgsSymbolLayerV2Utils::encodePoint(mOffset);
return map;
}

QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::clone() const
{
return new QgsSvgMarkerSymbolLayerV2(mName, mSize, mAngle);
QgsSvgMarkerSymbolLayerV2* m = new QgsSvgMarkerSymbolLayerV2(mName, mSize, mAngle);
m->setOffset( mOffset );
return m;
}
@@ -5,14 +5,14 @@
#include <QMap>

#include <QColor>
#include <QPointF>

#include "qgssymbolv2.h"

#include "qgssymbollayerv2utils.h" // QgsStringMap

class QPainter;
class QSize;
class QPointF;
class QPolygonF;

class QgsRenderContext;
@@ -72,12 +72,16 @@ class QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2

void setSize(double size) { mSize = size; }
double size() const { return mSize; }

void setOffset(QPointF offset) { mOffset = offset; }
QPointF offset() { return mOffset; }

protected:
QgsMarkerSymbolLayerV2(bool locked = false);

double mAngle;
double mSize;
QPointF mOffset;
};

class QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
@@ -87,6 +87,18 @@ Qt::BrushStyle QgsSymbolLayerV2Utils::decodeBrushStyle(QString str)
return Qt::SolidPattern;
}

QString QgsSymbolLayerV2Utils::encodePoint(QPointF point)
{
return QString("%1,%2").arg(point.x()).arg(point.y());
}

QPointF QgsSymbolLayerV2Utils::decodePoint(QString str)
{
QStringList lst = str.split(',');
if (lst.count() != 2)
return QPointF(0,0);
return QPointF( lst[0].toDouble(), lst[1].toDouble() );
}

QIcon QgsSymbolLayerV2Utils::symbolPreviewIcon(QgsSymbolV2* symbol, QSize size)
{
@@ -15,6 +15,7 @@ class QgsVectorColorRampV2;
class QColor;
class QIcon;
class QPixmap;
class QPointF;
class QSize;

class QgsSymbolLayerV2Utils
@@ -29,6 +30,9 @@ class QgsSymbolLayerV2Utils

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

static QString encodePoint(QPointF point);
static QPointF decodePoint(QString str);

static QIcon symbolPreviewIcon(QgsSymbolV2* symbol, QSize size);
static QIcon symbolLayerPreviewIcon(QgsSymbolLayerV2* layer, QSize size);
@@ -116,6 +116,8 @@ QgsSimpleMarkerSymbolLayerV2Widget::QgsSimpleMarkerSymbolLayerV2Widget(QWidget*
connect(btnChangeColorFill, SIGNAL(clicked()), this, SLOT(setColorFill()));
connect(spinSize, SIGNAL(valueChanged(int)), 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()));
}

void QgsSimpleMarkerSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
@@ -140,6 +142,14 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)
updateColorButton(btnChangeColorFill, mLayer->color());
spinSize->setValue(mLayer->size());
spinAngle->setValue(mLayer->angle());

// without blocking signals the value gets changed because of slot setOffset()
spinOffsetX->blockSignals(true);
spinOffsetX->setValue(mLayer->offset().x());
spinOffsetX->blockSignals(false);
spinOffsetY->blockSignals(true);
spinOffsetY->setValue(mLayer->offset().y());
spinOffsetY->blockSignals(false);
}

QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2Widget::symbolLayer()
@@ -185,6 +195,12 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setAngle()
emit changed();
}

void QgsSimpleMarkerSymbolLayerV2Widget::setOffset()
{
mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
emit changed();
}


///////////

@@ -331,6 +347,8 @@ QgsSvgMarkerSymbolLayerV2Widget::QgsSvgMarkerSymbolLayerV2Widget(QWidget* parent
connect(viewImages->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(setName(const QModelIndex&)));
connect(spinSize, SIGNAL(valueChanged(int)), 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()));
}

void QgsSvgMarkerSymbolLayerV2Widget::populateList()
@@ -395,6 +413,14 @@ void QgsSvgMarkerSymbolLayerV2Widget::setSymbolLayer(QgsSymbolLayerV2* layer)

spinSize->setValue(mLayer->size());
spinAngle->setValue(mLayer->angle());

// without blocking signals the value gets changed because of slot setOffset()
spinOffsetX->blockSignals(true);
spinOffsetX->setValue(mLayer->offset().x());
spinOffsetX->blockSignals(false);
spinOffsetY->blockSignals(true);
spinOffsetY->setValue(mLayer->offset().y());
spinOffsetY->blockSignals(false);
}

QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2Widget::symbolLayer()
@@ -422,6 +448,12 @@ void QgsSvgMarkerSymbolLayerV2Widget::setAngle()
emit changed();
}

void QgsSvgMarkerSymbolLayerV2Widget::setOffset()
{
mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
emit changed();
}

///////////////

QgsLineDecorationSymbolLayerV2Widget::QgsLineDecorationSymbolLayerV2Widget(QWidget* parent)
@@ -75,7 +75,8 @@ class QgsSimpleMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, privat
void setColorFill();
void setSize();
void setAngle();

void setOffset();

protected:
QgsSimpleMarkerSymbolLayerV2* mLayer;
};
@@ -166,7 +167,8 @@ class QgsSvgMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private U
void setName(const QModelIndex& idx);
void setSize();
void setAngle();

void setOffset();

protected:

void populateList();

0 comments on commit 276b81d

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