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, "
63 "the order might not be kept every time.\n\n"
64 "For help with QGIS expression functions, see the inbuilt help for specific functions "
65 "which is available in the expression builder." );
68 QgsOrderByExpressionAlgorithm *QgsOrderByExpressionAlgorithm::createInstance()
const
70 return new QgsOrderByExpressionAlgorithm();
75 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
79 const QString expressionString = parameterAsExpression( parameters, QStringLiteral(
"EXPRESSION" ), context );
81 const bool ascending = parameterAsBoolean( parameters, QStringLiteral(
"ASCENDING" ), context );
82 const bool nullsFirst = parameterAsBoolean( parameters, QStringLiteral(
"NULLS_FIRST" ), context );
85 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, sinkId, source->fields(), source->wkbType(), source->sourceCrs() ) );
89 const long count = source->featureCount();
90 const double step = count > 0 ? 100.0 / count : 1;
94 request.
addOrderBy( expressionString, ascending, nullsFirst );
104 if ( !sink->addFeature( inFeature ) )
111 outputs.insert( QStringLiteral(
"OUTPUT" ), sinkId );