Skip to content
Permalink
Browse files

Fix marker rotation

The rotation is no longer saved in the Qgs*SymbolRendererV2 but in the
QgsMarkerSymbolV2 in a QgsDataDefined. This commit fixes the legacy API and
redirects calls to the new API.
  • Loading branch information
m-kuhn authored and nyalldawson committed Aug 6, 2015
1 parent 118eea5 commit 1e6483c6d1afdd01f170340e4d5676deff627c34
@@ -123,8 +123,8 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2
//! @note added in 2.5
void updateColorRamp( QgsVectorColorRampV2* ramp, bool inverted = false );

void setRotationField( QString fieldOrExpression );
QString rotationField() const;
void setRotationField( QString fieldOrExpression ) /Deprecated/;
QString rotationField() const /Deprecated/;

void setSizeScaleField( QString fieldOrExpression );
QString sizeScaleField() const;
@@ -249,8 +249,8 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
//! @note added in 2.10
void setGraduatedMethod( GraduatedMethod method );

void setRotationField( QString fieldOrExpression );
QString rotationField() const;
void setRotationField( QString fieldOrExpression ) /Deprecated/;
QString rotationField() const /Deprecated/;

void setSizeScaleField( QString fieldOrExpression );
QString sizeScaleField() const;
@@ -173,9 +173,9 @@ class QgsFeatureRendererV2
void setVertexMarkerAppearance( int type, int size );

//! return rotation field name (or empty string if not set or not supported by renderer)
virtual QString rotationField() const;
virtual QString rotationField() const /Deprecated/;
//! sets rotation field of renderer (if supported by the renderer)
virtual void setRotationField( QString fieldName );
virtual void setRotationField( QString fieldName ) /Deprecated/;

//! return whether the renderer will render a feature or not.
//! Must be called between startRender() and stopRender() calls.
@@ -22,8 +22,8 @@ class QgsSingleSymbolRendererV2 : QgsFeatureRendererV2
QgsSymbolV2* symbol() const;
void setSymbol( QgsSymbolV2* s /Transfer/ );

void setRotationField( QString fieldOrExpression );
QString rotationField() const;
void setRotationField( QString fieldOrExpression ) /Deprecated/;
QString rotationField() const /Deprecated/;

void setSizeScaleField( QString fieldOrExpression );
QString sizeScaleField() const;
@@ -135,6 +135,11 @@ void QgsDataDefined::setExpressionString( const QString &expr )
d->exprRefColumns.clear();
}

QString QgsDataDefined::expressionOrField() const
{
return d->useExpression ? d->expressionString : QString( "\"%1\"" ).arg( d->field );
}

