Skip to content

Commit

Permalink
Added offset property (X,Y) also for marker symbol layers.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@10809 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed May 17, 2009
1 parent 1188ebb commit 276b81d
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 100 deletions.
31 changes: 24 additions & 7 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}


Expand Down Expand Up @@ -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();
}
Expand All @@ -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)
Expand Down Expand Up @@ -244,6 +251,7 @@ QgsSvgMarkerSymbolLayerV2::QgsSvgMarkerSymbolLayerV2(QString name, double size,
mName = name;
mSize = size;
mAngle = angle;
mOffset = QPointF(0,0);
}


Expand All @@ -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;
}


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


Expand All @@ -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;
}
6 changes: 5 additions & 1 deletion src/core/symbology-ng/qgssymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class QgsVectorColorRampV2;
class QColor;
class QIcon;
class QPixmap;
class QPointF;
class QSize;

class QgsSymbolLayerV2Utils
Expand All @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -185,6 +195,12 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setAngle()
emit changed();
}

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


///////////

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class QgsSimpleMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, privat
void setColorFill();
void setSize();
void setAngle();

void setOffset();

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

void setOffset();

protected:

void populateList();
Expand Down
Loading

0 comments on commit 276b81d

Please sign in to comment.