Skip to content

Commit abd2607

Browse files
committedMay 1, 2017
Allow QgsFeatureRequest::OrderBy expressions to be prepared
1 parent 8031ac4 commit abd2607

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
 

‎src/core/qgsfeaturerequest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,22 @@ QgsFeatureRequest::OrderByClause::OrderByClause( const QString &expression, bool
302302
{
303303
}
304304

305+
QgsFeatureRequest::OrderByClause::OrderByClause( const QgsExpression &expression, bool ascending )
306+
: mExpression( expression )
307+
, mAscending( ascending )
308+
{
309+
// postgres behavior: default for ASC: NULLS LAST, default for DESC: NULLS FIRST
310+
mNullsFirst = !ascending;
311+
}
312+
313+
QgsFeatureRequest::OrderByClause::OrderByClause( const QgsExpression &expression, bool ascending, bool nullsfirst )
314+
: mExpression( expression )
315+
, mAscending( ascending )
316+
, mNullsFirst( nullsfirst )
317+
{
318+
319+
}
320+
305321
bool QgsFeatureRequest::OrderByClause::ascending() const
306322
{
307323
return mAscending;
@@ -335,6 +351,11 @@ QgsExpression QgsFeatureRequest::OrderByClause::expression() const
335351
return mExpression;
336352
}
337353

354+
bool QgsFeatureRequest::OrderByClause::prepare( QgsExpressionContext *context )
355+
{
356+
return mExpression.prepare( context );
357+
}
358+
338359
QgsFeatureRequest::OrderBy::OrderBy( const QList<QgsFeatureRequest::OrderByClause> &other )
339360
{
340361
Q_FOREACH ( const QgsFeatureRequest::OrderByClause &clause, other )

‎src/core/qgsfeaturerequest.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,40 @@ class CORE_EXPORT QgsFeatureRequest
138138
*/
139139
OrderByClause( const QString &expression, bool ascending, bool nullsfirst );
140140

141+
/**
142+
* Creates a new OrderByClause for a QgsFeatureRequest
143+
*
144+
* \param expression The expression to use for ordering
145+
* \param ascending If the order should be ascending (1,2,3) or descending (3,2,1)
146+
* If the order is ascending, by default nulls are last
147+
* If the order is descending, by default nulls are first
148+
*/
149+
OrderByClause( const QgsExpression &expression, bool ascending = true );
150+
151+
/**
152+
* Creates a new OrderByClause for a QgsFeatureRequest
153+
*
154+
* \param expression The expression to use for ordering
155+
* \param ascending If the order should be ascending (1,2,3) or descending (3,2,1)
156+
* \param nullsfirst If true, NULLS are at the beginning, if false, NULLS are at the end
157+
*/
158+
OrderByClause( const QgsExpression &expression, bool ascending, bool nullsfirst );
159+
141160
/**
142161
* The expression
143162
* \returns the expression
144163
*/
145164
QgsExpression expression() const;
146165

166+
/**
167+
* Prepare the expression with the given context.
168+
*
169+
* \see QgsExpression::prepare
170+
*
171+
* \since QGIS 3.0
172+
*/
173+
bool prepare( QgsExpressionContext *context );
174+
147175
/**
148176
* Order ascending
149177
* \returns If ascending order is requested

0 commit comments

Comments
 (0)
Please sign in to comment.