QMap<QString, QVariant> QgsDataDefined::expressionParams() const
{
return d->expressionParams;
@@ -91,15 +91,39 @@ class CORE_EXPORT QgsDataDefined
bool isActive() const;
void setActive( bool active );

/**
* Returns if the field or the expression part is active.
*
* @return True if it is in expression mode.
*/
bool useExpression() const;

void setUseExpression( bool use );

/**
* Returns the expression string of this QgsDataDefined.
*
* @return An expression
*
* @see field()
* @see expressionOrField()
*/
QString expressionString() const;

void setExpressionString( const QString& expr );

// @note not available in python bindings
/**
* Returns an expression which represents a single field if useExpression returns false
*
* @return An expression
*
* @note added in 2.12
*/
QString expressionOrField() const;

//! @note not available in python bindings
QMap<QString, QVariant> expressionParams() const;
// @note not available in python bindings
//! @note not available in python bindings
void setExpressionParams( QMap<QString, QVariant> params );
void insertExpressionParam( QString key, QVariant param );

@@ -134,7 +158,16 @@ class CORE_EXPORT QgsDataDefined
*/
QStringList referencedColumns( const QgsFields& fields = QgsFields() );

/**
* Get the field which this QgsDataDefined represents. Be aware that this may return
* a field name which may not be active if useExpression is true.
*
* @return A fieldname
*
* @see expressionOrField()
*/
QString field() const;

void setField( const QString& field );

/** Encodes the QgsDataDefined into a string map.
@@ -39,12 +39,12 @@ class QgsDataDefinedPrivate : public QSharedData
QgsDataDefinedPrivate( bool active = false,
bool useExpression = false,
const QString& expressionString = QString(),
const QString& field = QString() )
QString field = QString() )
: expression( 0 )
, active( active )
, useExpression( useExpression )
, expressionString( expressionString )
, field( field )
, field( field.remove( QRegExp( "^\"|\"$" ) ) )
, expressionPrepared( false )
{
}
@@ -493,9 +493,7 @@ QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2::clone() const
r->setInvertedColorRamp( mInvertedColorRamp );
}
r->setUsingSymbolLevels( usingSymbolLevels() );
r->setRotationField( rotationField() );
r->setSizeScaleField( sizeScaleField() );
//r->setScaleMethod( scaleMethod() );

copyPaintEffect( r );
return r;
@@ -815,12 +813,22 @@ void QgsCategorizedSymbolRendererV2::updateColorRamp( QgsVectorColorRampV2* ramp

void QgsCategorizedSymbolRendererV2::setRotationField( QString fieldOrExpression )
{
mRotation.reset( QgsSymbolLayerV2Utils::fieldOrExpressionToExpression( fieldOrExpression ) );
if ( mSourceSymbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( mSourceSymbol.data() );
s->setDataDefinedAngle( QgsDataDefined( fieldOrExpression ) );
}
}

QString QgsCategorizedSymbolRendererV2::rotationField() const
{
return mRotation.data() ? QgsSymbolLayerV2Utils::fieldOrExpressionFromExpression( mRotation.data() ) : QString();
if ( mSourceSymbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( mSourceSymbol.data() );
return s->dataDefinedAngle().expressionOrField();
}

return QString();
}

void QgsCategorizedSymbolRendererV2::setSizeScaleField( QString fieldOrExpression )
@@ -156,8 +156,8 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2
//! @note added in 2.5
void updateColorRamp( QgsVectorColorRampV2* ramp, bool inverted = false );

void setRotationField( QString fieldOrExpression ) override;
QString rotationField() const override;
Q_DECL_DEPRECATED void setRotationField( QString fieldOrExpression ) override;
Q_DECL_DEPRECATED QString rotationField() const override;

void setSizeScaleField( QString fieldOrExpression );
QString sizeScaleField() const;
@@ -518,9 +518,7 @@ QgsFeatureRendererV2* QgsGraduatedSymbolRendererV2::clone() const
r->setInvertedColorRamp( mInvertedColorRamp );
}
r->setUsingSymbolLevels( usingSymbolLevels() );
r->setRotationField( rotationField() );
r->setSizeScaleField( sizeScaleField() );
//r->setScaleMethod( scaleMethod() );
r->setLabelFormat( labelFormat() );
r->setGraduatedMethod( graduatedMethod() );
copyPaintEffect( r );
@@ -1365,12 +1363,23 @@ void QgsGraduatedSymbolRendererV2::updateSymbols( QgsSymbolV2 *sym )

void QgsGraduatedSymbolRendererV2::setRotationField( QString fieldOrExpression )
{
mRotation.reset( QgsSymbolLayerV2Utils::fieldOrExpressionToExpression( fieldOrExpression ) );
if ( mSourceSymbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( mSourceSymbol.data() );
s->setDataDefinedAngle( QgsDataDefined( fieldOrExpression ) );
}

}

QString QgsGraduatedSymbolRendererV2::rotationField() const
{
return mRotation.data() ? QgsSymbolLayerV2Utils::fieldOrExpressionFromExpression( mRotation.data() ) : QString();
if ( mSourceSymbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( mSourceSymbol.data() );
return s->dataDefinedAngle().expressionOrField();
}

return QString();
}

void QgsGraduatedSymbolRendererV2::setSizeScaleField( QString fieldOrExpression )
@@ -295,8 +295,8 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
//! @note added in 2.10
void setGraduatedMethod( GraduatedMethod method ) { mGraduatedMethod = method; }

void setRotationField( QString fieldOrExpression ) override;
QString rotationField() const override;
Q_DECL_DEPRECATED void setRotationField( QString fieldOrExpression ) override;
Q_DECL_DEPRECATED QString rotationField() const override;

void setSizeScaleField( QString fieldOrExpression );
QString sizeScaleField() const;
@@ -212,9 +212,11 @@ class CORE_EXPORT QgsFeatureRendererV2
void setVertexMarkerAppearance( int type, int size );

//! return rotation field name (or empty string if not set or not supported by renderer)
virtual QString rotationField() const { return ""; }
//! @deprecated use the symbol's methods instead
Q_DECL_DEPRECATED virtual QString rotationField() const { return QString(); }
//! sets rotation field of renderer (if supported by the renderer)
virtual void setRotationField( QString fieldName ) { Q_UNUSED( fieldName ); }
//! @deprecated use the symbol's methods instead
Q_DECL_DEPRECATED virtual void setRotationField( QString fieldName ) { Q_UNUSED( fieldName ); }

//! return whether the renderer will render a feature or not.
//! Must be called between startRender() and stopRender() calls.
@@ -153,12 +153,22 @@ void QgsSingleSymbolRendererV2::setSymbol( QgsSymbolV2* s )

void QgsSingleSymbolRendererV2::setRotationField( QString fieldOrExpression )
{
mRotation.reset( QgsSymbolLayerV2Utils::fieldOrExpressionToExpression( fieldOrExpression ) );
if ( mSymbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( mSymbol.data() );
s->setDataDefinedAngle( QgsDataDefined( fieldOrExpression ) );
}
}

QString QgsSingleSymbolRendererV2::rotationField() const
{
return mRotation.data() ? QgsSymbolLayerV2Utils::fieldOrExpressionFromExpression( mRotation.data() ) : QString();
if ( mSymbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( mSymbol.data() );
return s->dataDefinedAngle().expressionOrField();
}

return QString();
}

void QgsSingleSymbolRendererV2::setSizeScaleField( QString fieldOrExpression )
@@ -186,9 +196,7 @@ QgsFeatureRendererV2* QgsSingleSymbolRendererV2::clone() const
{
QgsSingleSymbolRendererV2* r = new QgsSingleSymbolRendererV2( mSymbol->clone() );
r->setUsingSymbolLevels( usingSymbolLevels() );
r->setRotationField( rotationField() );
r->setSizeScaleField( sizeScaleField() );
//r->setScaleMethod( scaleMethod() );
copyPaintEffect( r );
return r;
}
@@ -42,8 +42,8 @@ class CORE_EXPORT QgsSingleSymbolRendererV2 : public QgsFeatureRendererV2
QgsSymbolV2* symbol() const;
void setSymbol( QgsSymbolV2* s );

void setRotationField( QString fieldOrExpression ) override;
QString rotationField() const override;
Q_DECL_DEPRECATED void setRotationField( QString fieldOrExpression ) override;
Q_DECL_DEPRECATED QString rotationField() const override;

void setSizeScaleField( QString fieldOrExpression );
QString sizeScaleField() const;
@@ -450,11 +450,6 @@ QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsV
advMenu->addAction( tr( "Match to symbols from file..." ), this, SLOT( matchToSymbolsFromXml() ) );
advMenu->addAction( tr( "Symbol levels..." ), this, SLOT( showSymbolLevels() ) );

mDataDefinedMenus = new QgsRendererV2DataDefinedMenus( advMenu, mLayer,
mRenderer->rotationField(), mRenderer->sizeScaleField(), mRenderer->scaleMethod() );
connect( mDataDefinedMenus, SIGNAL( rotationFieldChanged( QString ) ), this, SLOT( rotationFieldChanged( QString ) ) );
connect( mDataDefinedMenus, SIGNAL( sizeScaleFieldChanged( QString ) ), this, SLOT( sizeScaleFieldChanged( QString ) ) );
connect( mDataDefinedMenus, SIGNAL( scaleMethodChanged( QgsSymbolV2::ScaleMethod ) ), this, SLOT( scaleMethodChanged( QgsSymbolV2::ScaleMethod ) ) );
btnAdvanced->setMenu( advMenu );
}

@@ -156,8 +156,6 @@ class GUI_EXPORT QgsCategorizedSymbolRendererV2Widget : public QgsRendererV2Widg

QgsSymbolV2* mCategorizedSymbol;

QgsRendererV2DataDefinedMenus* mDataDefinedMenus;

QgsCategorizedSymbolRendererV2Model* mModel;

private:
@@ -466,11 +466,6 @@ QgsGraduatedSymbolRendererV2Widget::QgsGraduatedSymbolRendererV2Widget( QgsVecto

advMenu->addAction( tr( "Symbol levels..." ), this, SLOT( showSymbolLevels() ) );

mDataDefinedMenus = new QgsRendererV2DataDefinedMenus( advMenu, mLayer,
mRenderer->rotationField(), mRenderer->sizeScaleField(), mRenderer->scaleMethod() );
connect( mDataDefinedMenus, SIGNAL( rotationFieldChanged( QString ) ), this, SLOT( rotationFieldChanged( QString ) ) );
connect( mDataDefinedMenus, SIGNAL( sizeScaleFieldChanged( QString ) ), this, SLOT( sizeScaleFieldChanged( QString ) ) );
connect( mDataDefinedMenus, SIGNAL( scaleMethodChanged( QgsSymbolV2::ScaleMethod ) ), this, SLOT( scaleMethodChanged( QgsSymbolV2::ScaleMethod ) ) );
btnAdvanced->setMenu( advMenu );

mHistogramWidget->setLayer( mLayer );
@@ -143,8 +143,6 @@ class GUI_EXPORT QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget

int mRowSelected;

QgsRendererV2DataDefinedMenus* mDataDefinedMenus;

QgsGraduatedSymbolRendererV2Model* mModel;

QgsRangeList mCopyBuffer;
@@ -63,12 +63,6 @@ QgsSingleSymbolRendererV2Widget::QgsSingleSymbolRendererV2Widget( QgsVectorLayer
QMenu* advMenu = mSelector->advancedMenu();

advMenu->addAction( tr( "Symbol levels..." ), this, SLOT( showSymbolLevels() ) );

mDataDefinedMenus = new QgsRendererV2DataDefinedMenus( advMenu, mLayer,
mRenderer->rotationField(), mRenderer->sizeScaleField(), mRenderer->scaleMethod() );
connect( mDataDefinedMenus, SIGNAL( rotationFieldChanged( QString ) ), this, SLOT( rotationFieldChanged( QString ) ) );
connect( mDataDefinedMenus, SIGNAL( sizeScaleFieldChanged( QString ) ), this, SLOT( sizeScaleFieldChanged( QString ) ) );
connect( mDataDefinedMenus, SIGNAL( scaleMethodChanged( QgsSymbolV2::ScaleMethod ) ), this, SLOT( scaleMethodChanged( QgsSymbolV2::ScaleMethod ) ) );
}

QgsSingleSymbolRendererV2Widget::~QgsSingleSymbolRendererV2Widget()
@@ -78,8 +72,6 @@ QgsSingleSymbolRendererV2Widget::~QgsSingleSymbolRendererV2Widget()
delete mRenderer;

delete mSelector;

delete mDataDefinedMenus;
}


@@ -48,8 +48,6 @@ class GUI_EXPORT QgsSingleSymbolRendererV2Widget : public QgsRendererV2Widget
QgsSingleSymbolRendererV2* mRenderer;
QgsSymbolV2SelectorDialog* mSelector;
QgsSymbolV2* mSingleSymbol;

QgsRendererV2DataDefinedMenus* mDataDefinedMenus;
};


0 comments on commit 1e6483c

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