18 #include <QStringList>
35 :
QgsExpression( createExpression( type, baseExpression, minValue, maxValue, minSize, maxSize, nullSize, exponent ) )
36 , mExpression( baseExpression )
40 , mMinValue( minValue )
41 , mMaxValue( maxValue )
42 , mNullSize( nullSize )
64 void QgsScaleExpression::init()
72 const NodeFunction * f =
dynamic_cast<const NodeFunction*
>(
rootNode() );
80 if (
"coalesce" ==
Functions()[f->fnIndex()]->name() )
82 f =
dynamic_cast<const NodeFunction*
>( args[0] );
88 args = f->args()->list();
91 if (
"scale_linear" ==
Functions()[f->fnIndex()]->name() )
95 else if (
"scale_exp" ==
Functions()[f->fnIndex()]->name() )
127 mExpression = args[0]->dump();
130 QString QgsScaleExpression::createExpression( Type type,
const QString & baseExpr,
double minValue,
double maxValue,
double minSize,
double maxSize,
double nullSize,
double exponent )
142 return QString(
"coalesce(scale_linear(%1, %2, %3, %4, %5), %6)" ).
arg( baseExpr, minValueString, maxValueString, minSizeString, maxSizeString, nullSizeString );
147 return QString(
"coalesce(scale_exp(%1, %2, %3, %4, %5, %6), %7)" ).
arg( baseExpr, minValueString, maxValueString, minSizeString, maxSizeString, exponentString, nullSizeString );
160 return mMinSize + ( qBound( mMinValue, value, mMaxValue ) - mMinValue ) * ( mMaxSize - mMinSize ) / ( mMaxValue - mMinValue );
165 return mMinSize + qPow( qBound( mMinValue, value, mMaxValue ) - mMinValue, mExponent ) * ( mMaxSize - mMinSize ) / qPow( mMaxValue - mMinValue, mExponent );
QgsScaleExpression(const QString &expression)
Constructor for QgsScaleExpression which parses an expression string to determine whether it's a scal...
Class for parsing and evaluation of expressions (formerly called "search strings").
double size(double value) const
Calculates the size corresponding to a specific value.
QgsExpression()
Used by QgsOgcUtils to create an empty.
QString dump() const
Return an expression string, constructed from the internal abstract syntax tree.
const Node * rootNode() const
Returns root node of the expression. Root node is null is parsing has failed.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
static const QList< Function * > & Functions()
QString number(int n, int base)
double exponent() const
Returns the exponent of the exponential expression.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const