Skip to content

Commit

Permalink
Add methods for retrieving and setting size units for QgsMarkerSymbolV2
Browse files Browse the repository at this point in the history
(cherry-picked from e21de03)
  • Loading branch information
nyalldawson committed Apr 15, 2016
1 parent ccbecb3 commit bc0181c
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 1 deletion.
66 changes: 65 additions & 1 deletion python/core/symbology-ng/qgssymbolv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,19 @@ class QgsMarkerSymbolV2 : QgsSymbolV2

QgsMarkerSymbolV2( const QgsSymbolLayerV2List& layers /Transfer/ = QgsSymbolLayerV2List() );

/** Sets the angle for the whole symbol. Individual symbol layer sizes
* will be rotated to maintain their current relative angle to the whole symbol angle.
* @param angle new symbol angle
* @see angle()
*/
void setAngle( double angle );

/** Returns the marker angle for the whole symbol. Note that for symbols with
* multiple symbol layers, this will correspond just to the angle of
* the first symbol layer.
* @note added in QGIS 2.16
* @see setAngle()
*/
double angle() const;

/** Set data defined angle for whole symbol (including all symbol layers).
Expand All @@ -389,9 +401,60 @@ class QgsMarkerSymbolV2 : QgsSymbolV2
*/
void setLineAngle( double lineAngle );

/** Sets the size for the whole symbol. Individual symbol layer sizes
* will be scaled to maintain their current relative size to the whole symbol size.
* @param size new symbol size
* @see size()
* @see setSizeUnit()
* @see setSizeMapUnitScale()
*/
void setSize( double size );

/** Returns the size for the whole symbol, which is the maximum size of
* all marker symbol layers in the symbol.
* @see setSize()
* @see sizeUnit()
* @see sizeMapUnitScale()
*/
double size() const;

/** Sets the size units for the whole symbol (including all symbol layers).
* @param unit size units
* @note added in QGIS 2.16
* @see sizeUnit()
* @see setSizeMapUnitScale()
* @see setSize()
*/
void setSizeUnit( OutputUnit unit );

/** Returns the size units for the whole symbol (including all symbol layers).
* @returns size units, or mixed units if symbol layers have different units
* @note added in QGIS 2.16
* @see setSizeUnit()
* @see sizeMapUnitScale()
* @see size()
*/
OutputUnit sizeUnit() const;

/** Sets the size map unit scale for the whole symbol (including all symbol layers).
* @param scale map unit scale
* @note added in QGIS 2.16
* @see sizeMapUnitScale()
* @see setSizeUnit()
* @see setSize()
*/
void setSizeMapUnitScale( const QgsMapUnitScale& scale );

/** Returns the size map unit scale for the whole symbol. Note that for symbols with
* multiple symbol layers, this will correspond just to the map unit scale
* for the first symbol layer.
* @note added in QGIS 2.16
* @see setSizeMapUnitScale()
* @see sizeUnit()
* @see size()
*/
QgsMapUnitScale sizeMapUnitScale() const;

/** Set data defined size for whole symbol (including all symbol layers).
* @param dd data defined size
* @note added in QGIS 2.9
Expand All @@ -415,7 +478,8 @@ class QgsMarkerSymbolV2 : QgsSymbolV2
/** Returns the approximate bounding box of the marker symbol, which includes the bounding box
* of all symbol layers for the symbol.
* @returns approximate symbol bounds, in painter units
* @note added in QGIS 2.14 */
* @note added in QGIS 2.14
*/
QRectF bounds( QPointF point, QgsRenderContext& context ) const;

virtual QgsMarkerSymbolV2* clone() const /Factory/;
Expand Down
61 changes: 61 additions & 0 deletions src/core/symbology-ng/qgssymbolv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,67 @@ double QgsMarkerSymbolV2::size() const
return maxSize;
}

void QgsMarkerSymbolV2::setSizeUnit( QgsSymbolV2::OutputUnit unit )
{
Q_FOREACH ( QgsSymbolLayerV2* layer, mLayers )
{
if ( layer->type() != QgsSymbolV2::Marker )
continue;

QgsMarkerSymbolLayerV2* markerLayer = static_cast<QgsMarkerSymbolLayerV2*>( layer );
markerLayer->setSizeUnit( unit );
}
}

