25 QString QgsOrderByExpressionAlgorithm::name()
const
27 return QStringLiteral(
"orderbyexpression" );
30 QString QgsOrderByExpressionAlgorithm::displayName()
const
32 return QObject::tr(
"Order by expression" );
35 QStringList QgsOrderByExpressionAlgorithm::tags()
const
37 return QObject::tr(
"orderby,sort,expression,field" ).split(
',' );
40 QString QgsOrderByExpressionAlgorithm::group()
const
42 return QObject::tr(
"Vector general" );
45 QString QgsOrderByExpressionAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeneral" );
50 void QgsOrderByExpressionAlgorithm::initAlgorithm(
const QVariantMap & )
60 QString QgsOrderByExpressionAlgorithm::shortHelpString()
const
62 return QObject::tr(
"This algorithm sorts a vector layer according to an expression. Be careful, it might not work as expected with some providers, the order might not be kept every time." );
65 QgsOrderByExpressionAlgorithm *QgsOrderByExpressionAlgorithm::createInstance()
const
67 return new QgsOrderByExpressionAlgorithm();
72 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
76 QString expressionString = parameterAsExpression( parameters, QStringLiteral(
"EXPRESSION" ), context );
78 bool ascending = parameterAsBoolean( parameters, QStringLiteral(
"ASCENDING" ), context );
79 bool nullsFirst = parameterAsBoolean( parameters, QStringLiteral(
"NULLS_FIRST" ), context );
82 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, sinkId, source->fields(), source->wkbType(), source->sourceCrs() ) );
86 long count = source->featureCount();
87 double step = count > 0 ? 100.0 / count : 1;
91 request.
addOrderBy( expressionString, ascending, nullsFirst );
101 sink->addFeature( inFeature );
107 outputs.insert( QStringLiteral(
"OUTPUT" ), sinkId );