25QString QgsOrderByExpressionAlgorithm::name()
const
27 return QStringLiteral(
"orderbyexpression" );
30QString QgsOrderByExpressionAlgorithm::displayName()
const
32 return QObject::tr(
"Order by expression" );
35QStringList QgsOrderByExpressionAlgorithm::tags()
const
37 return QObject::tr(
"orderby,sort,expression,field" ).split(
',' );
40QString QgsOrderByExpressionAlgorithm::group()
const
42 return QObject::tr(
"Vector general" );
45QString QgsOrderByExpressionAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeneral" );
50void QgsOrderByExpressionAlgorithm::initAlgorithm(
const QVariantMap & )
60QString 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." );
68QgsOrderByExpressionAlgorithm *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 ) )
113 outputs.insert( QStringLiteral(
"OUTPUT" ), sinkId );
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & addOrderBy(const QString &expression, bool ascending=true)
Adds a new OrderByClause, appending it as the least important one.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A boolean parameter for processing algorithms.
An expression parameter for processing algorithms.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.