QgsSymbolV2::OutputUnit QgsMarkerSymbolV2::sizeUnit() const
{
bool first = true;
OutputUnit unit = Mixed;

Q_FOREACH ( QgsSymbolLayerV2* layer, mLayers )
{
if ( layer->type() != QgsSymbolV2::Marker )
continue;
const QgsMarkerSymbolLayerV2* markerLayer = static_cast<const QgsMarkerSymbolLayerV2*>( layer );

if ( first )
unit = markerLayer->sizeUnit();
else
{
if ( unit != markerLayer->sizeUnit() )
return Mixed;
}

first = false;
}
return unit;
}

void QgsMarkerSymbolV2::setSizeMapUnitScale( const QgsMapUnitScale &scale )
{
Q_FOREACH ( QgsSymbolLayerV2* layer, mLayers )
{
if ( layer->type() != QgsSymbolV2::Marker )
continue;

QgsMarkerSymbolLayerV2* markerLayer = static_cast<QgsMarkerSymbolLayerV2*>( layer );
markerLayer->setSizeMapUnitScale( scale );
}
}

QgsMapUnitScale QgsMarkerSymbolV2::sizeMapUnitScale() const
{
Q_FOREACH ( QgsSymbolLayerV2* layer, mLayers )
{
if ( layer->type() != QgsSymbolV2::Marker )
continue;

QgsMarkerSymbolLayerV2* markerLayer = static_cast<QgsMarkerSymbolLayerV2*>( layer );
return markerLayer->sizeMapUnitScale();
}
return QgsMapUnitScale();
}

void QgsMarkerSymbolV2::setDataDefinedSize( const QgsDataDefined &dd )
{
const double symbolSize = size();
Expand Down
64 changes: 64 additions & 0 deletions src/core/symbology-ng/qgssymbolv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,27 @@ class CORE_EXPORT QgsSymbolV2RenderContext
class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
{
public:

/** Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
* This is a convenience method for easier creation of marker symbols.
*/
static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );

QgsMarkerSymbolV2( const QgsSymbolLayerV2List& layers = QgsSymbolLayerV2List() );

/** Sets the angle for the whole symbol. Individual symbol layer sizes
* will be rotated to maintain their current relative angle to the whole symbol angle.
* @param angle new symbol angle
* @see angle()
*/
void setAngle( double angle );

/** Returns the marker angle for the whole symbol. Note that for symbols with
* multiple symbol layers, this will correspond just to the angle of
* the first symbol layer.
* @note added in QGIS 2.16
* @see setAngle()
*/
double angle() const;

/** Set data defined angle for whole symbol (including all symbol layers).
Expand All @@ -457,9 +470,60 @@ class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
*/
void setLineAngle( double lineAngle );

/** Sets the size for the whole symbol. Individual symbol layer sizes
* will be scaled to maintain their current relative size to the whole symbol size.
* @param size new symbol size
* @see size()
* @see setSizeUnit()
* @see setSizeMapUnitScale()
*/
void setSize( double size );

/** Returns the size for the whole symbol, which is the maximum size of
* all marker symbol layers in the symbol.
* @see setSize()
* @see sizeUnit()
* @see sizeMapUnitScale()
*/
double size() const;

/** Sets the size units for the whole symbol (including all symbol layers).
* @param unit size units
* @note added in QGIS 2.16
* @see sizeUnit()
* @see setSizeMapUnitScale()
* @see setSize()
*/
void setSizeUnit( OutputUnit unit );

/** Returns the size units for the whole symbol (including all symbol layers).
* @returns size units, or mixed units if symbol layers have different units
* @note added in QGIS 2.16
* @see setSizeUnit()
* @see sizeMapUnitScale()
* @see size()
*/
OutputUnit sizeUnit() const;

/** Sets the size map unit scale for the whole symbol (including all symbol layers).
* @param scale map unit scale
* @note added in QGIS 2.16
* @see sizeMapUnitScale()
* @see setSizeUnit()
* @see setSize()
*/
void setSizeMapUnitScale( const QgsMapUnitScale& scale );

/** Returns the size map unit scale for the whole symbol. Note that for symbols with
* multiple symbol layers, this will correspond just to the map unit scale
* for the first symbol layer.
* @note added in QGIS 2.16
* @see setSizeMapUnitScale()
* @see sizeUnit()
* @see size()
*/
QgsMapUnitScale sizeMapUnitScale() const;

/** Set data defined size for whole symbol (including all symbol layers).
* @param dd data defined size
* @note added in QGIS 2.9
Expand Down

0 comments on commit bc0181c

Please sign in to comment.