Skip to content

Commit 96a01e0

Browse files
committed
Output units for point pattern and line pattern symbol layers
1 parent 47ee439 commit 96a01e0

File tree

4 files changed

+108
-6
lines changed

4 files changed

+108
-6
lines changed

src/core/symbology-ng/qgsfillsymbollayerv2.cpp

+39-6
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,8 @@ QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::createFromSld( QDomElement &ele
11201120
////////////////////////
11211121

11221122
QgsPointPatternFillSymbolLayer::QgsPointPatternFillSymbolLayer(): QgsImageFillSymbolLayer(), mMarkerSymbol( 0 ), mDistanceX( 15 ),
1123-
mDistanceY( 15 ), mDisplacementX( 0 ), mDisplacementY( 0 )
1123+
mDistanceXUnit( QgsSymbolV2::MM ), mDistanceY( 15 ), mDistanceYUnit( QgsSymbolV2::MM ), mDisplacementX( 0 ), mDisplacementXUnit( QgsSymbolV2::MM ),
1124+
mDisplacementY( 0 ), mDisplacementYUnit( QgsSymbolV2::MM )
11241125
{
11251126
mDistanceX = 15;
11261127
mDistanceY = 15;
@@ -1153,6 +1154,29 @@ QgsSymbolLayerV2* QgsPointPatternFillSymbolLayer::create( const QgsStringMap& pr
11531154
{
11541155
layer->setDisplacementY( properties["displacement_y"].toDouble() );
11551156
}
1157+
1158+
/*propertyMap["distance_x_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mDistanceXUnit );
1159+
propertyMap["distance_y_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mDistanceYUnit );
1160+
propertyMap["displacement_x_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mDisplacementXUnit );
1161+
propertyMap["displacement_y_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mDisplacementYUnit );*/
1162+
1163+
if ( properties.contains( "distance_x_unit" ) )
1164+
{
1165+
layer->setDistanceXUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["distance_x_unit"] ) );
1166+
}
1167+
if ( properties.contains( "distance_y_unit" ) )
1168+
{
1169+
layer->setDistanceYUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["distance_y_unit"] ) );
1170+
}
1171+
if ( properties.contains( "displacement_x_unit" ) )
1172+
{
1173+
layer->setDisplacementXUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["displacement_x_unit"] ) );
1174+
}
1175+
if ( properties.contains( "displacement_y_unit" ) )
1176+
{
1177+
layer->setDisplacementYUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["displacement_y_unit"] ) );
1178+
}
1179+
11561180
return layer;
11571181
}
11581182

@@ -1164,8 +1188,9 @@ QString QgsPointPatternFillSymbolLayer::layerType() const
11641188
void QgsPointPatternFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
11651189
{
11661190
//render 3 rows and columns in one go to easily incorporate displacement
1167-
double width = context.outputPixelSize( mDistanceX ) * 2.0;
1168-
double height = context.outputPixelSize( mDistanceY ) * 2.0;
1191+
const QgsRenderContext& ctx = context.renderContext();
1192+
double width = mDistanceX * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceXUnit ) * 2.0;
1193+
double height = mDistanceY * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceYUnit ) * 2.0;
11691194

