16 #ifndef QGSEXPRESSIONSORTER_H 17 #define QGSEXPRESSIONSORTER_H 25 class QgsExpressionSorter
28 explicit QgsExpressionSorter(
const QList<QgsFeatureRequest::OrderByClause> &preparedOrderBys )
29 : mPreparedOrderBys( preparedOrderBys )
33 , mUseCaseInsensitiveComparison( QLocale::system().name() == QLocale::c().name() )
41 const QVariant &v1 = f1.
mIndexes.at( i );
42 const QVariant &v2 = f2.
mIndexes.at( i );
46 if ( v1.isNull() && v2.isNull() )
50 if ( v1.isNull() != v2.isNull() )
63 case QVariant::LongLong:
64 case QVariant::ULongLong:
65 if ( v1.toLongLong() == v2.toLongLong() )
68 return v1.toLongLong() < v2.toLongLong();
70 return v1.toLongLong() > v2.toLongLong();
72 case QVariant::Double:
76 return v1.toDouble() < v2.toDouble();
78 return v1.toDouble() > v2.toDouble();
81 if ( v1.toDate() == v2.toDate() )
84 return v1.toDate() < v2.toDate();
86 return v1.toDate() > v2.toDate();
89 if ( v1.toTime() == v2.toTime() )
92 return v1.toTime() < v2.toTime();
94 return v1.toTime() > v2.toTime();
96 case QVariant::DateTime:
97 if ( v1.toDateTime() == v2.toDateTime() )
100 return v1.toDateTime() < v2.toDateTime();
102 return v1.toDateTime() > v2.toDateTime();
105 if ( v1.toBool() == v2.toBool() )
113 if ( 0 == v1.toString().localeAwareCompare( v2.toString() ) )
115 if ( mUseCaseInsensitiveComparison )
118 return v1.toString().compare( v2.toString(), Qt::CaseInsensitive ) < 0;
120 return v1.toString().compare( v2.toString(), Qt::CaseInsensitive ) > 0;
125 return v1.toString().localeAwareCompare( v2.toString() ) < 0;
127 return v1.toString().localeAwareCompare( v2.toString() ) > 0;
142 QVector<QgsIndexedFeature> indexedFeatures;
148 indexedFeature.
mIndexes.resize( mPreparedOrderBys.size() );
156 indexedFeature.
mIndexes.replace( i++, orderBy.
expression().evaluate( expressionContext ) );
158 indexedFeatures.append( indexedFeature );
161 delete expressionContext->
popScope();
163 std::sort( indexedFeatures.begin(), indexedFeatures.end(), *this );
168 features.append( indexedFeature.
mFeature );
172 QList<QgsFeatureRequest::OrderByClause> mPreparedOrderBys;
173 bool mUseCaseInsensitiveComparison;
179 #endif // QGSEXPRESSIONSORTER_H bool nullsFirst() const
Set if NULLS should be returned first.
bool ascending() const
Order ascending.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
Temporarily used structure to cache order by information.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Single scope for storing variables and functions for use within a QgsExpressionContext.
The OrderByClause class represents an order by clause for a QgsFeatureRequest.
QgsExpression expression() const
The expression.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
QVector< QVariant > mIndexes
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.