Skip to content
Permalink
Browse files

QgsDataDefined: Implicit management for useExpression

  • Loading branch information
m-kuhn authored and nyalldawson committed Aug 6, 2015
1 parent 728ead8 commit 9c3d65ef7b2695237dd98dd91e627cd28737b3bf
@@ -71,6 +71,14 @@ class QgsDataDefined
* @return True if it is in expression mode.
*/
bool useExpression() const;

/**
* Controls if the field or the expression part is active.
* For QGIS<=2.10 it is mandatory to call this after {@link setExpressionString}
* or {@link setField}.
*
* @param use True if it should be set to expression mode.
*/
void setUseExpression( bool use );

/**
@@ -82,17 +90,25 @@ class QgsDataDefined
* @see expressionOrField()
*/
QString expressionString() const;


/**
* Sets the expression for this QgsDataDefined.
* Will also set useExpression to true.
*
* @param expr The expression to set
*
* @see setField
*/
void setExpressionString( const QString& expr );

/**
* Returns an expression which represents a single field if useExpression returns false, otherwise
* returns the current expression string.
* @return An expression
*
* @note added in 2.12
*/
QString expressionOrField() const;
QString expressionOrField() const;

// @note not available in python bindings
//QMap<QString, QVariant> expressionParams() const;
@@ -140,7 +156,13 @@ class QgsDataDefined
* @see expressionOrField()
*/
QString field() const;


/**
* Set the field name which this QgsDataDefined represents.
* Will set useExpression to false.
*
* @param field
*/
void setField( const QString& field );

/** Encodes the QgsDataDefined into a string map.
@@ -121,9 +121,9 @@ void QgsComposerObject::setDataDefinedProperty( const QgsComposerObject::DataDef
{
QgsDataDefined* dd = it.value();
dd->setActive( active );
dd->setUseExpression( useExpression );
dd->setExpressionString( expression );
dd->setField( field );
dd->setUseExpression( useExpression );
}
}
else if ( !defaultVals )
@@ -365,6 +365,8 @@ void QgsComposerUtils::readDataDefinedProperty( const QgsComposerObject::DataDef
{
dd->setActive( false );
}
dd->setField( ddElem.attribute( "field" ) );
dd->setExpressionString( ddElem.attribute( "expr" ) );
QString useExpr = ddElem.attribute( "useExpr" );
if ( useExpr.compare( "true", Qt::CaseInsensitive ) == 0 )
{
@@ -374,8 +376,6 @@ void QgsComposerUtils::readDataDefinedProperty( const QgsComposerObject::DataDef
{
dd->setUseExpression( false );
}
dd->setField( ddElem.attribute( "field" ) );
dd->setExpressionString( ddElem.attribute( "expr" ) );
}

void QgsComposerUtils::writeDataDefinedPropertyMap( QDomElement &itemElem, QDomDocument &doc, const QMap<QgsComposerObject::DataDefinedProperty, QString> *dataDefinedNames, const QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties )
@@ -3024,9 +3024,9 @@ void QgsComposition::setDataDefinedProperty( const QgsComposerObject::DataDefine
{
QgsDataDefined* dd = it.value();
dd->setActive( active );
dd->setUseExpression( useExpression );
dd->setExpressionString( expression );
dd->setField( field );
dd->setUseExpression( useExpression );
}
}
else if ( !defaultVals )
@@ -130,6 +130,7 @@ void QgsDataDefined::setExpressionString( const QString &expr )

d.detach();

d->useExpression = true;
d->expressionString = expr;
d->expressionPrepared = false;
d->exprRefColumns.clear();
@@ -268,6 +269,7 @@ void QgsDataDefined::setField( const QString &field )
return;

d.detach();
d->useExpression = false;
d->field = field;
d->exprRefColumns.clear();
}
@@ -98,6 +98,13 @@ class CORE_EXPORT QgsDataDefined
*/
bool useExpression() const;

/**
* Controls if the field or the expression part is active.
* For QGIS<=2.10 it is mandatory to call this after {@link setExpressionString}
* or {@link setField}.
*
* @param use True if it should be set to expression mode.
*/
void setUseExpression( bool use );

/**
@@ -110,6 +117,14 @@ class CORE_EXPORT QgsDataDefined
*/
QString expressionString() const;

/**
* Sets the expression for this QgsDataDefined.
* Will also set useExpression to true.
*
* @param expr The expression to set
*
* @see setField
*/
void setExpressionString( const QString& expr );

/**
@@ -168,6 +183,12 @@ class CORE_EXPORT QgsDataDefined
*/
QString field() const;

/**
* Set the field name which this QgsDataDefined represents.
* Will set useExpression to false.
*
* @param field
*/
void setField( const QString& field );

/** Encodes the QgsDataDefined into a string map.
@@ -1097,9 +1097,9 @@ void QgsPalLayerSettings::setDataDefinedProperty( QgsPalLayerSettings::DataDefin
{
QgsDataDefined* dd = it.value();
dd->setActive( active );
dd->setUseExpression( useExpr );
dd->setExpressionString( expr );
dd->setField( field );
dd->setUseExpression( useExpr );
}
}
else if ( !defaultVals )
@@ -42,32 +42,32 @@ inline
QgsDataDefined* rotateWholeSymbol( double additionalRotation, const QgsDataDefined& dd )
{
QgsDataDefined* rotatedDD = new QgsDataDefined( dd );
rotatedDD->setUseExpression( true );
QString exprString = dd.useExpression() ? dd.expressionString() : dd.field();
rotatedDD->setExpressionString( QString::number( additionalRotation ) + " + (" + exprString + ")" );
rotatedDD->setUseExpression( true );
return rotatedDD;
}

inline
QgsDataDefined* scaleWholeSymbol( double scaleFactor, const QgsDataDefined& dd )
{
QgsDataDefined* scaledDD = new QgsDataDefined( dd );
scaledDD->setUseExpression( true );
QString exprString = dd.useExpression() ? dd.expressionString() : dd.field();
scaledDD->setExpressionString( QString::number( scaleFactor ) + "*(" + exprString + ")" );
scaledDD->setUseExpression( true );
return scaledDD;
}

inline
QgsDataDefined* scaleWholeSymbol( double scaleFactorX, double scaleFactorY, const QgsDataDefined& dd )
{
QgsDataDefined* scaledDD = new QgsDataDefined( dd );
scaledDD->setUseExpression( true );
QString exprString = dd.useExpression() ? dd.expressionString() : dd.field();
scaledDD->setExpressionString(
( scaleFactorX ? "tostring(" + QString::number( scaleFactorX ) + "*(" + exprString + "))" : "'0'" ) +
"|| ',' || " +
( scaleFactorY ? "tostring(" + QString::number( scaleFactorY ) + "*(" + exprString + "))" : "'0'" ) );
scaledDD->setUseExpression( true );
return scaledDD;
}

@@ -203,9 +203,9 @@ void QgsDataDefinedButton::updateDataDefined( QgsDataDefined *dd ) const
return;

dd->setActive( isActive() );
dd->setUseExpression( useExpression() );
dd->setExpressionString( getExpression() );
dd->setField( getField() );
dd->setUseExpression( useExpression() );
}

QgsDataDefined QgsDataDefinedButton::currentDataDefined() const

0 comments on commit 9c3d65e

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