Skip to content

Commit

Permalink
Output unit for simple marker
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Mar 11, 2013
1 parent c771505 commit d6b140a
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 60 deletions.
20 changes: 16 additions & 4 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ QgsSimpleMarkerSymbolLayerV2::QgsSimpleMarkerSymbolLayerV2( QString name, QColor
mAngle = angle;
mOffset = QPointF( 0, 0 );
mScaleMethod = scaleMethod;
mSizeUnit = QgsSymbolV2::MM;
mOffsetUnit = QgsSymbolV2::MM;
}

QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::create( const QgsStringMap& props )
Expand Down Expand Up @@ -82,6 +84,10 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::create( const QgsStringMap& prop
QgsSimpleMarkerSymbolLayerV2* m = new QgsSimpleMarkerSymbolLayerV2( name, color, borderColor, size, angle, scaleMethod );
if ( props.contains( "offset" ) )
m->setOffset( QgsSymbolLayerV2Utils::decodePoint( props["offset"] ) );
if ( props.contains( "offset_unit" ) )
m->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["offset_unit"] ) );
if ( props.contains( "size_unit" ) )
m->setSizeUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["size_unit"] ) );
return m;
}

Expand Down Expand Up @@ -146,7 +152,7 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
// scale the shape (if the size is not going to be modified)
if ( !hasDataDefinedSize )
{
double scaledSize = context.outputLineWidth( mSize );
double scaledSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );
if ( mUsingCache )
scaledSize *= context.renderContext().rasterScaleFactor();
double half = scaledSize / 2.0;
Expand Down Expand Up @@ -178,7 +184,7 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex

void QgsSimpleMarkerSymbolLayerV2::prepareCache( QgsSymbolV2RenderContext& context )
{
double scaledSize = context.outputPixelSize( mSize );
double scaledSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );

// calculate necessary image size for the cache
double pw = (( mPen.widthF() == 0 ? 1 : mPen.widthF() ) + 1 ) / 2 * 2; // make even (round up); handle cosmetic pen
Expand Down Expand Up @@ -375,7 +381,9 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
return;
}

QPointF off( context.outputLineWidth( mOffset.x() ), context.outputLineWidth( mOffset.y() ) );
double offsetX = mOffset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
double offsetY = mOffset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
QPointF off( offsetX, offsetY );
if ( mAngle )
off = _rotatedOffset( off, mAngle );

Expand All @@ -401,7 +409,7 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
// resize if necessary
if ( hasDataDefinedSize )
{
double scaledSize = context.outputLineWidth( mSize );
double scaledSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );

switch ( mScaleMethod )
{
Expand Down Expand Up @@ -440,8 +448,10 @@ QgsStringMap QgsSimpleMarkerSymbolLayerV2::properties() const
map["color"] = QgsSymbolLayerV2Utils::encodeColor( mColor );
map["color_border"] = QgsSymbolLayerV2Utils::encodeColor( mBorderColor );
map["size"] = QString::number( mSize );
map["size_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mSizeUnit );
map["angle"] = QString::number( mAngle );
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
map["scale_method"] = QgsSymbolLayerV2Utils::encodeScaleMethod( mScaleMethod );
return map;
}
Expand All @@ -450,6 +460,8 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::clone() const
{
QgsSimpleMarkerSymbolLayerV2* m = new QgsSimpleMarkerSymbolLayerV2( mName, mColor, mBorderColor, mSize, mAngle, mScaleMethod );
m->setOffset( mOffset );
m->setSizeUnit( mSizeUnit );
m->setOffsetUnit( mOffsetUnit );
return m;
}

Expand Down
18 changes: 17 additions & 1 deletion src/core/symbology-ng/qgssymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


QgsMarkerSymbolLayerV2::QgsMarkerSymbolLayerV2( bool locked )
: QgsSymbolLayerV2( QgsSymbolV2::Marker, locked )
: QgsSymbolLayerV2( QgsSymbolV2::Marker, locked ), mSizeUnit( QgsSymbolV2::MM ), mOffsetUnit( QgsSymbolV2::MM )
{
}

Expand All @@ -47,6 +47,22 @@ void QgsMarkerSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context,
stopRender( context );
}

void QgsMarkerSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
{
mSizeUnit = unit;
mOffsetUnit = unit;
}

