@@ -84,7 +84,7 @@ QgsFeatureRequest& QgsFeatureRequest::operator=( const QgsFeatureRequest & rh )
84
84
mAttrs = rh.mAttrs ;
85
85
mSimplifyMethod = rh.mSimplifyMethod ;
86
86
mLimit = rh.mLimit ;
87
- mOrderBys = rh.mOrderBys ;
87
+ mOrderBy = rh.mOrderBy ;
88
88
return *this ;
89
89
}
90
90
@@ -144,24 +144,25 @@ QgsFeatureRequest &QgsFeatureRequest::setExpressionContext( const QgsExpressionC
144
144
145
145
QgsFeatureRequest& QgsFeatureRequest::addOrderBy ( const QString& expression, bool ascending )
146
146
{
147
- mOrderBys .append ( OrderByClause ( expression, ascending ) );
147
+ mOrderBy .append ( OrderByClause ( expression, ascending ) );
148
148
return *this ;
149
149
}
150
150
151
151
QgsFeatureRequest& QgsFeatureRequest::addOrderBy ( const QString& expression, bool ascending, bool nullsfirst )
152
152
{
153
- mOrderBys .append ( OrderByClause ( expression, ascending, nullsfirst ) );
153
+ mOrderBy .append ( OrderByClause ( expression, ascending, nullsfirst ) );
154
154
return *this ;
155
155
}
156
156
157
- QList< QgsFeatureRequest::OrderByClause> QgsFeatureRequest::orderBys () const
157
+ QgsFeatureRequest::OrderBy QgsFeatureRequest::orderBy () const
158
158
{
159
- return mOrderBys ;
159
+ return mOrderBy ;
160
160
}
161
161
162
- void QgsFeatureRequest::setOrderBys ( const QList< QgsFeatureRequest::OrderByClause>& orderBys )
162
+ QgsFeatureRequest& QgsFeatureRequest::setOrderBy ( const QgsFeatureRequest::OrderBy& orderBy )
163
163
{
164
- mOrderBys = orderBys;
164
+ mOrderBy = orderBy;
165
+ return *this ;
165
166
}
166
167
167
168
QgsFeatureRequest& QgsFeatureRequest::setLimit ( long limit )
@@ -307,7 +308,90 @@ void QgsFeatureRequest::OrderByClause::setNullsFirst( bool nullsFirst )
307
308
mNullsFirst = nullsFirst;
308
309
}
309
310
311
+ QString QgsFeatureRequest::OrderByClause::dump () const
312
+ {
313
+ return QString ( " %1 %2 %3" )
314
+ .arg ( mExpression .expression () )
315
+ .arg ( mAscending ? " ASC" : " DESC" )
316
+ .arg ( mNullsFirst ? " NULLS FIRST" : " NULLS LAST" );
317
+ }
318
+
310
319
QgsExpression QgsFeatureRequest::OrderByClause::expression () const
311
320
{
312
321
return mExpression ;
313
322
}
323
+
324
+ QgsFeatureRequest::OrderBy::OrderBy ( const QList<QgsFeatureRequest::OrderByClause>& other )
325
+ {
326
+ Q_FOREACH ( const QgsFeatureRequest::OrderByClause& clause, other )
327
+ {
328
+ append ( clause );
329
+ }
330
+ }
331
+
332
+ QList<QgsFeatureRequest::OrderByClause> QgsFeatureRequest::OrderBy::list () const
333
+ {
334
+ return *this ;
335
+ }
336
+
337
+ void QgsFeatureRequest::OrderBy::save ( QDomElement& elem ) const
338
+ {
339
+ QDomDocument doc = elem.ownerDocument ();
340
+ QList<OrderByClause>::ConstIterator it;
341
+ for ( it = constBegin (); it != constEnd (); ++it )
342
+ {
343
+ const OrderByClause& clause = *it;
344
+ QDomElement clauseElem = doc.createElement ( " orderByClause" );
345
+ clauseElem.setAttribute ( " asc" , clause.ascending () );
346
+ clauseElem.setAttribute ( " nullsFirst" , clause.nullsFirst () );
347
+ clauseElem.appendChild ( doc.createTextNode ( clause.expression ().expression () ) );
348
+
349
+ elem.appendChild ( clauseElem );
350
+ }
351
+ }
352
+
353
+ void QgsFeatureRequest::OrderBy::load ( const QDomElement& elem )
354
+ {
355
+ clear ();
356
+
357
+ QDomNodeList clauses = elem.childNodes ();
358
+
359
+ for ( int i = 0 ; i < clauses.size (); ++i )
360
+ {
361
+ QDomElement clauseElem = clauses.at ( i ).toElement ();
362
+ QString expression = clauseElem.text ();
363
+ bool asc = clauseElem.attribute ( " asc" ).toInt () != 0 ;
364
+ bool nullsFirst = clauseElem.attribute ( " nullsFirst" ).toInt () != 0 ;
365
+
366
+ append ( OrderByClause ( expression, asc, nullsFirst ) );
367
+ }
368
+ }
369
+
370
+ QSet<QString> QgsFeatureRequest::OrderBy::usedAttributes () const
371
+ {
372
+ QSet<QString> usedAttributes;
373
+
374
+ QList<OrderByClause>::ConstIterator it;
375
+ for ( it = constBegin (); it != constEnd (); ++it )
376
+ {
377
+ const OrderByClause& clause = *it;
378
+
379
+ usedAttributes.unite ( clause.expression ().referencedColumns ().toSet () );
380
+ }
381
+
382
+ return usedAttributes;
383
+ }
384
+ QString QgsFeatureRequest::OrderBy::dump () const
385
+ {
386
+ QStringList results;
387
+
388
+ QList<OrderByClause>::ConstIterator it;
389
+ for ( it = constBegin (); it != constEnd (); ++it )
390
+ {
391
+ const OrderByClause& clause = *it;
392
+
393
+ results << clause.dump ();
394
+ }
395
+
396
+ return results.join ( " , " );
397
+ }
0 commit comments