11701195
if ( width > 10000 || height > 10000 ) //protect symbol layer from eating too much memory
11711196
{
@@ -1200,8 +1225,8 @@ void QgsPointPatternFillSymbolLayer::startRender( QgsSymbolV2RenderContext& cont
12001225
mMarkerSymbol->renderPoint( QPointF( width, height ), context.feature(), pointRenderContext );
12011226

12021227
//render displaced points
1203-
double displacementPixelX = context.outputPixelSize( mDisplacementX );
1204-
double displacementPixelY = context.outputPixelSize( mDisplacementY );
1228+
double displacementPixelX = mDisplacementX * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDisplacementXUnit );
1229+
double displacementPixelY = mDisplacementY * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDisplacementYUnit );
12051230
mMarkerSymbol->renderPoint( QPointF( width / 2.0, -displacementPixelY ), context.feature(), pointRenderContext );
12061231
mMarkerSymbol->renderPoint( QPointF( displacementPixelX, height / 2.0 ), context.feature(), pointRenderContext );
12071232
mMarkerSymbol->renderPoint( QPointF( width / 2.0 + displacementPixelX, height / 2.0 - displacementPixelY ), context.feature(), pointRenderContext );
@@ -1246,16 +1271,24 @@ QgsStringMap QgsPointPatternFillSymbolLayer::properties() const
12461271
propertyMap["distance_y"] = QString::number( mDistanceY );
12471272
propertyMap["displacement_x"] = QString::number( mDisplacementX );
12481273
propertyMap["displacement_y"] = QString::number( mDisplacementY );
1274+
propertyMap["distance_x_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mDistanceXUnit );
1275+
propertyMap["distance_y_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mDistanceYUnit );
1276+
propertyMap["displacement_x_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mDisplacementXUnit );
1277+
propertyMap["displacement_y_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mDisplacementYUnit );
12491278
return propertyMap;
12501279
}
12511280

12521281
QgsSymbolLayerV2* QgsPointPatternFillSymbolLayer::clone() const
12531282
{
1254-
QgsSymbolLayerV2* clonedLayer = QgsPointPatternFillSymbolLayer::create( properties() );
1283+
QgsPointPatternFillSymbolLayer* clonedLayer = static_cast<QgsPointPatternFillSymbolLayer*>( QgsPointPatternFillSymbolLayer::create( properties() ) );
12551284
if ( mMarkerSymbol )
12561285
{
12571286
clonedLayer->setSubSymbol( mMarkerSymbol->clone() );
12581287
}
1288+
clonedLayer->setDistanceXUnit( mDistanceXUnit );
1289+
clonedLayer->setDistanceYUnit( mDistanceYUnit );
1290+
clonedLayer->setDisplacementXUnit( mDisplacementXUnit );
1291+
clonedLayer->setDisplacementYUnit( mDisplacementYUnit );
12591292
return clonedLayer;
12601293
}
12611294

src/core/symbology-ng/qgsfillsymbollayerv2.h

+16
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,28 @@ class CORE_EXPORT QgsPointPatternFillSymbolLayer: public QgsImageFillSymbolLayer
297297
bool setSubSymbol( QgsSymbolV2* symbol );
298298
virtual QgsSymbolV2* subSymbol() { return mMarkerSymbol; }
299299

300+
void setDistanceXUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceXUnit = unit; }
301+
QgsSymbolV2::OutputUnit distanceXUnit() const { return mDistanceXUnit; }
302+
303+
void setDistanceYUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceYUnit = unit; }
304+
QgsSymbolV2::OutputUnit distanceYUnit() const { return mDistanceYUnit; }
305+
306+
void setDisplacementXUnit( QgsSymbolV2::OutputUnit unit ) { mDisplacementXUnit = unit; }
307+
QgsSymbolV2::OutputUnit displacementXUnit() const { return mDisplacementXUnit; }
308+
309+
void setDisplacementYUnit( QgsSymbolV2::OutputUnit unit ) { mDisplacementYUnit = unit; }
310+
QgsSymbolV2::OutputUnit displacementYUnit() const { return mDisplacementYUnit; }
311+
300312
protected:
301313
QgsMarkerSymbolV2* mMarkerSymbol;
302314
double mDistanceX;
315+
QgsSymbolV2::OutputUnit mDistanceXUnit;
303316
double mDistanceY;
317+
QgsSymbolV2::OutputUnit mDistanceYUnit;
304318
double mDisplacementX;
319+
QgsSymbolV2::OutputUnit mDisplacementXUnit;
305320
double mDisplacementY;
321+
QgsSymbolV2::OutputUnit mDisplacementYUnit;
306322
};
307323

308324
class CORE_EXPORT QgsCentroidFillSymbolLayerV2 : public QgsFillSymbolLayerV2