QgsSymbolV2::OutputUnit QgsMarkerSymbolLayerV2::outputUnit() const
{
QgsSymbolV2::OutputUnit unit = mSizeUnit;
if ( mOffsetUnit != unit )
{
return QgsSymbolV2::Mixed;
}
return unit;
}

void QgsLineSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
{
QPolygonF points;
Expand Down
11 changes: 11 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,23 @@ class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
virtual void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
{ Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "QgsMarkerSymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); }

void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }

void setSizeUnit( QgsSymbolV2::OutputUnit unit ) { mSizeUnit = unit; }
QgsSymbolV2::OutputUnit sizeUnit() const { return mSizeUnit; }

virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit );
virtual QgsSymbolV2::OutputUnit outputUnit() const;

protected:
QgsMarkerSymbolLayerV2( bool locked = false );

double mAngle;
double mSize;
QgsSymbolV2::OutputUnit mSizeUnit;
QPointF mOffset;
QgsSymbolV2::OutputUnit mOffsetUnit;
QgsSymbolV2::ScaleMethod mScaleMethod;
};

Expand Down
1 change: 0 additions & 1 deletion src/core/symbology-ng/qgssymbolv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f,
QgsSymbolV2* QgsMarkerSymbolV2::clone() const
{
QgsSymbolV2* cloneSymbol = new QgsMarkerSymbolV2( cloneLayers() );
cloneSymbol->setOutputUnit( outputUnit() );
cloneSymbol->setAlpha( mAlpha );
return cloneSymbol;
}
Expand Down
23 changes: 23 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer
spinOffsetY->blockSignals( true );
spinOffsetY->setValue( mLayer->offset().y() );
spinOffsetY->blockSignals( false );

mSizeUnitComboBox->blockSignals( true );
mSizeUnitComboBox->setCurrentIndex( mLayer->sizeUnit() );
mSizeUnitComboBox->blockSignals( false );
mOffsetUnitComboBox->blockSignals( true );
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
mOffsetUnitComboBox->blockSignals( false );
}

QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2Widget::symbolLayer()
Expand Down Expand Up @@ -342,6 +349,22 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setOffset()
emit changed();
}

void QgsSimpleMarkerSymbolLayerV2Widget::on_mSizeUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setSizeUnit(( QgsSymbolV2::OutputUnit ) index );
}
}

void QgsSimpleMarkerSymbolLayerV2Widget::on_mOffsetUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setOffsetUnit(( QgsSymbolV2::OutputUnit ) index );
}
}


///////////

Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class GUI_EXPORT QgsSimpleMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Wid
void setSize();
void setAngle();
void setOffset();
void on_mSizeUnitComboBox_currentIndexChanged( int index );
void on_mOffsetUnitComboBox_currentIndexChanged( int index );

protected:
QgsSimpleMarkerSymbolLayerV2* mLayer;
Expand Down
129 changes: 75 additions & 54 deletions src/ui/symbollayer/widget_simplemarker.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>378</width>
<height>275</height>
<height>290</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -19,19 +19,6 @@
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="spinAngle">
<property name="decimals">
<number>2</number>
</property>
<property name="maximum">
<double>360.000000000000000</double>
</property>
<property name="singleStep">
<double>5.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="spinSize">
<property name="decimals">
Expand All @@ -45,17 +32,17 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColorBorder">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Change</string>
<string>Border color</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColorBorder">
<property name="text">
<string>Fill color</string>
<string>Change</string>
</property>
</widget>
</item>
Expand All @@ -66,35 +53,7 @@
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Offset X,Y</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColorFill">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Angle</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Border color</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDoubleSpinBox" name="spinOffsetX">
Expand All @@ -118,8 +77,28 @@
</item>
</layout>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="mUnitComboBox">
<item row="4" column="0">
<widget class="QLabel" name="mSizeUnitLabel">
<property name="text">
<string>Size unit</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDoubleSpinBox" name="spinAngle">
<property name="decimals">
<number>2</number>
</property>
<property name="maximum">
<double>360.000000000000000</double>
</property>
<property name="singleStep">
<double>5.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="mSizeUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
Expand All @@ -132,13 +111,55 @@
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mOutputUnitLabel">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Fill color</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Angle</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColorFill">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Offset X,Y</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="mOffsetUnitLabel">
<property name="text">
<string>Unit</string>
<string>Offset unit</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="mOffsetUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Map unit</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit d6b140a

Please sign in to comment.