18 #include <QStringList>
34 :
QgsExpression( createExpression( type, baseExpression, minValue, maxValue, minSize, maxSize, nullSize ) )
35 , mExpression( baseExpression )
39 , mMinValue( minValue )
40 , mMaxValue( maxValue )
41 , mNullSize( nullSize )
46 void QgsScaleExpression::init()
54 const NodeFunction * f =
dynamic_cast<const NodeFunction*
>(
rootNode() );
62 if (
"coalesce" ==
Functions()[f->fnIndex()]->name() )
64 f =
dynamic_cast<const NodeFunction*
>( args[0] );
70 args = f->args()->list();
73 if (
"scale_linear" ==
Functions()[f->fnIndex()]->name() )
77 else if (
"scale_exp" ==
Functions()[f->fnIndex()]->name() )
111 mExpression = args[0]->dump();
114 QString QgsScaleExpression::createExpression( Type type,
const QString & baseExpr,
double minValue,
double maxValue,
double minSize,
double maxSize,
double nullSize )
125 return QString(
"coalesce(scale_linear(%1, %2, %3, %4, %5), %6)" ).
arg( baseExpr, minValueString, maxValueString, minSizeString, maxSizeString, nullSizeString );
128 return QString(
"coalesce(scale_exp(%1, %2, %3, %4, %5, 0.5), %6)" ).
arg( baseExpr, minValueString, maxValueString, minSizeString, maxSizeString, nullSizeString );
131 return QString(
"coalesce(scale_exp(%1, %2, %3, %4, %5, 0.57), %6)" ).
arg( baseExpr, minValueString, maxValueString, minSizeString, maxSizeString, nullSizeString );
144 return mMinSize + ( qBound( mMinValue, value, mMaxValue ) - mMinValue ) * ( mMaxSize - mMinSize ) / ( mMaxValue - mMinValue );
147 return mMinSize + qPow( qBound( mMinValue, value, mMaxValue ) - mMinValue, .5 ) * ( mMaxSize - mMinSize ) / qPow( mMaxValue - mMinValue, .5 );
150 return mMinSize + qPow( qBound( mMinValue, value, mMaxValue ) - mMinValue, .57 ) * ( mMaxSize - mMinSize ) / qPow( mMaxValue - mMinValue, .57 );
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 the expression string that represents this QgsExpression.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
static const QList< Function * > & Functions()
QString number(int n, int base)
const Node * rootNode() const
Returns root node of the expression. Root node is null is parsing has failed.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const