src/gui/symbology-ng/qgssymbollayerv2widget.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,19 @@ void QgsPointPatternFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* lay
14401440
mVerticalDistanceSpinBox->setValue( mLayer->distanceY() );
14411441
mHorizontalDisplacementSpinBox->setValue( mLayer->displacementX() );
14421442
mVerticalDisplacementSpinBox->setValue( mLayer->displacementY() );
1443+
1444+
mHorizontalDistanceUnitComboBox->blockSignals( true );
1445+
mHorizontalDistanceUnitComboBox->setCurrentIndex( mLayer->distanceXUnit() );
1446+
mHorizontalDistanceUnitComboBox->blockSignals( false );
1447+
mVerticalDistanceUnitComboBox->blockSignals( true );
1448+
mVerticalDistanceUnitComboBox->setCurrentIndex( mLayer->distanceYUnit() );
1449+
mVerticalDistanceUnitComboBox->blockSignals( false );
1450+
mHorizontalDisplacementUnitComboBox->blockSignals( true );
1451+
mHorizontalDisplacementUnitComboBox->setCurrentIndex( mLayer->displacementXUnit() );
1452+
mHorizontalDisplacementUnitComboBox->blockSignals( false );
1453+
mVerticalDisplacementUnitComboBox->blockSignals( true );
1454+
mVerticalDisplacementUnitComboBox->setCurrentIndex( mLayer->displacementYUnit() );
1455+
mVerticalDisplacementUnitComboBox->blockSignals( false );
14431456
}
14441457

14451458
QgsSymbolLayerV2* QgsPointPatternFillSymbolLayerWidget::symbolLayer()
@@ -1483,6 +1496,42 @@ void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDisplacementSpinBox_value
14831496
}
14841497
}
14851498

1499+
void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDistanceUnitComboBox_currentIndexChanged( int index )
1500+
{
1501+
if ( mLayer )
1502+
{
1503+
mLayer->setDistanceXUnit(( QgsSymbolV2::OutputUnit ) index );
1504+
emit changed();
1505+
}
1506+
}
1507+
1508+
void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDistanceUnitComboBox_currentIndexChanged( int index )
1509+
{
1510+
if ( mLayer )
1511+
{
1512+
mLayer->setDistanceYUnit(( QgsSymbolV2::OutputUnit ) index );
1513+
emit changed();
1514+
}
1515+
}
1516+
1517+
void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDisplacementUnitComboBox_currentIndexChanged( int index )
1518+
{
1519+
if ( mLayer )
1520+
{
1521+
mLayer->setDisplacementXUnit(( QgsSymbolV2::OutputUnit ) index );
1522+
emit changed();
1523+
}
1524+
}
1525+
1526+
void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDisplacementUnitComboBox_currentIndexChanged( int index )
1527+
{
1528+
if ( mLayer )
1529+
{
1530+
mLayer->setDisplacementYUnit(( QgsSymbolV2::OutputUnit ) index );
1531+
emit changed();
1532+
}
1533+
}
1534+
14861535
/////////////
14871536

14881537
QgsFontMarkerSymbolLayerV2Widget::QgsFontMarkerSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent )

src/gui/symbology-ng/qgssymbollayerv2widget.h

+4
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ class GUI_EXPORT QgsPointPatternFillSymbolLayerWidget: public QgsSymbolLayerV2Wi
349349
void on_mVerticalDistanceSpinBox_valueChanged( double d );
350350
void on_mHorizontalDisplacementSpinBox_valueChanged( double d );
351351
void on_mVerticalDisplacementSpinBox_valueChanged( double d );
352+
void on_mHorizontalDistanceUnitComboBox_currentIndexChanged( int index );
353+
void on_mVerticalDistanceUnitComboBox_currentIndexChanged( int index );
354+
void on_mHorizontalDisplacementUnitComboBox_currentIndexChanged( int index );
355+
void on_mVerticalDisplacementUnitComboBox_currentIndexChanged( int index );
352356
};
353357

354358
/////////

0 commit comments

Comments
 (0)